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 Details

  • Method Details

    • of

      @Nonnull public static <T> Key<T> of(@Nonnull String name, @Nonnull 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) and Key.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 name
      type - the dynamic type
      Returns:
      the key
      Since:
      3.2-ALPHA-2
    • of

      @Nonnull public static Key<Object> of(@Nonnull String name)
      Creates an instance with the given name. Type is considered as unknown (and assumed as Object). Please see of(String, Class) for more information.
      Parameters:
      name - the name
      Returns:
      the key
      Since:
      3.2-ALPHA-4
    • allKeys

      @Nonnull public static 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 String stringValue()
      Returns the String value of this object.
      Specified by:
      stringValue in interface StringValue
      Returns:
      the string
    • compareTo

      public int compareTo(@Nonnull Key<?> other)
      Specified by:
      compareTo in interface Comparable<T>