com.opera.core.systems.preferences
Class AbstractOperaPreferences.AbstractPreference

java.lang.Object
  extended by com.opera.core.systems.preferences.AbstractOperaPreferences.AbstractPreference
All Implemented Interfaces:
OperaPreferences.OperaPreference
Direct Known Subclasses:
OperaFilePreferences.FilePreference, OperaGenericPreferences.GenericPreference, OperaScopePreferences.ScopePreference
Enclosing class:
AbstractOperaPreferences

public abstract static class AbstractOperaPreferences.AbstractPreference
extends Object
implements OperaPreferences.OperaPreference

Shared methods for the OperaPreferences.OperaPreference interface for keeping the local cache of individual preference up to date.

See Also:
OperaScopePreferences.ScopePreference, OperaFilePreferences.FilePreference

Field Summary
protected  Object defaultValue
           
 
Constructor Summary
AbstractOperaPreferences.AbstractPreference(String section, String key, Object value)
           
 
Method Summary
 Object getDefaultValue()
          Gets the default value of the preference.
 String getKey()
          Gets the key of this preference.
 String getSection()
          Gets the section this preference belongs to.
 Object getValue()
          Gets the value of this preference.
 Object getValue(boolean raw)
          Returns the value of the preference.
protected  boolean isTruthy(Object o)
          Whether object holds a "truthy" value.
protected  Object sanitizeValue(Object value)
          If object is a boolean, convert it to "1" or "0".
 void setValue(Object value)
          Sets the value of this preference.
 String toString()
          Gets the value of this preference.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultValue

protected Object defaultValue
Constructor Detail

AbstractOperaPreferences.AbstractPreference

public AbstractOperaPreferences.AbstractPreference(String section,
                                                   String key,
                                                   Object value)
Method Detail

getSection

public String getSection()
Description copied from interface: OperaPreferences.OperaPreference
Gets the section this preference belongs to.

Specified by:
getSection in interface OperaPreferences.OperaPreference
Returns:
the parent section of this preference

getKey

public String getKey()
Description copied from interface: OperaPreferences.OperaPreference
Gets the key of this preference.

Specified by:
getKey in interface OperaPreferences.OperaPreference
Returns:
the key of this preference

getValue

public Object getValue()
Description copied from interface: OperaPreferences.OperaPreference
Gets the value of this preference.

Specified by:
getValue in interface OperaPreferences.OperaPreference
Returns:
the value of this preference

getValue

public Object getValue(boolean raw)
Returns the value of the preference. If argument raw is true, it will be returned as it is saved in the cache, meaning we won't try to figure out whether the object is /actually/ a boolean or an integer. Preferences in Opera is a messy business. Some boolean values are stored as integers and everything will be returned as strings. This is an attempt at making sense of it all because we want the user-facing API to be nice: If the user queries a pref's value and the value is similar to a boolean value, we will return it as a boolean. Values stored as strings with a truthy value ("0" or "1") are considered boolean. Values stored as integers will always be returned as integers. Other values will be returned as objects and will rely on Java autoboxing.

Parameters:
raw - set to true to return the raw data in cache
Returns:
value of the preference

setValue

public void setValue(Object value)
Description copied from interface: OperaPreferences.OperaPreference
Sets the value of this preference.

Specified by:
setValue in interface OperaPreferences.OperaPreference
Parameters:
value - the new value

getDefaultValue

public Object getDefaultValue()
Description copied from interface: OperaPreferences.OperaPreference
Gets the default value of the preference.

Specified by:
getDefaultValue in interface OperaPreferences.OperaPreference
Returns:
the default value of this preference

toString

public String toString()
Description copied from interface: OperaPreferences.OperaPreference
Gets the value of this preference.

Specified by:
toString in interface OperaPreferences.OperaPreference
Overrides:
toString in class Object
Returns:
the value of this preference

sanitizeValue

protected Object sanitizeValue(Object value)
If object is a boolean, convert it to "1" or "0".

Parameters:
value - an object
Returns:
a sanitized object

isTruthy

protected boolean isTruthy(Object o)
Whether object holds a "truthy" value. As a string it equals "0", "1", "true" or "false".

Parameters:
o - object to check
Returns:
true if value is "truthy", false otherwise


Copyright © 2012. All Rights Reserved.