com.limegroup.gnutella.settings
Class Setting

java.lang.Object
  extended bycom.limegroup.gnutella.settings.Setting
Direct Known Subclasses:
BooleanSetting, ByteSetting, CharArraySetting, ColorSetting, FileArraySetting, FileSetting, FloatSetting, IntSetting, LongSetting, StringArraySetting, StringSetting

public abstract class Setting
extends java.lang.Object

Private abstract class for an individual setting. Subclasses of this class provide typing for settings.


Field Summary
protected  java.util.Properties DEFAULT_PROPS
          Protected default Properties instance for subclasses.
protected  java.lang.String DEFAULT_VALUE
          Constant for the default value for this Setting.
protected  java.lang.String KEY
          The constant key for this property, specified upon construction.
protected  java.util.Properties PROPS
          Protected Properties instance containing properties for any subclasses.
 
Constructor Summary
protected Setting(java.util.Properties defaultProps, java.util.Properties props, java.lang.String key, java.lang.String defaultValue)
          Constructs a new setting with the specified key and default value.
 
Method Summary
 java.lang.String getKey()
          Get the key for this setting.
 java.lang.String getValueAsString()
          Returns the value as stored in the properties file.
 boolean isDefault()
          Determines whether or not the current value is the default value.
protected abstract  void loadValue(java.lang.String sValue)
          Load value from property string value
 void reload()
          Reload value from properties object
 void revertToDefault()
          Revert to the default value.
 Setting setAlwaysSave(boolean save)
          Sets whether or not this setting should always save, even if it is default.
protected  void setValue(java.lang.String value)
          Set new property value
 boolean shouldAlwaysSave()
          Determines whether or not this value should always be saved to disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PROPS

protected final java.util.Properties DEFAULT_PROPS
Protected default Properties instance for subclasses.


PROPS

protected final java.util.Properties PROPS
Protected Properties instance containing properties for any subclasses.


KEY

protected final java.lang.String KEY
The constant key for this property, specified upon construction.


DEFAULT_VALUE

protected final java.lang.String DEFAULT_VALUE
Constant for the default value for this Setting.

Constructor Detail

Setting

protected Setting(java.util.Properties defaultProps,
                  java.util.Properties props,
                  java.lang.String key,
                  java.lang.String defaultValue)
Constructs a new setting with the specified key and default value. Private access ensures that only this class can construct new Settings.

Parameters:
key - the key for the setting
defaultValue - the defaultValue for the setting
Throws:
IllegalArgumentException - if the key for this setting is already contained in the map of default settings
Method Detail

reload

public void reload()
Reload value from properties object


revertToDefault

public void revertToDefault()
Revert to the default value. It is critically important that the DEFAULT_VALUE is valid, otherwise an infinite loop will be encountered when revertToDefault is called, as invalid values call revertToDefault. Because default values are hard-coded into the program, this is okay.


shouldAlwaysSave

public boolean shouldAlwaysSave()
Determines whether or not this value should always be saved to disk.


setAlwaysSave

public Setting setAlwaysSave(boolean save)
Sets whether or not this setting should always save, even if it is default. Returns this so it can be used during assignment.


isDefault

public boolean isDefault()
Determines whether or not the current value is the default value.


getKey

public java.lang.String getKey()
Get the key for this setting.


getValueAsString

public java.lang.String getValueAsString()
Returns the value as stored in the properties file.


setValue

protected void setValue(java.lang.String value)
Set new property value

Parameters:
value - new property value

loadValue

protected abstract void loadValue(java.lang.String sValue)
Load value from property string value

Parameters:
sValue - property string value