Package org.sm.smtools.application.util
Enum Registry
java.lang.Object
java.lang.Enum<Registry>
org.sm.smtools.application.util.Registry
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<Registry>
,java.lang.constant.Constable
public enum Registry extends java.lang.Enum<Registry>
The
Registry
class provides a mechanism for accessing (persistent) global variables.
The Registry
class is actually a singleton instance, and a local reference to it
should be obtained as follows:
Registry registry = Registry.kINSTANCE;The registry contains serialisable objects that can be stored and retrieved via a
String
key using the
addObject(String,Object)
and getObject(String)
methods.- Version:
- 26/06/2018
- Author:
- Sven Maerivoet
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
java.lang.Enum.EnumDesc<E extends java.lang.Enum<E>>
-
Enum Constant Summary
Enum Constants Enum Constant Description kINSTANCE
The singleton instance. -
Method Summary
Modifier and Type Method Description void
addObject(java.lang.String name, java.lang.Object object)
Adds an object to the registry.void
clear()
Clears the registry.java.lang.Object
getObject(java.lang.String name)
Returns an object from the registry.void
load(java.lang.String filename)
Loads all objects in the registry from a file using deserialisation.void
save(java.lang.String filename)
Saves all objects in the registry to a file using serialisation.static Registry
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static Registry[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.Methods inherited from class java.lang.Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
-
Enum Constant Details
-
kINSTANCE
The singleton instance.
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
clear
public void clear()Clears the registry. -
addObject
public void addObject(java.lang.String name, java.lang.Object object)Adds an object to the registry.- Parameters:
name
- the name of the objectobject
- a reference to the object
-
getObject
public java.lang.Object getObject(java.lang.String name)Returns an object from the registry.- Parameters:
name
- the name of the object- Returns:
- a reference to the object
-
load
Loads all objects in the registry from a file using deserialisation.- Parameters:
filename
- the name of the file to load the registry from- Throws:
RegistryException
- if an error occurred during the deserialisation process
-
save
Saves all objects in the registry to a file using serialisation.Note that care should be taken that all the objects are serialisable.
- Parameters:
filename
- the name of the file to save the registry to- Throws:
RegistryException
- if an error occurred during the serialisation process
-