- 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
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 -
Method Summary
Modifier and TypeMethodDescriptiondefault booleancontainsKey(@NonNull Map<Key<?>, Object> map) Whether the map contains all keys required by this map accessor.Gets the value of the attribute denoted by this Key from a Map.get(@NonNull ReadOnlyMap<? super Key<?>, Object> a) Gets the value of the attribute denoted by this Key from a Map.Gets the value of the attribute denoted by this Key from a Map.getValueProperty(@NonNull Map<? super Key<?>, javafx.beans.property.ObjectProperty<?>> a) Gets the value of the attribute denoted by this Key from a Map.default booleanisAssignable(@Nullable Object value) Returns true if the specified value is assignable with this key.default booleanReturns true if the specified value is the default value of this key.booleanWhether the value may be set to null.propertyAt(@NonNull javafx.collections.ObservableMap<Key<?>, Object> map) Creates a new property for the map entry specified by this key.Use this method to perform a type-safe put operation of an attribute into a Map.default @NonNull ImmutableMap<Key<?>, Object> Use this method to perform a type-safe put operation of an attribute into a Map.Use this method to perform a type-safe put operation of an attribute into a Map.readOnlyPropertyAt(@NonNull javafx.collections.ObservableMap<Key<?>, Object> map) Creates a new read-only property for the map entry specified by this key.Use this method to perform a type-safe remove operation of an attribute on a Map.default @NonNull ImmutableMap<Key<?>, Object> remove(@NonNull ImmutableMap<Key<?>, Object> a) Use this method to perform a type-safe remove operation of an attribute on a 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
-
serialVersionUID
static final long serialVersionUID- See Also:
-
-
Method Details
-
containsKey
Description copied from interface:MapAccessorWhether the map contains all keys required by this map accessor.- Specified by:
containsKeyin interfaceMapAccessor<T>- Parameters:
map- a map- Returns:
- true if map contains all keys required by this map accessor.
-
get
Gets the value of the attribute denoted by this Key from a Map.- Specified by:
getin interfaceMapAccessor<T>- Parameters:
a- A Map.- Returns:
- The value of the attribute.
-
get
Gets the value of the attribute denoted by this Key from a Map.- Specified by:
getin interfaceMapAccessor<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
Use this method to perform a type-safe put operation of an attribute into a Map.- Specified by:
putin interfaceMapAccessor<T>- Parameters:
a- An attribute map.value- The new value.- Returns:
- The old value.
-
put
default @NonNull ImmutableMap<Key<?>,Object> put(@NonNull 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:
putin interfaceMapAccessor<T>- Parameters:
a- An attribute map.value- The new value.- Returns:
- The updated map
-
remove
Use this method to perform a type-safe remove operation of an attribute on a Map.- Specified by:
removein interfaceMapAccessor<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:
removein interfaceMapAccessor<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
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
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
-