Type Parameters:
T - the value type
All Superinterfaces:
MapAccessor<T>
All Known Subinterfaces:
NonNullKey<T>, NullableKey<T>
All Known Implementing Classes:
AbstractKey, NonNullListKey, NonNullObjectKey, NullableObjectKey, TransientKey

public interface Key<T> extends MapAccessor<T>
An name which provides typesafe access to a map entry.

A Key has a name, a type and a default value.

A key is identified by its identity. The hashcode and equals are based on the identity of the key.

The following code example shows how to set and get a value from a map.

 
 String value = "Werner";
 Key<String> stringKey = new Key("name",String.class,null);
 Map<Key<?>,Object> map = new HashMap<>();
 stringKey.put(map, value);
 
 

Note that Key is not a value type. Thus using two distinct instances of a Key will result in two distinct entries in the hash map, even if both keys have the same name.

Author:
Werner Randelshofer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    cast(Object value)
     
    default boolean
    Whether the map contains all keys required by this map accessor.
    default @Nullable T
    get(Map<? super Key<?>,Object> a)
    Gets the value of the attribute denoted by this Key from a Map.
    default @Nullable T
    get(ReadOnlyMap<? super Key<?>,Object> a)
    Gets the value of the attribute denoted by this Key from a Map.
    default @Nullable T
    getValue(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a)
    Gets the value of the attribute denoted by this Key from a Map.
    default javafx.beans.property.ObjectProperty<T>
    getValueProperty(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a)
    Gets the value of the attribute denoted by this Key from a Map.
    default boolean
    isAssignable(@Nullable Object value)
    Returns true if the specified value is assignable with this key.
    default boolean
    isDefault(@Nullable Object value)
    Returns true if the specified value is the default value of this key.
    boolean
    Whether the value may be set to null.
    default javafx.beans.property.ObjectProperty<T>
    propertyAt(javafx.collections.ObservableMap<Key<?>,Object> map)
    Creates a new property for the map entry specified by this key.
    default @Nullable T
    put(Map<? super Key<?>,Object> a, @Nullable T value)
    Use this method to perform a type-safe put operation of an attribute into a Map.
    default ImmutableMap<Key<?>,Object>
    put(ImmutableMap<Key<?>,Object> a, @Nullable T value)
    Use this method to perform a type-safe put operation of an attribute into a Map.
    default @Nullable T
    putValue(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a, @Nullable T value)
    Use this method to perform a type-safe put operation of an attribute into a Map.
    default javafx.beans.property.ReadOnlyProperty<T>
    readOnlyPropertyAt(javafx.collections.ObservableMap<Key<?>,Object> map)
    Creates a new read-only property for the map entry specified by this key.
    default @Nullable T
    remove(Map<? super Key<?>,Object> a)
    Use this method to perform a type-safe remove operation of an attribute on a Map.
    default ImmutableMap<Key<?>,Object>
    Use this method to perform a type-safe remove operation of an attribute on a Map.
    default javafx.beans.binding.Binding<T>
    valueAt(javafx.collections.ObservableMap<Key<?>,Object> map)
    Creates a new binding for the map entry specified by this key.

    Methods inherited from interface org.jhotdraw8.fxcollection.typesafekey.MapAccessor

    getDefaultValue, getName, getRawValueType, getValueType, isTransient, set
  • Field Details

  • Method Details

    • containsKey

      default boolean containsKey(Map<Key<?>,Object> map)
      Description copied from interface: MapAccessor
      Whether the map contains all keys required by this map accessor.
      Specified by:
      containsKey in interface MapAccessor<T>
      Parameters:
      map - a map
      Returns:
      true if map contains all keys required by this map accessor.
    • get

      default @Nullable T get(Map<? super Key<?>,Object> a)
      Gets the value of the attribute denoted by this Key from a Map.
      Specified by:
      get in interface MapAccessor<T>
      Parameters:
      a - A Map.
      Returns:
      The value of the attribute.
    • get

      default @Nullable T get(ReadOnlyMap<? super Key<?>,Object> a)
      Gets the value of the attribute denoted by this Key from a Map.
      Specified by:
      get in interface MapAccessor<T>
      Parameters:
      a - A Map.
      Returns:
      The value of the attribute.
    • getValueProperty

      default javafx.beans.property.ObjectProperty<T> getValueProperty(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a)
      Gets the value of the attribute denoted by this Key from a Map.
      Parameters:
      a - A Map.
      Returns:
      The value of the attribute.
    • getValue

      default @Nullable T getValue(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a)
      Gets the value of the attribute denoted by this Key from a Map.
      Parameters:
      a - A Map.
      Returns:
      The value of the attribute.
    • put

      default @Nullable T put(Map<? super Key<?>,Object> a, @Nullable T value)
      Use this method to perform a type-safe put operation of an attribute into a Map.
      Specified by:
      put in interface MapAccessor<T>
      Parameters:
      a - An attribute map.
      value - The new value.
      Returns:
      The old value.
    • put

      default ImmutableMap<Key<?>,Object> put(ImmutableMap<Key<?>,Object> a, @Nullable T value)
      Use this method to perform a type-safe put operation of an attribute into a Map.
      Specified by:
      put in interface MapAccessor<T>
      Parameters:
      a - An attribute map.
      value - The new value.
      Returns:
      The updated map
    • remove

      default @Nullable T remove(Map<? super Key<?>,Object> a)
      Use this method to perform a type-safe remove operation of an attribute on a Map.
      Specified by:
      remove in interface MapAccessor<T>
      Parameters:
      a - An attribute map.
      Returns:
      The old value.
    • remove

      default ImmutableMap<Key<?>,Object> remove(ImmutableMap<Key<?>,Object> a)
      Use this method to perform a type-safe remove operation of an attribute on a Map.
      Specified by:
      remove in interface MapAccessor<T>
      Parameters:
      a - An attribute map.
      Returns:
      The old value.
    • putValue

      default @Nullable T putValue(Map<? super Key<?>,javafx.beans.property.ObjectProperty<?>> a, @Nullable T value)
      Use this method to perform a type-safe put operation of an attribute into a Map.
      Parameters:
      a - An attribute map.
      value - The new value.
      Returns:
      The old value.
    • isNullable

      boolean isNullable()
      Whether the value may be set to null.
      Returns:
      true if nullable
    • isAssignable

      default boolean isAssignable(@Nullable Object value)
      Returns true if the specified value is assignable with this key.
      Parameters:
      value - The object to be verified for assignability.
      Returns:
      True if assignable.
    • isDefault

      default boolean isDefault(@Nullable Object value)
      Returns true if the specified value is the default value of this key.
      Parameters:
      value - The object to be verified for assignability.
      Returns:
      True if assignable.
    • valueAt

      default javafx.beans.binding.Binding<T> valueAt(javafx.collections.ObservableMap<Key<?>,Object> map)
      Creates a new binding for the map entry specified by this key.
      Parameters:
      map - a map
      Returns:
      a binding for the map entry
    • propertyAt

      default javafx.beans.property.ObjectProperty<T> propertyAt(javafx.collections.ObservableMap<Key<?>,Object> map)
      Creates a new property for the map entry specified by this key.
      Parameters:
      map - a map
      Returns:
      a property for the map entry
    • readOnlyPropertyAt

      default javafx.beans.property.ReadOnlyProperty<T> readOnlyPropertyAt(javafx.collections.ObservableMap<Key<?>,Object> map)
      Creates a new read-only property for the map entry specified by this key.
      Parameters:
      map - a map
      Returns:
      a property for the map entry
    • cast

      default T cast(Object value)