Package ej.bon

Class Immutables


  • public class Immutables
    extends 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.

    The method get(String) allows to retrieve an object from the pool using its ID.

    • Constructor Detail

      • Immutables

        public Immutables()
    • Method Detail

      • get

        public static Object get​(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.

        Parameters:
        ID - the ID of the immutable object to get
        Returns:
        the immutable object matching the ID
        Throws:
        NoSuchElementException - if the ID is not found
        ImmutablesError - if an internal error occurred during immutable access
      • put

        @Deprecated
        public static void put​(String ID,
                               Object object)
        Deprecated.
        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.

        Parameters:
        ID - the ID of the immutable object to set
        object - the object to set immutable
        Throws:
        NullPointerException - if given object is null
        OutOfMemoryError - if the immutable memory is full
        See Also:
        freeMemory()
      • isImmutable

        public static boolean isImmutable​(Object object)
        Gets whether or not the given object is in the immutable objects pool or not.
        Parameters:
        object - the object to check
        Returns:
        true if the given object is immutable, false otherwise
        Throws:
        NullPointerException - if given object is null
      • allIDs

        public static String[] allIDs()
        Returns an array with the IDs of all the objects in the pool.
        Returns:
        all the immutable objects ID.
        See Also:
        get(String)
      • freeMemory

        public static long freeMemory()
        Returns the amount of free immutable memory still available.
        Returns:
        the amount of free immutable memory
      • totalMemory

        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.

        Returns:
        the total amount of immutable memory