Class 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
    • 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 the String value of this object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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) 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<java.lang.Object> of​(@Nonnull
                                               java.lang.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 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 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 java.lang.Comparable<T>