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>

@Virtual public class GenericProperties<K> extends HashMap<K,Object>
HashMap implementation that allows for storing and retrieving values using generics.
See Also:
  • 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. Returns null if the key is not found or if the type from the map does not match the expected type.

      Note:
      Avoid using primitive-type Classes like int.class. They aren't properly supported. Use non-primitives like Integer.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 is null.
    • 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 is null or a type mismatch occurs, the default value is returned, and placed into the map if non-null.

      Note:
      Avoid using primitive-type Classes like int.class. They aren't properly supported. Use non-primitives like Integer.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.
      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 is null.
    • 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-type Classes like int.class. They aren't properly supported. Use non-primitives like Integer.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 null if there was no mapping for key, cast to V if the types match, otherwise null.
      Throws:
      NullPointerException - if key or type is null.