Class Settings

All Implemented Interfaces:
Serializable, Cloneable, Map<String,Object>

public final class Settings extends HashMap<String,Object>
Implements a HashMap with additional functionality.
See Also:
  • Constructor Details

    • Settings

      public Settings()
      Constructs an empty Settings instance with the default initial capacity and load factor.
    • Settings

      public Settings(int initialCapacity, float loadFactor)
      Constructs an empty Settings instance with the specified initial capacity and load factor.
      Parameters:
      initialCapacity - the initial capacity.
      loadFactor - the load factor.
      Throws:
      IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive.
    • Settings

      public Settings(int initialCapacity)
      Constructs an empty Settings instance with the specified initial capacity and a default load factor.
      Parameters:
      initialCapacity - the initial capacity.
      Throws:
      IllegalArgumentException - if the initial capacity is negative.
  • Method Details

    • put

      public Object put(String key, Object value)
      Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced. Registered listeners are notified of the changed mappings.
      Specified by:
      put in interface Map<String,Object>
      Overrides:
      put in class HashMap<String,Object>
      Parameters:
      key - the key with which the specified value is to be associated.
      value - value to be associated with the specified key.
      Returns:
      the previous value associated with key or null.
      Throws:
      NullPointerException - if an argument is null.
    • putAll

      public void putAll(Map<? extends String,? extends Object> map)
      Copies all of the mappings from the specified map to this map. These mappings will replace any mappings that this map had for any of the keys currently in the specified map. Registered listeners are notified of the changed mappings.
      Specified by:
      putAll in interface Map<String,Object>
      Overrides:
      putAll in class HashMap<String,Object>
      Parameters:
      map - the mappings to be stored in this map
      Throws:
      NullPointerException - if map is null.
    • putAll

      public void putAll(Properties properties)
      Copies all of the mappings of properties to this map. These mappings replace any mappings that this map had for any of the keys currently in the specified Properties. Registered listeners are notified of the changed mappings.
      Parameters:
      properties - the properties to copy to this map.
      Throws:
      NullPointerException - if properties is null.
    • putMap

      public void putMap(Map<?,?> map)
      Copies all of the mappings of supplied map to this map. These mappings replace any mappings that this map had for any of the keys currently in the specified map. Registered listeners are notified of the changed mappings.
      Parameters:
      map - the map to copy to this map.
      Throws:
      NullPointerException - if map is null.
    • putDefaults

      public void putDefaults(Settings settings)
      Adds the mappings of settings not contained in this map. The mappings that currently exist in this map are not changed. Registered listeners are notified of the changed mappings.
      Parameters:
      settings - the settings to add to this map.
      Throws:
      NullPointerException - if settings is null.
    • putDefaults

      public void putDefaults(Properties properties)
      Adds the mappings of properties not contained in this map. The mappings that currently exist in this map are not changed. Registered listeners are notified of the changed mappings.
      Parameters:
      properties - the properties to add to this map.
      Throws:
      NullPointerException - if properties is null.
    • remove

      public Object remove(Object key)
      Removes the mapping for the specified key from this map if present. Registered listeners are notified of the removed mappings.
      Specified by:
      remove in interface Map<String,Object>
      Overrides:
      remove in class HashMap<String,Object>
      Parameters:
      key - the key whose mapping is to be removed from the map.
      Returns:
      the previous value associated with key or null.
      Throws:
      NullPointerException - if key is null.
    • clear

      public void clear()
      Removes all of the mappings from this map. The map will be empty after this call returns. Registered listeners are notified of the removed mappings.
      Specified by:
      clear in interface Map<String,Object>
      Overrides:
      clear in class HashMap<String,Object>
    • get

      public Object get(Object key)
      Returns the value to which the specified object key is mapped.
      Specified by:
      get in interface Map<String,Object>
      Overrides:
      get in class HashMap<String,Object>
      Parameters:
      key - the object key of the mapping.
      Returns:
      the object value or null if not defined.
      Throws:
      NullPointerException - if key is null.
    • get

      public Object get(String key)
      Returns the value to which the specified string key is mapped.
      Parameters:
      key - the string key of the mapping.
      Returns:
      the object value or null if not defined.
      Throws:
      NullPointerException - if key is null.
    • get

      public Object get(String key, Object defval)
      Returns the object value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the object value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
    • getString

      public String getString(String key)
      Returns the string value of a mapping or null if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the string value or null if not defined.
      Throws:
      NullPointerException - if key is null.
    • getString

      public String getString(String key, String defval)
      Returns the string value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the string value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
    • getDouble

      public double getDouble(String key) throws NumberFormatException
      Returns the double value of a mapping or 0 if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the double value or 0 if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a Double.
    • getDouble

      public double getDouble(String key, double defval) throws NumberFormatException
      Returns the double value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the double value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a Double.
    • getInt

      public int getInt(String key) throws NumberFormatException
      Returns the integer value of a mapping or 0 if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the integer value or 0 if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not an Integer.
    • getInt

      public int getInt(String key, int defval) throws NumberFormatException
      Returns the integer value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the integer value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not an Integer.
    • getLong

      public long getLong(String key) throws NumberFormatException
      Returns the long value of a mapping or 0 if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the long value or 0 if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a Long.
    • getLong

      public long getLong(String key, long defval) throws NumberFormatException
      Returns the long value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the long value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a Long.
    • getBigDecimal

      public BigDecimal getBigDecimal(String key) throws NumberFormatException
      Returns the decimal value of a mapping or ZERO if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the decimal value or ZERO if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a BigDecimal.
    • getBigDecimal

      public BigDecimal getBigDecimal(String key, BigDecimal defval) throws NumberFormatException
      Returns the decimal value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the decimal value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
      NumberFormatException - if the value is not a BigDecimal.
    • getBoolean

      public boolean getBoolean(String key)
      Returns the boolean value of a mapping or false if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the boolean value or false if not defined.
      Throws:
      NullPointerException - if key is null.
      ClassCastException - if the value is not a Boolean.
    • getBoolean

      public boolean getBoolean(String key, boolean defval)
      Returns the boolean value of the key or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the boolean value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
    • getDate

      public Date getDate(String key)
      Returns the date value of a mapping or null if not defined.
      Parameters:
      key - the key of the mapping.
      Returns:
      the date value or null if not defined.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if the value is not a Date.
    • getDate

      public Date getDate(String key, Date defval)
      Returns the date value of a mapping or defval if not defined.
      Parameters:
      key - the key of the mapping.
      defval - the default value.
      Returns:
      the date value or defval if not defined.
      Throws:
      NullPointerException - if key is null.
      IllegalArgumentException - if the value is not a Date.
    • addPropertyChangeListener

      public void addPropertyChangeListener(String key, PropertyChangeListener listener)
      Adds a listener to the list of change listeners of this map.
      Parameters:
      key - the key of the mapping.
      listener - the property change listener.
      Throws:
      NullPointerException - if an argument is null.
    • removePropertyChangeListener

      public void removePropertyChangeListener(String key, PropertyChangeListener listener)
      Removes a listener from the list of change listeners of this map.
      Parameters:
      key - the key of the mapping.
      listener - the property change listener.
      Throws:
      NullPointerException - if an argument is null.