- 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
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 Tdefault booleancontainsKey(Map<Key<?>, Object> map) Whether the map contains all keys required by this map accessor.default @Nullable TGets the value of the attribute denoted by this Key from a Map.default @Nullable Tget(ReadOnlyMap<? super Key<?>, Object> a) Gets the value of the attribute denoted by this Key from a Map.default @Nullable TGets 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 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.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 TUse 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 TUse 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 TUse this method to perform a type-safe remove operation of an attribute on a Map.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.default javafx.beans.binding.Binding<T> 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 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
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
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(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 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
-