com.emarsys.ecommon.prefs.config
Class GenericSetting

java.lang.Object
  extended by com.emarsys.ecommon.prefs.config.GenericSetting
All Implemented Interfaces:
ISetting, java.io.Serializable

public class GenericSetting
extends java.lang.Object
implements ISetting

GenericSetting represents some kind of the reference implementation of ISetting.

TODO special equals() and hashCode() contract

Author:
Michael "kULO" Kulovits
See Also:
Serialized Form

Field Summary
protected  SettingMode mode
           
protected  java.lang.String name
           
protected  java.lang.String value
           
 
Fields inherited from interface com.emarsys.ecommon.prefs.config.ISetting
DEF_DATE_FORMAT
 
Constructor Summary
GenericSetting()
           
GenericSetting(ISetting isetting)
           
GenericSetting(java.lang.String name, java.lang.String value)
           
GenericSetting(java.lang.String name, java.lang.String value, SettingMode mode)
           
 
Method Summary
 boolean equals(java.lang.Object that)
           Returns false if the passed Object is not an instance of ISetting or has a different String name than this instance.
static boolean getAsBoolean(java.lang.String value)
           
static java.util.Date getAsDate(java.lang.String value, java.lang.String format)
           
static double getAsDouble(java.lang.String value)
           
static int getAsInt(java.lang.String value)
           
static java.util.List<java.lang.String> getAsList(java.lang.String value)
           
static long getAsLong(java.lang.String value)
           
 boolean getBooleanValue()
          Parses the setting's value and converts it to a boolean value.
 java.util.Date getDateValue()
          Parses the setting's value assuming the default date format and converts it to a Date instance.
 java.util.Date getDateValue(java.lang.String format)
          Parses the setting's value using the passed date format and converts it to a Date instance.
 double getDoubleValue()
          Parses the setting's value and converts it to a double value.
 int getIntValue()
          Parses the setting's value and converts it to an int.
 java.util.List<java.lang.String> getListValues()
          Parses the setting's value which is assumed to be a comma seperated list and converts it to a List instance.
 long getLongValue()
          Parses the setting's value and converts it to a long value.
 SettingMode getMode()
          Retrieves the SettingMode associated with the ISetting.
 java.lang.String getName()
          The unique and persistent name of the setting.
 java.lang.String getValue()
          Retrieves the persistent String value of the ISetting.
 int hashCode()
          Creates a hash code for this ISetting that solely refers to its unique name.
 void setMode(SettingMode mode)
          Set/updates the ISetting's mode.
 void setName(java.lang.String name)
          Sets/updates the unique name of the ISetting.
 void setValue(java.lang.String value)
          Sets/updates the value of the ISetting.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

protected java.lang.String name

value

protected java.lang.String value

mode

protected SettingMode mode
Constructor Detail

GenericSetting

public GenericSetting()

GenericSetting

public GenericSetting(java.lang.String name,
                      java.lang.String value)
Parameters:
name -
value -

GenericSetting

public GenericSetting(java.lang.String name,
                      java.lang.String value,
                      SettingMode mode)
Parameters:
name -
value -
mode -

GenericSetting

public GenericSetting(ISetting isetting)
Parameters:
isetting -
Method Detail

getAsList

public static java.util.List<java.lang.String> getAsList(java.lang.String value)
Parameters:
value -
Returns:

getAsInt

public static int getAsInt(java.lang.String value)
Parameters:
value -
Returns:

getAsLong

public static long getAsLong(java.lang.String value)
Parameters:
value -
Returns:

getAsDouble

public static double getAsDouble(java.lang.String value)
Parameters:
value -
Returns:

getAsBoolean

public static boolean getAsBoolean(java.lang.String value)
Parameters:
value -
Returns:

getAsDate

public static java.util.Date getAsDate(java.lang.String value,
                                       java.lang.String format)
                                throws java.text.ParseException
Parameters:
value -
format -
Returns:
Throws:
java.text.ParseException

getName

public java.lang.String getName()
Description copied from interface: ISetting
The unique and persistent name of the setting.

Specified by:
getName in interface ISetting
Returns:
the non-null name of the ISetting
See Also:
ISetting.getName()

setName

public void setName(java.lang.String name)
Description copied from interface: ISetting
Sets/updates the unique name of the ISetting. The update needs not to have a persistent effect (altough it might be case if your ISetting is implemented as a managed JPA entity, for instance). Thus if you want to persistently update your Configuration you have to use ConfigurationBackend.set(ISetting).

Specified by:
setName in interface ISetting
Parameters:
name - - the name of the setting
See Also:
ISetting.setName(java.lang.String)

getValue

public java.lang.String getValue()
Description copied from interface: ISetting
Retrieves the persistent String value of the ISetting.

Specified by:
getValue in interface ISetting
Returns:
the non-null value of the ISetting
See Also:
ISetting.getValue()

getIntValue

public int getIntValue()
Description copied from interface: ISetting
Parses the setting's value and converts it to an int. Throws a an unchecked instance of RuntimeException on parsing errors.

Specified by:
getIntValue in interface ISetting
Returns:
the setting's integer value
See Also:
ISetting.getIntValue()

getLongValue

public long getLongValue()
Description copied from interface: ISetting
Parses the setting's value and converts it to a long value. Throws a an unchecked instance of RuntimeException on parsing errors.

Specified by:
getLongValue in interface ISetting
Returns:
the setting's long value
See Also:
ISetting.getLongValue()

getDoubleValue

public double getDoubleValue()
Description copied from interface: ISetting
Parses the setting's value and converts it to a double value. Throws a an unchecked instance of RuntimeException on parsing errors.

Specified by:
getDoubleValue in interface ISetting
Returns:
the setting's double value
See Also:
ISetting.getDoubleValue()

getBooleanValue

public boolean getBooleanValue()
Description copied from interface: ISetting
Parses the setting's value and converts it to a boolean value. Throws a an unchecked instance of RuntimeException on parsing errors.

Specified by:
getBooleanValue in interface ISetting
Returns:
the setting's boolean value
See Also:
ISetting.getBooleanValue()

getDateValue

public java.util.Date getDateValue()
                            throws java.text.ParseException
Description copied from interface: ISetting
Parses the setting's value assuming the default date format and converts it to a Date instance.

Specified by:
getDateValue in interface ISetting
Returns:
the setting's Date value
Throws:
java.text.ParseException - - on any parsing error.
See Also:
ISetting.getDateValue()

getDateValue

public java.util.Date getDateValue(java.lang.String format)
                            throws java.text.ParseException
Description copied from interface: ISetting
Parses the setting's value using the passed date format and converts it to a Date instance.

Specified by:
getDateValue in interface ISetting
Parameters:
format - - the SimpleDateFormat in a String form
Returns:
the setting's Date value
Throws:
java.text.ParseException - - on any parsing error.
See Also:
ISetting.getDateValue(java.lang.String)

getListValues

public java.util.List<java.lang.String> getListValues()
Description copied from interface: ISetting
Parses the setting's value which is assumed to be a comma seperated list and converts it to a List instance. Throws a an unchecked instance of RuntimeException on parsing errors.

Specified by:
getListValues in interface ISetting
Returns:
the setting's List values
See Also:
ISetting.getListValues()

setValue

public void setValue(java.lang.String value)
Description copied from interface: ISetting
Sets/updates the value of the ISetting. The update needs not to have a persistent effect (altough it might be case if your ISetting is implemented as a managed JPA entity, for instance). Thus if you want to persistently update your Configuration you have to use ConfigurationBackend.set(ISetting).

Specified by:
setValue in interface ISetting
Parameters:
value - - the (new) value of the setting
See Also:
ISetting.setValue(java.lang.String)

getMode

public SettingMode getMode()
Description copied from interface: ISetting
Retrieves the SettingMode associated with the ISetting. The SettingMode is transient and volatile, that means it needs not to be stored persistently in the backend and might be changed by chained backends several times during a call to ConfigurationBackend.get(String).

Specified by:
getMode in interface ISetting
Returns:
the SettingMode of this ISetting, never null.
See Also:
ISetting.getMode()

setMode

public void setMode(SettingMode mode)
Description copied from interface: ISetting
Set/updates the ISetting's mode. The SettingMode is not stored persistently for settings and mighty change on its way through ConfigurationBackends.

Specified by:
setMode in interface ISetting
Parameters:
mode - the mode to set
See Also:
com.emarsys.ecommon.prefs.config.ISetting#setMode(com.emarsys.core.setting.config.SettingMode)

equals

public boolean equals(java.lang.Object that)
Description copied from interface: ISetting

Returns false if the passed Object is not an instance of ISetting or has a different String name than this instance.

Only the name is relevant for an equality check of ISetting instances, this has to ensured in every subtype!

Specified by:
equals in interface ISetting
Overrides:
equals in class java.lang.Object
Parameters:
that - the object with which to compare
Returns:
true if this object has the same setting name as 'that'; false otherwise.
See Also:
ISetting.equals(Object)

hashCode

public int hashCode()
Description copied from interface: ISetting
Creates a hash code for this ISetting that solely refers to its unique name. This has to be ensured in subclasses too!

Specified by:
hashCode in interface ISetting
Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this setting
See Also:
ISetting.hashCode()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2010 emarsys AG. All Rights Reserved.