|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ahc.util.IntegerFactory
This class is an implementation of the GOF "Flyweight" pattern. It provides a single point of
access to Integer objects and caches them. Since Integer objects are immutable, an entire
program can e.g. share a single instance of e.g. "Integer (1)"; this class caches instances
and thus allows memory to be saved.
This class uses a fixed number of 1000 bins to store the integers (analogously to a HashMap)
in order to maximize retrieval performance. If it is used for numbers larger than that, it
will still work but performance will degrade due to the linear lookup overhead inside each
bin.
CAUTION: This class never releases an Integer once it was created. So this class should be
used only in those cases when that is desired, e.g. for counters of relatively small numbers
in collections.
Field Summary | |
static int |
NUM_BINS
|
Constructor Summary | |
IntegerFactory()
|
Method Summary | |
static java.lang.Integer |
add(java.lang.Integer v1,
int v2)
convenience method for retrieving the sum. |
static java.lang.Integer |
add(java.lang.Integer v1,
java.lang.Integer v2)
convenience method for retrieving the sum. |
static java.lang.Integer |
decrement(java.lang.Integer value)
convenience method for retrieving the next lower number. |
static java.lang.Integer |
get(int value)
|
static java.lang.Integer |
increment(java.lang.Integer value)
convenience method for retrieving the next higher number. |
static java.lang.Integer |
mod(java.lang.Integer a,
int b)
an implementation of the mathematically typical - as opposed to the Java - implementation of the modulus funtion. |
static java.lang.Integer |
mod(java.lang.Integer a,
java.lang.Integer b)
an implementation of the mathematically typical - as opposed to the Java - implementation of the modulus funtion. |
static java.lang.Integer |
mod(int a,
int b)
an implementation of the mathematically typical - as opposed to the Java - implementation of the modulus funtion. |
static java.lang.Integer |
mod(int a,
java.lang.Integer b)
an implementation of the mathematically typical - as opposed to the Java - implementation of the modulus funtion. |
static java.lang.Integer |
subtract(java.lang.Integer v1,
int v2)
convenience method for retrieving the difference. |
static java.lang.Integer |
subtract(java.lang.Integer v1,
java.lang.Integer v2)
convenience method for retrieving the difference. |
static java.lang.Integer |
subtract(int v1,
java.lang.Integer v2)
convenience method for retrieving the difference. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int NUM_BINS
Constructor Detail |
public IntegerFactory()
Method Detail |
public static java.lang.Integer get(int value)
public static java.lang.Integer increment(java.lang.Integer value)
public static java.lang.Integer decrement(java.lang.Integer value)
public static java.lang.Integer add(java.lang.Integer v1, java.lang.Integer v2)
public static java.lang.Integer add(java.lang.Integer v1, int v2)
public static java.lang.Integer subtract(java.lang.Integer v1, java.lang.Integer v2)
public static java.lang.Integer subtract(java.lang.Integer v1, int v2)
public static java.lang.Integer subtract(int v1, java.lang.Integer v2)
public static java.lang.Integer mod(int a, int b)
public static java.lang.Integer mod(java.lang.Integer a, int b)
public static java.lang.Integer mod(int a, java.lang.Integer b)
public static java.lang.Integer mod(java.lang.Integer a, java.lang.Integer b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |