Module org.jhotdraw8.fxcollection
Class AbstractKey<T>
java.lang.Object
org.jhotdraw8.fxcollection.typesafekey.AbstractKey<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
Serializable,Key<T>,MapAccessor<T>
- Direct Known Subclasses:
NonNullObjectKey,NullableObjectKey,TransientKey
A name which provides typesafe access to a map entry.
A Key has a name, a type and a default value.
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
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractKey(@NonNull String name, @NonNull Type clazz) Creates a new instance with the specified name, type token class, default value null, and allowing null values.AbstractKey(@NonNull String name, @NonNull Type clazz, boolean isNullable, @Nullable T initialValue) Creates a new instance with the specified name, type token class, default value, and allowing or disallowing null values.Creates a new instance with the specified name, type token class, default value, and allowing or disallowing null values.AbstractKey(@NonNull String name, @NonNull Type clazz, @Nullable Class<?>[] typeParameters, boolean isNullable, @Nullable T initialValue) AbstractKey(@Nullable String name, @NonNull Type clazz, boolean isNullable, boolean isTransient, @Nullable T initialValue) -
Method Summary
Modifier and TypeMethodDescriptionReturns the default value of this map accessor.getName()Returns the name string.Returns the value type of this map accessor.booleanWhether the value may be set to null.booleanWhether the value needs to be made persistent.toString()Returns the name string.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jhotdraw8.fxcollection.typesafekey.Key
cast, containsKey, get, get, getValue, getValueProperty, isAssignable, isDefault, propertyAt, put, put, putValue, readOnlyPropertyAt, remove, remove, valueAtMethods inherited from interface org.jhotdraw8.fxcollection.typesafekey.MapAccessor
getRawValueType, set
-
Constructor Details
-
AbstractKey
Creates a new instance with the specified name, type token class, default value null, and allowing null values.- Parameters:
name- The name of the key.clazz- The type of the value.
-
AbstractKey
-
AbstractKey
Creates a new instance with the specified name, type token class, default value, and allowing or disallowing null values.- Parameters:
name- The name of the key.clazz- The type of the value.initialValue- The default value.
-
AbstractKey
public AbstractKey(@NonNull String name, @NonNull Type clazz, boolean isNullable, @Nullable T initialValue) Creates a new instance with the specified name, type token class, default value, and allowing or disallowing null values.- Parameters:
name- The name of the key.clazz- The type of the value.isNullable- Whether the value may be set to nullinitialValue- The default value.
-
AbstractKey
-
AbstractKey
-
-
Method Details
-
getName
Returns the name string.- Specified by:
getNamein interfaceMapAccessor<T>- Returns:
- name string.
-
getValueType
Description copied from interface:MapAccessorReturns the value type of this map accessor.If the value type has type parameters, make sure to create it using
TypeToken.- Specified by:
getValueTypein interfaceMapAccessor<T>
-
getDefaultValue
Description copied from interface:MapAccessorReturns the default value of this map accessor.The default value of an attribute or property is the value used when that attribute or property is not specified.
- Specified by:
getDefaultValuein interfaceMapAccessor<T>- Returns:
- the default value
-
isNullable
public boolean isNullable()Description copied from interface:KeyWhether the value may be set to null.- Specified by:
isNullablein interfaceKey<T>- Returns:
- true if nullable
-
isTransient
public boolean isTransient()Description copied from interface:MapAccessorWhether the value needs to be made persistent.- Specified by:
isTransientin interfaceMapAccessor<T>- Returns:
- true if transient
-
toString
Returns the name string.
-