Package it.tidalwave.util
Class Key<T>
- java.lang.Object
-
- it.tidalwave.util.Key<T>
-
- All Implemented Interfaces:
StringValue
,java.io.Serializable
,java.lang.Comparable<Key<?>>
@Immutable public class Key<T> extends java.lang.Object implements StringValue, java.lang.Comparable<Key<?>>, java.io.Serializable
- Since:
- 1.11.0
- Author:
- Fabrizio Giudici
- See Also:
- Serialized Form
- Stereotype:
- flyweight
-
-
Constructor Summary
Constructors Constructor Description Key(StringValue name)
Deprecated.Key(java.lang.String name)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static java.util.Set<Key<?>>
allKeys()
Returns all the keys registered in the system.int
compareTo(Key<?> other)
static Key<java.lang.Object>
of(java.lang.String name)
Creates an instance with the given name.static <T> Key<T>
of(java.lang.String name, java.lang.Class<T> type)
Creates an instance with the given name and type.java.lang.String
stringValue()
Returns theString
value of this object.
-
-
-
Constructor Detail
-
Key
@Deprecated public Key(@Nonnull java.lang.String name)
Deprecated.Create a new instance with the given name.- Parameters:
name
- the name
-
Key
public Key(@Nonnull StringValue name)
Deprecated.Create a new instance with the given name.- Parameters:
name
- the name
-
-
Method Detail
-
of
@Nonnull public static <T> Key<T> of(@Nonnull java.lang.String name, @Nonnull java.lang.Class<T> type)
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
@Nonnull public static Key<java.lang.Object> of(@Nonnull java.lang.String name)
Creates an instance with the given name. Type is considere 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
@Nonnull public static java.util.Set<Key<?>> allKeys()
Returns all the keys registered in the system.- Returns:
- a mutable and sorted set of keys.
- Since:
- 3.2-ALPHA-2
-
stringValue
@Nonnull public java.lang.String stringValue()
Returns theString
value of this object.- Specified by:
stringValue
in interfaceStringValue
- Returns:
- the string
-
-