de.lmu.ifi.dbs.elki.utilities
Class ConstantObject<D extends ConstantObject<D>>

java.lang.Object
  extended by de.lmu.ifi.dbs.elki.utilities.ConstantObject<D>
Type Parameters:
D - Class self reference for Comparable restriction
All Implemented Interfaces:
Comparable<D>
Direct Known Subclasses:
OptionID

public abstract class ConstantObject<D extends ConstantObject<D>>
extends Object
implements Comparable<D>

ConstantObject provides a parent class for constant objects, that are immutable and unique by class and name.


Field Summary
private static Map<Class<?>,Map<String,ConstantObject<?>>> CONSTANT_OBJECTS_INDEX
          Index of constant objects.
private  int hashCode
          The cached hash code of this object.
private  String name
          Holds the value of the property's name.
 
Constructor Summary
protected ConstantObject(String name)
          Provides a ConstantObject of the given name.
 
Method Summary
 int compareTo(D o)
          Two constant objects are generally compared by their name.
 boolean equals(Object o)
           
 String getName()
          Returns the name of the ConstantObject.
 int hashCode()
           
static
<D extends ConstantObject<D>>
D
lookup(Class<D> type, String name)
          Provides a ConstantObject of specified class and name if it exists.
protected  Object readResolve()
          Method for use by the serialization mechanism to ensure identity of ConstantObjects.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONSTANT_OBJECTS_INDEX

private static final Map<Class<?>,Map<String,ConstantObject<?>>> CONSTANT_OBJECTS_INDEX
Index of constant objects.


name

private final String name
Holds the value of the property's name.


hashCode

private final int hashCode
The cached hash code of this object.

Constructor Detail

ConstantObject

protected ConstantObject(String name)
Provides a ConstantObject of the given name.

Parameters:
name - name of the ConstantObject
Method Detail

getName

public String getName()
Returns the name of the ConstantObject.

Returns:
the name of the ConstantObject

lookup

public static final <D extends ConstantObject<D>> D lookup(Class<D> type,
                                                           String name)
Provides a ConstantObject of specified class and name if it exists.

Type Parameters:
D - Type for compile time type checking
Parameters:
type - the type of the desired ConstantObject
name - the name of the desired ConstantObject
Returns:
the ConstantObject of designated type and name if it exists, null otherwise

readResolve

protected Object readResolve()
Method for use by the serialization mechanism to ensure identity of ConstantObjects.

Returns:
the ConstantObject that already exists in the virtual machine rather than a new instance as created by the serialization mechanism

equals

public boolean equals(Object o)
Overrides:
equals in class Object
See Also:
Object.equals(Object)

hashCode

public int hashCode()
Overrides:
hashCode in class Object
See Also:
Object.hashCode()

compareTo

public int compareTo(D o)
Two constant objects are generally compared by their name. The result reflects the lexicographical order of the names by this.getName().compareTo(o.getName().

Specified by:
compareTo in interface Comparable<D extends ConstantObject<D>>
Parameters:
o - Object to compare to.
Returns:
comparison result
See Also:
Comparable.compareTo(java.lang.Object)

Release 0.4.0 (2011-09-20_1324)