helix.graph.model
Interface RegistryValue

All Known Implementing Classes:
AbstractRegistryValue, ImmutableRegistryValue, RBoolean, RColorSet, RFloat, RInteger, RObject, RString, RVertex, RVertexArray, RVertexList, RVertexSet, RVoid

public interface RegistryValue

A RegistryValue object represents something that can be stored in a Registry. In order to adapt to several implementations of Registry, a RegistryValue should provide some serialization facilities : - a serialize() method that produce a String representation of the instance. - a constructor with a String argument (e.g MyRegistryValue(String s)) that can reconstruct an instance from the previous String. Note: this is the responsability of the Registry implementation to manage the serialization/deserialization process. The default Memory implementation (MemRegistry) does not care at all about these methods since it will never serialize/deserialize the objects. A typical SGBD or Disk based Registry will store the key, the serialized String and the original class of the object. Then, in the get() method, it will call the class constructor with the stored String value to restore the original object. A RegistryValue also implements a klone() method, to potentially clone the object. This method is called, in particular, when the Registry is copied thru the Registry.copy() method. The behavior of your klone() method depends upon the mutability of the object. For immutable objects, there is no need to actually duplicate the object. a typical implementation is therefore :
public RegistryValue klone() { return this }
For mutable objects, the klone() method should make a deep copy of the instance if you want the copy to have its own life. A simple way to do this is :
public RegistryValue klone() { return new MyRegistryValue(this.serialize()) }
note: the method is called klone() instead of clone() to avoir conflicts with the strange Object.clone() method. Finally, RegistryValue also implements several conversion to basic types (String, int, float and boolean). This is mostly useful for basic types RegistryValue e.g. :
registry.set("age", 123);
registry.get("age").intValue();
registry.get("age").stringValue();
If your RegistryValue cannot be converted into a Basic type, just throw the IllegalValueException Runtime exception. Note: you may also redefine the hashCode() and equals() methods for use of your RegistryValue in hashMaps. The AbstractRegistryValue provides a good startpoint for your class.


Method Summary
 RegistryValue klone()
          Potentially clone this instance.
 String serialize()
          get a String representation of this instance.
 boolean toBoolean()
           
 float toFloat()
           
 int toInt()
           
 String toString()
          Get a String representation of this instance value note: this representation may not be suitable as the constructor argument, use serialize() instead.
 

Method Detail

serialize

String serialize()
get a String representation of this instance. this representation can further be used as a constructor argument to reconstruct this instance.

Returns:
string representation of this instance

klone

RegistryValue klone()
Potentially clone this instance.

Returns:
a clone (deep copy) of this instance. Note that it may be the instance itself (for immutable objects).

toString

String toString()
                throws IllegalValueException
Get a String representation of this instance value note: this representation may not be suitable as the constructor argument, use serialize() instead.

Overrides:
toString in class Object
Returns:
String representation of this instance value
Throws:
IllegalValueException

toInt

int toInt()
          throws IllegalValueException
Returns:
int representation of this instance value
Throws:
IllegalValueException

toFloat

float toFloat()
              throws IllegalValueException
Returns:
float representation of this instance value
Throws:
IllegalValueException

toBoolean

boolean toBoolean()
                  throws IllegalValueException
Returns:
boolean representation of this instance value
Throws:
IllegalValueException