com.bristle.javalib.util
Class BooleanWrapper

java.lang.Object
  extended by com.bristle.javalib.util.BooleanWrapper
Direct Known Subclasses:
GetOpt.DefaultBoolean, GetOpt.Required, GetOpt.ValueRequired

public class BooleanWrapper
extends Object

This class wraps a Boolean. It is useful to subclass when you want an object that is essentially a Boolean, but can be distinguished from other Boolean types. For example, when you write a method with multiple parameters that are all Booleans, but serve different purposes, and you want to be sure they were passed in the correct order on the method call, you can define each parameter to be a different subclass of this class. Note: This class would not be necessary if java.lang.Boolean was not declared as "final".

Usage:
   - The typical scenario for using this class is:
     - Declare subclasses of this class:
        public static class IsFlat extends BooleanWrapper
        { public IsFlat(boolean blnValue) { super(blnValue); } }
        public static class IsHard extends BooleanWrapper
        { public IsHard(boolean blnValue) { super(blnValue); } }
     - Declare a method that takes the subclasses as parameters:
        public void validate(Boolean blnValue, IsFlat blnFlat, IsHard blnHard);
     - Call the method, with order of arguments enforced:
        validate(blnValue, new IsFlat(true), new IsHard(false));

   - See the source code of the inner Tester class for more examples.
  
Assumptions:
Effects:
       - None.
Anticipated Changes:
Notes:
Implementation Notes:
Portability Issues:
Revision History:
   $Log$


Nested Class Summary
static class BooleanWrapper.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Constructor Summary
BooleanWrapper(boolean blnValue)
          Constructor.
BooleanWrapper(Boolean blnValue)
          Constructor.
 
Method Summary
static String castToString(BooleanWrapper wrapper)
          Return the BooleanWrapper cast to a String, or null if the specified BooleanWrapper is null.
 boolean getboolean()
          Get the wrapped Boolean.
 Boolean getBoolean()
          Get the wrapped Boolean.
 void setboolean(boolean blnNew)
          Set the wrapped Boolean.
 void setBoolean(Boolean blnNew)
          Set the wrapped Boolean.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BooleanWrapper

public BooleanWrapper(boolean blnValue)
Constructor.

Parameters:
blnValue - Value of the Boolean

BooleanWrapper

public BooleanWrapper(Boolean blnValue)
Constructor.

Parameters:
blnValue - Value of the Boolean
Method Detail

setBoolean

public void setBoolean(Boolean blnNew)
Set the wrapped Boolean.

Parameters:
blnNew - The new Boolean.

getBoolean

public Boolean getBoolean()
Get the wrapped Boolean.

Returns:
The log level.

setboolean

public void setboolean(boolean blnNew)
Set the wrapped Boolean.

Parameters:
blnNew - The new Boolean.

getboolean

public boolean getboolean()
Get the wrapped Boolean.

Returns:
The log level.

castToString

public static String castToString(BooleanWrapper wrapper)
Return the BooleanWrapper cast to a String, or null if the specified BooleanWrapper is null.

Parameters:
wrapper - BooleanWrapper to cast to String.
Returns:
String version of the object.