Interface SessionKey<T>

  • Type Parameters:
    T - the type

    public interface SessionKey<T>
    A key for an object in the session.

    A key is a combination of type and name. A key must have a type, or name, or both.

    A key stored in the session always has a type parameter. That is, all keys returned by SessionData.getKeys() are guaranteed to have a type parameter. A key with a name only can be used to retrieve an item from the session where the type is not known ahead of time.

    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      java.lang.String getName()
      The name.
      java.lang.Class<T> getType()
      The type.
      static <T> SessionKey<T> of​(java.lang.Class<T> type)
      Creates a key of the given type with no name.
      static SessionKey<?> of​(java.lang.String name)
      Creates a key of the given name with no type.
      static <T> SessionKey<T> of​(java.lang.String name, java.lang.Class<T> type)
      Creates a key of the given name and type.
      static <T> SessionKey<T> ofType​(java.lang.String name, T value)
      Creates a key of the given name, and the type of the given object (as provided by Object.getClass()).
      static <T> SessionKey<T> ofType​(T value)
      Creates a key of type of the given object (as provided by Object.getClass()), and no name.
    • Method Detail

      • getName

        @Nullable
        java.lang.String getName()
        The name.
        Returns:
        the name
      • getType

        @Nullable
        java.lang.Class<T> getType()
        The type.
        Returns:
        the type
      • of

        static <T> SessionKey<T> of​(java.lang.Class<T> type)
        Creates a key of the given type with no name.
        Type Parameters:
        T - the type
        Parameters:
        type - the type
        Returns:
        a session key
      • of

        static <T> SessionKey<T> of​(@Nullable
                                    java.lang.String name,
                                    @Nullable
                                    java.lang.Class<T> type)
        Creates a key of the given name and type.

        If both arguments are null, an IllegalArgumentException will be thrown.

        Type Parameters:
        T - the type
        Parameters:
        name - the name
        type - the type
        Returns:
        a session key
      • of

        static SessionKey<?> of​(java.lang.String name)
        Creates a key of the given name with no type.
        Parameters:
        name - the name
        Returns:
        a session key
      • ofType

        static <T> SessionKey<T> ofType​(java.lang.String name,
                                        T value)
        Creates a key of the given name, and the type of the given object (as provided by Object.getClass()).
        Type Parameters:
        T - the type
        Parameters:
        name - the name
        value - the object who's runtime type will be used as the type of the key
        Returns:
        a session key
      • ofType

        static <T> SessionKey<T> ofType​(T value)
        Creates a key of type of the given object (as provided by Object.getClass()), and no name.
        Type Parameters:
        T - the type
        Parameters:
        value - the object who's runtime type will be used as the type of the key
        Returns:
        a session key