|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.bristle.javalib.util.IntegerWrapper
public class IntegerWrapper
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. |
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 |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public IntegerWrapper(int intValue)
intValue
- Value of the Integerpublic IntegerWrapper(Integer intValue)
intValue
- Value of the IntegerMethod Detail |
---|
public void setInteger(Integer intNew)
intNew
- The new Integer.public Integer getInteger()
public void setInt(int intNew)
intNew
- The new Integer.public int getInt()
public static String castToString(IntegerWrapper wrapper)
wrapper
- IntegerWrapper to cast to String.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |