org.gridlab.gat
Class Preferences

java.lang.Object
  extended by org.gridlab.gat.Preferences
All Implemented Interfaces:
Serializable

public class Preferences
extends Object
implements Serializable

An instance of this class represents user preferences for selecting adaptors. For an overview of the known preferences used by JavaGAT and known adaptors see: known preferences.

See Also:
Serialized Form

Constructor Summary
Preferences()
          Constructs a new Preferences with no mappings.
Preferences(Preferences p)
          Copy constructor.
Preferences(Properties properties)
          Constructs a new Preferences object out of a Properties object.
Preferences(String propertyFile)
          Constructs a new Preferences object out of a Java propertyFile.
 
Method Summary
 Object clone()
          Returns a shallow clone of this Preferences.
 boolean containsKey(String key)
          Returns true if the supplied object equals() a key in this Preferences.
 boolean containsValue(Object value)
          Returns true if this Preferences contains a value o, such that o.equals(value).
 boolean equals(Object o)
           
 Object get(String key)
          Returns the value to which the specified key is mapped in the preferences.
 Object get(String key, Object defaultValue)
          Returns the value to which the specified key is mapped in the preferences.
 int hashCode()
           
 Set<String> keySet()
          Returns a "set view" of this Preferences' keys.
 Object put(String key, Object value)
          Associates the specified value with the specified key in this map (optional operation).
 void putAll(Preferences p)
          Copies all of the mappings from the specified Preferences to this Preferences.
 void putAll(Properties properties)
          Copies all of the mappings from the specified Properties to this Preferences.
 Object remove(String key)
          Removes from the preferences and returns the value which is mapped by the supplied key.
 String toString()
          Converts this Preferences to a String, surrounded by braces, and with key/value pairs listed with an equals sign between, separated by a comma and space.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Preferences

public Preferences()
Constructs a new Preferences with no mappings.


Preferences

public Preferences(Preferences p)
Copy constructor.

Throws:
NullPointerException - if p is null, or contains null keys or values

Preferences

public Preferences(String propertyFile)
Constructs a new Preferences object out of a Java propertyFile. All the key value pairs in the propertyFile will be added to the new Preferences object.

Parameters:
propertyFile - the property file containing the preferences.

Preferences

public Preferences(Properties properties)
Constructs a new Preferences object out of a Properties object. All the key value pairs in the Properties object will be added to the new Preferences object.

Parameters:
properties - the Properties object containing the preferences.
Method Detail

put

public Object put(String key,
                  Object value)
Associates the specified value with the specified key in this map (optional operation). If the map previously contained a mapping for this key, the old value is replaced.

Parameters:
key - key with which the specified value is to be associated.
value - value to be associated with the specified key.
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
Throws:
UnsupportedOperationException - if the put operation is not supported by this map.
ClassCastException - if the class of the specified key or value prevents it from being stored in this map.
IllegalArgumentException - if some aspect of this key or value prevents it from being stored in this map.
NullPointerException - this map does not permit null keys or values, and the specified key or value is null.

get

public Object get(String key)
Returns the value to which the specified key is mapped in the preferences.

Parameters:
key - a key in the preferences
Returns:
the value to which the key is mapped in the preferences; null if the key is not mapped to any value
Throws:
NullPointerException - if the key or value is null.

get

public Object get(String key,
                  Object defaultValue)
Returns the value to which the specified key is mapped in the preferences.

Parameters:
key - a key in the preferences
Returns:
the value to which the key is mapped in the preferences; null if the key is not mapped to any value
Throws:
NullPointerException - if the key or value is null.

putAll

public void putAll(Preferences p)
Copies all of the mappings from the specified Preferences to this Preferences. These mappings will replace any mappings that this Preferences had for any of the keys currently in the specified Preferences.

Parameters:
p - Preferences to be stored in this map.
Throws:
NullPointerException - if p is null, or contains null keys or values

putAll

public void putAll(Properties properties)
Copies all of the mappings from the specified Properties to this Preferences. These mappings will replace any mappings that this Preferences had for any of the keys currently in the specified Preferences.

Parameters:
properties - Properties to be stored in this map.
Throws:
NullPointerException - if properties is null, or contains null keys or values

clone

public Object clone()
Returns a shallow clone of this Preferences. The Hashtable itself is cloned, but its contents are not. This is O(n).

Overrides:
clone in class Object
Returns:
the clone

remove

public Object remove(String key)
Removes from the preferences and returns the value which is mapped by the supplied key. If the key maps to nothing, then the table remains unchanged, and null is returned.

Parameters:
key - the key used to locate the value to remove
Returns:
whatever the key mapped to, if present

containsKey

public boolean containsKey(String key)
Returns true if the supplied object equals() a key in this Preferences.

Parameters:
key - the key to search for in this Preferences
Returns:
true if the key is in the table
Throws:
NullPointerException - if key is null

keySet

public Set<String> keySet()
Returns a "set view" of this Preferences' keys. The set is backed by the hashtable, so changes in one show up in the other. The set supports element removal, but not element addition. The set is properly synchronized on the original hashtable.

Returns:
a set view of the keys

containsValue

public boolean containsValue(Object value)
Returns true if this Preferences contains a value o, such that o.equals(value). This is the new API for the old contains().

Parameters:
value - the value to search for in this Preferences
Returns:
true if at least one key maps to the value
Throws:
NullPointerException - if value is null

toString

public String toString()
Converts this Preferences to a String, surrounded by braces, and with key/value pairs listed with an equals sign between, separated by a comma and space. For example, "{a=1, b=2}".

NOTE: if the toString() method of any key or value throws an exception, this will fail for the same reason.

Overrides:
toString in class Object
Returns:
the string representation

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object