Class GenericProperties<K>
java.lang.Object
java.util.AbstractMap<K,Object>
java.util.HashMap<K,Object>
com.thecsdev.common.util.collections.GenericProperties<K>
- All Implemented Interfaces:
Serializable, Cloneable, Map<K,Object>
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal <V> VgetProperty(@NotNull Class<V> type, K key) Deprecated.final <V> VgetProperty(@NotNull Class<V> type, K key, V defaultValue) Retrieves the property associated with the key, casting it to the specified type.final <V> VsetProperty(@NotNull Class<V> type, K key, V value) Associates the specified value with the specified key in this map.Methods inherited from class HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class AbstractMap
equals, hashCode, toString
-
Constructor Details
-
GenericProperties
public GenericProperties()
-
-
Method Details
-
getProperty
@Deprecated @Nullable public final <V> V getProperty(@NotNull @NotNull Class<V> type, @NotNull K key) throws NullPointerException Deprecated.Retrieves the property associated with the key, casting it to the specified type. Returnsnullif the key is not found or if the type from the map does not match the expected type.Note:
Avoid using primitive-typeClasses likeint.class. They aren't properly supported. Use non-primitives likeInteger.class.- Type Parameters:
V- The desired value type.- Parameters:
type- The Class object representing the desired return type (type token).key- The key to look up.- Returns:
- The value of type V, or null on mismatch/absence.
- Throws:
NullPointerException- if key or type isnull.
-
getProperty
@Contract("_, _, !null -> !null; _, _, _ -> _;") @Nullable public final <V> V getProperty(@NotNull @NotNull Class<V> type, @NotNull K key, @Nullable V defaultValue) throws NullPointerException Retrieves the property associated with the key, casting it to the specified type. If the value is present and the correct type, it is returned. If the value isnullor a type mismatch occurs, the default value is returned, and placed into the map if non-null.Note:
Avoid using primitive-typeClasses likeint.class. They aren't properly supported. Use non-primitives likeInteger.class.- Type Parameters:
V- The desired value type.- Parameters:
type- TheClassobject representing the desired return type (type token).key- The key to look up.defaultValue- The value to return if the key is not found or types mismatch, and to insert if non-null.- Returns:
- The value of type V, the default value, or
null. - Throws:
NullPointerException- if key or type isnull.
-
setProperty
@Nullable public final <V> V setProperty(@NotNull @NotNull Class<V> type, @NotNull K key, @Nullable V value) throws NullPointerException Associates the specified value with the specified key in this map. The method checks if the value's type matches the expected type V.Note:
Avoid using primitive-typeClasses likeint.class. They aren't properly supported. Use non-primitives likeInteger.class.- Type Parameters:
V- The type of the value.- Parameters:
type- The Class object representing the expected type of the value (type token).key- The key with which the specified value is to be associated.value- The value to be associated with the specified key.- Returns:
- The previous value associated with key, or
nullif there was no mapping for key, cast to V if the types match, otherwisenull. - Throws:
NullPointerException- if key or type isnull.
-