de.erichseifert.gral.util
Class Settings

java.lang.Object
  extended by de.erichseifert.gral.util.Settings

public class Settings
extends Object

Class that stores a specific and a default setting for a certain key. It provides support for class which register as a listener to listen for setting changes.

See Also:
SettingsListener

Nested Class Summary
static class Settings.Key
          A settings key storing a name.
 
Constructor Summary
Settings(SettingsListener listener)
          Creates an empty Settings object.
 
Method Summary
 void addSettingsListener(SettingsListener l)
          Adds a new listener which gets notified if settings have changed.
 void clearDefaults()
          Deletes all default settings.
 void clearSettings()
          Deletes all settings.
<T> T
get(Settings.Key key)
          Returns the setting for the specified key.
 Map<Settings.Key,Object> getDefaults()
          Returns a map containing all default settings.
 Map<Settings.Key,Object> getSettings()
          Returns a map containing all settings.
 Set<SettingsListener> getSettingsListeners()
          Returns an unmodifiable set containing all registered listeners.
 boolean hasDefault(Settings.Key key)
          Returns true if there is a default setting for the specified key.
 boolean hasKey(Settings.Key key)
          Returns true if the specified key is contained.
 boolean hasSetting(Settings.Key key)
          Returns true if there is a setting for the specified key.
 Set<Settings.Key> keySet()
          Returns a set containing all keys of this settings object.
<T> void
remove(Settings.Key key)
          Removes the setting with the specified key.
<T> void
removeDefault(Settings.Key key)
          Removes the default setting with the specified key.
 void removeSettingsListener(SettingsListener l)
          Removes the specified listener.
<T> void
set(Settings.Key key, T value)
          Sets the setting for the specified key.
<T> void
setDefault(Settings.Key key, T value)
          Sets the default setting for the specified key.
 Collection<Object> values()
          Returns a collection containing all settings this object would return.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Settings

public Settings(SettingsListener listener)
Creates an empty Settings object.

Parameters:
listener - Initial settings listener.
Method Detail

addSettingsListener

public void addSettingsListener(SettingsListener l)
Adds a new listener which gets notified if settings have changed.

Parameters:
l - listener to be added

clearDefaults

public void clearDefaults()
Deletes all default settings.


clearSettings

public void clearSettings()
Deletes all settings.


get

public <T> T get(Settings.Key key)
Returns the setting for the specified key.

Type Parameters:
T - return type
Parameters:
key - key of the setting
Returns:
the value of the setting

getDefaults

public Map<Settings.Key,Object> getDefaults()
Returns a map containing all default settings.

Returns:
Map of default settings.

getSettings

public Map<Settings.Key,Object> getSettings()
Returns a map containing all settings.

Returns:
Map of settings.

getSettingsListeners

public Set<SettingsListener> getSettingsListeners()
Returns an unmodifiable set containing all registered listeners.

Returns:
Set of listeners.

hasDefault

public boolean hasDefault(Settings.Key key)
Returns true if there is a default setting for the specified key.

Parameters:
key - Key of the setting.
Returns:
true if the key has a default setting.

hasSetting

public boolean hasSetting(Settings.Key key)
Returns true if there is a setting for the specified key.

Parameters:
key - Key of the setting.
Returns:
true if the key has a setting.

hasKey

public boolean hasKey(Settings.Key key)
Returns true if the specified key is contained.

Parameters:
key - Key to be checked.
Returns:
true if the key exists.

keySet

public Set<Settings.Key> keySet()
Returns a set containing all keys of this settings object. Returns an empty set if no keys are set.

Returns:
Set of keys.

remove

public <T> void remove(Settings.Key key)
Removes the setting with the specified key.

Type Parameters:
T - value type
Parameters:
key - key of the setting

removeDefault

public <T> void removeDefault(Settings.Key key)
Removes the default setting with the specified key.

Type Parameters:
T - value type
Parameters:
key - key of the setting

removeSettingsListener

public void removeSettingsListener(SettingsListener l)
Removes the specified listener.

Parameters:
l - listener to be removed

set

public <T> void set(Settings.Key key,
                    T value)
Sets the setting for the specified key.

Type Parameters:
T - value type
Parameters:
key - key of the setting
value - value of the setting

setDefault

public <T> void setDefault(Settings.Key key,
                           T value)
Sets the default setting for the specified key.

Type Parameters:
T - value type
Parameters:
key - key of the setting
value - default value of the setting

values

public Collection<Object> values()
Returns a collection containing all settings this object would return. Returns an empty collection if no keys are set.

Returns:
Collection of values.


Copyright © 2009-2010. All Rights Reserved.