public class Immutables
extends java.lang.Object
This class gives access to the global immutable objects pool.
Immutable objects are persistent and normally reside in read-only-memory, such as flash memory.
Immutable objects are created in two ways:
put(String, Object)
or putAll(Hashtable)
,
The method get(String)
allows to retrieve an object from the pool using its ID.
Constructor and Description |
---|
Immutables() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String[] |
allIDs()
Returns an array with the IDs of all the objects in the pool.
|
static long |
freeMemory()
Returns the amount of free immutable memory still available.
|
static java.lang.Object |
get(java.lang.String ID)
Retrieves the object that match the the given ID in the immutable objects pool.
|
static boolean |
isImmutable(java.lang.Object object)
Gets whether or not the given object is in the immutable objects pool or not.
|
static void |
put(java.lang.String ID,
java.lang.Object object)
Maps the given ID to the given object in the immutable objects pool.
|
static void |
putAll(java.util.Hashtable table)
Maps all the mappings in the given table in the immutable objects pool.
|
static long |
totalMemory()
Returns the total amount of immutable memory.
|
public static java.lang.Object get(java.lang.String ID)
Retrieves the object that match the the given ID in the immutable objects pool.
If no object can be found with such ID, a NoSuchElementException
is thrown.
ID
- the ID of the immutable object to getjava.util.NoSuchElementException
- if the ID is not foundImmutablesError
- if an internal error occurred during immutable accesspublic static void put(java.lang.String ID, java.lang.Object object)
Maps the given ID to the given object in the immutable objects pool.
The object can be retrieved by calling the get method with an ID that is equal to the original ID.
ID
- the ID of the immutable object to setobject
- the object to set immutablejava.lang.NullPointerException
- if given object is null
java.lang.OutOfMemoryError
- if the immutable memory is fullfreeMemory()
public static void putAll(java.util.Hashtable table)
Maps all the mappings in the given table in the immutable objects pool.
table
- the table that contains the objects to set immutablejava.lang.NullPointerException
- if given table is null
java.lang.ClassCastException
- if an ID is not a String
java.lang.OutOfMemoryError
- if the immutable memory is fullfreeMemory()
,
put(String, Object)
public static boolean isImmutable(java.lang.Object object)
Gets whether or not the given object is in the immutable objects pool or not.
object
- the object to checktrue
if the given object is immutable, false
otherwisejava.lang.NullPointerException
- if given object is null
public static java.lang.String[] allIDs()
Returns an array with the IDs of all the objects in the pool.
get(String)
public static long freeMemory()
Returns the amount of free immutable memory still available.
public static long totalMemory()
Returns the total amount of immutable memory.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.