public class SizeEstimator extends Object
For classes that contain references to other objects, what exactly is included in an object's "size" is defined on a case-by-case basis.
| Modifier and Type | Field and Description |
|---|---|
static int |
BOOLEAN_SIZE |
static int |
BYTE_SIZE |
static int |
CHAR_SIZE |
static int |
DOUBLE_SIZE |
static int |
FLOAT_SIZE |
static int |
INT_SIZE |
static int |
LONG_SIZE |
static int |
SHORT_SIZE |
| Constructor and Description |
|---|
SizeEstimator() |
| Modifier and Type | Method and Description |
|---|---|
SizeEstimator |
add(boolean[] array)
Add the size of the given array object.
|
SizeEstimator |
add(byte[] array)
Add the size of the given array object.
|
SizeEstimator |
add(char[] array)
Add the size of the given array object.
|
SizeEstimator |
add(double[] array)
Add the size of the given array object.
|
SizeEstimator |
add(float[] array)
Add the size of the given array object.
|
SizeEstimator |
add(int[] array)
Add the size of the given array object.
|
SizeEstimator |
add(long value)
Adjust the total by an arbitrary amount.
|
SizeEstimator |
add(long[] array)
Add the size of the given array object.
|
SizeEstimator |
add(Object[] array)
Add the size of the given array object.
|
SizeEstimator |
add(short[] array)
Add the size of the given array object.
|
SizeEstimator |
add(SizeEstimating obj)
Add the size of the given
SizeEstimating object. |
SizeEstimator |
addArray(int elementSize,
int length)
Add the size of a non-null array having elements with the given size and the specified length.
|
SizeEstimator |
addArrayListField(ArrayList<?> list)
Add the size of an
ArrayList field, assuming ArrayList.trimToSize() has been invoked. |
SizeEstimator |
addBooleanField()
Add the size of a primitive
boolean field. |
SizeEstimator |
addByteField()
Add the size of a primitive
byte field. |
SizeEstimator |
addCharField()
Add the size of a primitive
char field. |
SizeEstimator |
addDoubleField()
Add the size of a primitive
double field. |
SizeEstimator |
addField(boolean[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(byte[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(char[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(double[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(float[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(int[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(long[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(Object[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(short[] array)
Add the size of the given array field.
|
SizeEstimator |
addField(SizeEstimating field)
Add the size of a
SizeEstimating reference field. |
SizeEstimator |
addFloatField()
Add the size of a primitive
float field. |
SizeEstimator |
addIntField()
Add the size of a primitive
int field. |
SizeEstimator |
addLongField()
Add the size of a primitive
long field. |
SizeEstimator |
addObjectOverhead()
Add the basic overhead for any object.
|
SizeEstimator |
addReferenceField()
Add the size of an object reference field.
|
SizeEstimator |
addShortField()
Add the size of a primitive
short field. |
SizeEstimator |
addTreeMapField(TreeMap<?,?> map)
Add the size of a
TreeMap field. |
SizeEstimator |
addTreeSetField(TreeSet<?> set)
Add the size of a
TreeSet field. |
int |
getObjectOverhead()
Get the basic overhead for any object.
|
int |
getReferenceSize()
Get the size of an object reference.
|
long |
getTotal()
Get the estimated total size.
|
public static final int BOOLEAN_SIZE
public static final int BYTE_SIZE
public static final int CHAR_SIZE
public static final int SHORT_SIZE
public static final int INT_SIZE
public static final int FLOAT_SIZE
public static final int LONG_SIZE
public static final int DOUBLE_SIZE
public long getTotal()
public int getObjectOverhead()
The implementation in SizeEstimator returns 12.
Objectpublic int getReferenceSize()
The implementation in SizeEstimator returns 4.
public SizeEstimator addObjectOverhead()
The implementation in SizeEstimator adds the amount returned by getObjectOverhead().
public SizeEstimator add(long value)
value - amount to add to the totalpublic final SizeEstimator addBooleanField()
boolean field.public final SizeEstimator addByteField()
byte field.public final SizeEstimator addCharField()
char field.public final SizeEstimator addShortField()
short field.public final SizeEstimator addIntField()
int field.public final SizeEstimator addFloatField()
float field.public final SizeEstimator addLongField()
long field.public final SizeEstimator addDoubleField()
double field.public final SizeEstimator addReferenceField()
This is for the field itself, not including any object it may reference if not null
public SizeEstimator addArray(int elementSize, int length)
elementSize - size of one array elementlength - array lengthIllegalArgumentException - if elementSize is non-positive or length is negativepublic SizeEstimator add(boolean[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(byte[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(char[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(short[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(int[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(float[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(long[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(double[] array)
array - array objectNullPointerException - if array is nullpublic SizeEstimator add(Object[] array)
This does not include the size of any objects referred to by elements in the array.
array - array objectNullPointerException - if array is nullpublic SizeEstimator addField(boolean[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(byte[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(char[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(short[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(int[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(float[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(long[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(double[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null.
array - array object, possibly nullpublic SizeEstimator addField(Object[] array)
This includes the size of the array field itself, plus the size of the referred-to array if not null. This does not include the size of any objects referred to by elements in the array.
array - array object, possibly nullpublic SizeEstimator add(SizeEstimating obj)
SizeEstimating object.
This method just invokes SizeEstimating.addTo().
obj - object to measureNullPointerException - if obj is nullpublic SizeEstimator addField(SizeEstimating field)
SizeEstimating reference field.
This includes the size of the field itself, plus the size of the referred-to object
(according to SizeEstimating.addTo() if field is not null.
field - field to measure, possibly nullpublic SizeEstimator addArrayListField(ArrayList<?> list)
ArrayList field, assuming ArrayList.trimToSize() has been invoked.
This includes the size of the array field itself, plus the size of the referred-to array if list is not null.
This does not include any objects referred to by the list.
list - ArrayList object, possibly nullpublic SizeEstimator addTreeMapField(TreeMap<?,?> map)
TreeMap field.
This includes the size of the field itself, plus the size of the referred-to TreeMap if map is not null.
This does not include the sizes of the key and value objects contained in the TreeMap.
map - TreeMap object, possibly nullpublic SizeEstimator addTreeSetField(TreeSet<?> set)
TreeSet field.
This includes the size of the field itself, plus the size of the referred-to TreeSet if set is not null.
This does not include the sizes of the objects contained in the TreeSet.
set - TreeSet object, possibly nullCopyright © 2016. All rights reserved.