Class GenericProperties<K>

java.lang.Object
java.util.AbstractMap<K,Object>
java.util.HashMap<K,Object>
io.github.thecsdev.tcdcommons.api.util.collections.GenericProperties<K>
All Implemented Interfaces:
Serializable, Cloneable, Map<K,Object>

public class GenericProperties<K> extends HashMap<K,Object>
A HashMap that stores Objects that represent "property" values, and the keys represent "property" names.
This implementation allows for storing and retrieving properties and their values using generics.
See Also:
  • Constructor Details

    • GenericProperties

      public GenericProperties()
  • Method Details

    • getProperty

      @Nullable public final <V> V getProperty(K key) throws ClassCastException
      Uses HashMap.get(Object) to obtain the value of a given property, after which it is casted to <V> and returned.
      Parameters:
      key - The property key.
      Throws:
      ClassCastException - If a value is present, but it cannot be cast to type <V>.
      See Also:
    • getProperty

      @Nullable public final <V> V getProperty(K key, V defaultValue) throws ClassCastException
      Uses getProperty(Object) to obtain the value of a given property. If getProperty(Object) returns null, the "default value" will be returned instead.
      Parameters:
      key - The property key.
      defaultValue - The value that will be returned if getProperty(Object) returns null.
      Throws:
      ClassCastException - If getProperty(Object) throws it.
    • getPropertyOrDefault

      @Nullable public final <V> V getPropertyOrDefault(K key, V defaultValue)
      Uses getProperty(Object) to obtain the value of a given property. If getProperty(Object) returns null or throws a ClassCastException, setProperty(Object, Object...) will be used to set the property to the "default value", after which the "default value" will be returned.
      Parameters:
      key - The property key.
      defaultValue - The value that will be returned if getProperty(Object) returns null.
    • setProperty

      @SafeVarargs @Nullable public final <V> V setProperty(K key, V... value) throws IllegalArgumentException
      Assigns a new value <V> for a given property.
      Parameters:
      key - The property key.
      value - The new value for the given property. Must pass a single Object here. Do not pass any arrays, null arrays, or arrays whose length is not 1.
      Returns:
      The previous value of the given property, or null if no value of the given type was assigned.
      Throws:
      IllegalArgumentException - If the "value" array is invalid, null, or its length is not 1.