public class Immutables extends Object
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 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 Object |
get(String ID)
Retrieves the object that match the the given ID in the immutable objects
pool.
|
static boolean |
isImmutable(Object object)
Gets whether or not the given object is in the immutable objects pool or not.
|
static void |
put(String ID,
Object object)
Maps the given ID to the given object in the immutable objects pool.
|
static void |
putAll(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 Object get(String ID)
If no object can be found with such ID, a NoSuchElementException
is
thrown.
ID
- the ID of the immutable object to getNoSuchElementException
- if the ID is not foundImmutablesError
- if an internal error occurred during immutable accesspublic static void put(String ID, Object object)
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 immutableNullPointerException
- if given object is null
OutOfMemoryError
- if the immutable memory is fullfreeMemory()
public static void putAll(Hashtable table)
table
- the table that contains the objects to set immutableNullPointerException
- if given table is null
ClassCastException
- if an ID is not a String
OutOfMemoryError
- if the immutable memory is fullfreeMemory()
,
put(String, Object)
public static boolean isImmutable(Object object)
object
- the object to checktrue
if the given object is immutable,
false
otherwiseNullPointerException
- if given object is null
public static String[] allIDs()
get(String)
public static long freeMemory()
public static long totalMemory()
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.