Type Parameters:
T - the value type
All Superinterfaces:
MapAccessor<T>, Serializable
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 Details

  • Method Details

    • containsKey

      default boolean containsKey(@NonNull 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(@NonNull 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(@NonNull 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 @NonNull javafx.beans.property.ObjectProperty<T> getValueProperty(@NonNull 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(@NonNull 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(@NonNull 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

      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(@NonNull 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

      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(@NonNull 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 @NonNull javafx.beans.binding.Binding<T> valueAt(@NonNull 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 @NonNull javafx.beans.property.ObjectProperty<T> propertyAt(@NonNull 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 @NonNull javafx.beans.property.ReadOnlyProperty<T> readOnlyPropertyAt(@NonNull 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 @NonNull T cast(Object value)