com.bristle.javalib.util
Class IntegerWrapper

java.lang.Object
  extended by com.bristle.javalib.util.IntegerWrapper
Direct Known Subclasses:
GetOpt.DefaultInteger, GetOpt.MaxInteger, GetOpt.MinInteger

public class IntegerWrapper
extends Object

This class wraps an Integer. It is useful to subclass when you want an object that is essentially an Integer, but can be distinguished from other Integer types. For example, when you write a method with multiple parameters that are all Integers, 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.Integer was not declared as "final".

Usage:
   - The typical scenario for using this class is:
     - Declare subclasses of this class:
        public static class MinInteger extends IntegerWrapper
        { public MinInteger(int intValue) { super(intValue); } }
        public static class MaxInteger extends IntegerWrapper
        { public MaxInteger(int intValue) { super(intValue); } }
     - Declare a method that takes the subclasses as parameters:
        public Integer getValue(MinInteger intMin, MaxInteger intMax);
     - Call the method, with order of arguments enforced:
        intValue = getValue(new MinInteger(1), new MaxInteger(100));

   - 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 IntegerWrapper.Tester
          Each class contains a Tester inner class with a main() for easier unit testing.
 
Field Summary
private  Integer m_int
           
 
Constructor Summary
IntegerWrapper(int intValue)
          Constructor.
IntegerWrapper(Integer intValue)
          Constructor.
 
Method Summary
static String castToString(IntegerWrapper wrapper)
          Return the IntegerWrapper cast to a String, or null if the specified IntegerWrapper is null.
 int getInt()
          Get the wrapped Integer.
 Integer getInteger()
          Get the wrapped Integer.
 void setInt(int intNew)
          Set the wrapped Integer.
 void setInteger(Integer intNew)
          Set the wrapped Integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_int

private Integer m_int
Constructor Detail

IntegerWrapper

public IntegerWrapper(int intValue)
Constructor.

Parameters:
intValue - Value of the Integer

IntegerWrapper

public IntegerWrapper(Integer intValue)
Constructor.

Parameters:
intValue - Value of the Integer
Method Detail

setInteger

public void setInteger(Integer intNew)
Set the wrapped Integer.

Parameters:
intNew - The new Integer.

getInteger

public Integer getInteger()
Get the wrapped Integer.

Returns:
The log level.

setInt

public void setInt(int intNew)
Set the wrapped Integer.

Parameters:
intNew - The new Integer.

getInt

public int getInt()
Get the wrapped Integer.

Returns:
The log level.

castToString

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

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