Package it.tidalwave.util
Class Key<T>
java.lang.Object
it.tidalwave.util.Key<T>
- All Implemented Interfaces:
StringValue
,Serializable
,Comparable<Key<?>>
@Immutable
public class Key<T>
extends Object
implements StringValue, Comparable<Key<?>>, Serializable
- Since:
- 1.11.0
- Author:
- Fabrizio Giudici
- See Also:
- Stereotype:
- flyweight
-
Constructor Summary
-
Method Summary
-
Constructor Details
-
Key
Deprecated.Create a new instance with the given name.- Parameters:
name
- the name
-
Key
Deprecated.Create a new instance with the given name.- Parameters:
name
- the name
-
-
Method Details
-
of
Creates an instance with the given name and type. If an identical key already exists, that existing instance is returned. It is allowed to have two keys with the same name and different types (e.g.Key.of("foo", String.class)
andKey.of("foo", Integer.class)
): they are considered as two distinct keys. This feature allows to treat the same data both as typed and type-agnostic at the same time; for instance, a collection of properties could be read from a configuration file in type-agnostic way (if there is no type information in the file) and later managed as typed only when needed.- Type Parameters:
T
- the static type- Parameters:
name
- the nametype
- the dynamic type- Returns:
- the key
- Since:
- 3.2-ALPHA-2
-
of
Creates an instance with the given name. Type is considered as unknown (and assumed asObject
). Please seeof(String, Class)
for more information.- Parameters:
name
- the name- Returns:
- the key
- Since:
- 3.2-ALPHA-4
-
allKeys
Returns all the keys registered in the system.- Returns:
- a mutable and sorted set of keys.
- Since:
- 3.2-ALPHA-2
-
stringValue
Returns theString
value of this object.- Specified by:
stringValue
in interfaceStringValue
- Returns:
- the string
-
compareTo
- Specified by:
compareTo
in interfaceComparable<T>
-
of(String, Class)