org.jostraca.util
Class PropertySet

java.lang.Object
  extended byorg.jostraca.util.PropertySet
Direct Known Subclasses:
ValueSet

public class PropertySet
extends java.lang.Object

Stores an editable list of name-value pairs.
Example

    PropertySet mps = new PropertySet();
    mps.load( "foo   = bar \n"
             +"white = black \n"
             );
    PropertySet ps = (PropertySet) mps;
    ps.has( "foo" );                  // returns true
    String   bar   = ps.get( "foo" ); // returns "bar"
    String[] names = ps.getNames();   // returns ["foo","white"]
 
WARNING
Surrounding whitepace is removed from names and values. Order is not preserved: getNames and getNamesEnum do not return names in the order they originally appeared. Contracts:


Field Summary
static java.lang.String CN
           
static java.lang.String END_angle
           
static java.lang.String END_brace
           
static java.lang.String MOD_escape
           
static java.lang.String MOD_remove_backslash
           
static java.lang.String MOD_trim
           
static java.lang.String NO_SUBSTITUTIONS_SUFFIX
           
static java.lang.String START_angle
           
static java.lang.String START_brace
           
 
Constructor Summary
PropertySet()
          Create an empty PropertySet.
PropertySet(java.io.File pFile)
          Create a PropertySet from a file.
PropertySet(java.util.Hashtable pHashtable)
          Create from a Hashtable.
PropertySet(java.util.Map pMap)
          Create from a Map.
PropertySet(java.lang.Object[] pNameValuePairs)
          Create from an Object[].
PropertySet(PropertySet pPropertySet)
          Create from a PropertySet.
PropertySet(java.lang.String pFilePath)
          Create a PropertySet from a file path.
 
Method Summary
 void clear()
          Clear all name-value pairs.
 java.lang.Object clone()
          Clone ProperySet.
 boolean contains(PropertySet pPropertySet)
          True if specified PropertySet is contained in this PropertySet.
 void copy(java.lang.String pFromName, java.lang.String pToName)
          Copy a value from one name to another.
 boolean equals(java.lang.Object pObject)
          True if specified Object is equal to this PropertySet.
 java.lang.String get(java.lang.String pName)
          Get a value by name, return empty String if undefined.
 java.lang.String get(java.lang.String pName, java.lang.String pDefault)
          Get a value by name, return default if not defined.
 java.lang.String[] getList(java.lang.String pName, java.lang.String pSeparationChars)
          Get a list of values.
 java.lang.String[] getNames()
          Get a String array of names.
 java.util.Enumeration getNamesEnum()
          Get an Enumeration of names.
 java.util.List getNamesList()
          Get a List of names.
 java.lang.String getSourceValue(java.lang.String pName)
          Get property value without performing substitutions.
 java.lang.String[] getValues()
          Get a String array of values.
 java.util.Enumeration getValuesEnum()
          Get an Enumeration of values.
 boolean has(java.lang.String pName)
          True if name exists.
 void inheritFrom(PropertySet pPropertySet)
          Inherit name-value pairs from a different PropertySet.
 java.lang.String insertValues(java.lang.String pText)
          Insert values by $ subsitution.
 boolean isDefined(java.lang.String pName)
          Return true if name has a non empty value.
 boolean isNo(java.lang.String pName)
          True if property has a no or false value.
 boolean isYes(java.lang.String pName)
          True if property has an yes or true value.
 void load(java.io.File pFile)
          Parse file into name-value pairs.
 void load(java.lang.String pFilePath)
          Parse file into name-value pairs.
 void overrideWith(PropertySet pPropertySet)
          Override name-value pairs with name-value pairs from a different PropertySet.
 void parse(java.lang.String pText)
          Parse Text into name-value pairs.
 void replaceAll(java.lang.String pFrom, java.lang.String pTo)
          Make a global replacement accross all properties.
 void save(java.io.File pFile)
          Save property set to disk.
 void save(java.lang.String pFilePath)
          Save property set to disk.
 void set(java.lang.Object pName, java.lang.Object pValue)
          Set name-value pair.
 void set(PropertySet pPropertySet)
          Set from a different PropertySet.
 void set(java.lang.String pName, boolean pValue)
          Set name-value pair.
 int size()
          Get number of names.
 java.lang.String toString()
          Return a String representation of data.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CN

public static final java.lang.String CN
See Also:
Constant Field Values

NO_SUBSTITUTIONS_SUFFIX

public static final java.lang.String NO_SUBSTITUTIONS_SUFFIX
See Also:
Constant Field Values

START_angle

public static final java.lang.String START_angle
See Also:
Constant Field Values

START_brace

public static final java.lang.String START_brace
See Also:
Constant Field Values

END_angle

public static final java.lang.String END_angle
See Also:
Constant Field Values

END_brace

public static final java.lang.String END_brace
See Also:
Constant Field Values

MOD_escape

public static final java.lang.String MOD_escape
See Also:
Constant Field Values

MOD_remove_backslash

public static final java.lang.String MOD_remove_backslash
See Also:
Constant Field Values

MOD_trim

public static final java.lang.String MOD_trim
See Also:
Constant Field Values
Constructor Detail

PropertySet

public PropertySet()
Create an empty PropertySet.


PropertySet

public PropertySet(java.io.File pFile)
Create a PropertySet from a file.

Parameters:
pFile - File containing properties.

PropertySet

public PropertySet(java.lang.String pFilePath)
Create a PropertySet from a file path.

Parameters:
pFilePath - path to file

PropertySet

public PropertySet(java.util.Hashtable pHashtable)
Create from a Hashtable.

Parameters:
pHashtable - property names and values

PropertySet

public PropertySet(java.util.Map pMap)
Create from a Map.

Parameters:
pMap - property names and values

PropertySet

public PropertySet(java.lang.Object[] pNameValuePairs)
Create from an Object[].

Parameters:
pNameValuePairs - property names and values

PropertySet

public PropertySet(PropertySet pPropertySet)
Create from a PropertySet.

Parameters:
pPropertySet - property names and values
Method Detail

get

public java.lang.String get(java.lang.String pName)
Get a value by name, return empty String if undefined. Subsitutions are performed: ${name} and $ are replaced with the corresponding property value. Use getSourceValue(java.lang.String) to get the value without substitutions.

Parameters:
pName - name of value

get

public java.lang.String get(java.lang.String pName,
                            java.lang.String pDefault)
Get a value by name, return default if not defined.

Parameters:
pName - name of value
pDefault - default value

getList

public java.lang.String[] getList(java.lang.String pName,
                                  java.lang.String pSeparationChars)
Get a list of values. Return empty array for unknown names. The list of values is formed by splitting the normal value.

Parameters:
pName - name of value list
pSeparationChars - list of chars on which to split

getSourceValue

public java.lang.String getSourceValue(java.lang.String pName)
Get property value without performing substitutions.

Parameters:
pName - name of value

has

public boolean has(java.lang.String pName)
True if name exists.

Parameters:
pName - Name to test.

getNames

public java.lang.String[] getNames()
Get a String array of names.


getValues

public java.lang.String[] getValues()
Get a String array of values.


getNamesEnum

public java.util.Enumeration getNamesEnum()
Get an Enumeration of names.


getNamesList

public java.util.List getNamesList()
Get a List of names.


getValuesEnum

public java.util.Enumeration getValuesEnum()
Get an Enumeration of values.


isYes

public boolean isYes(java.lang.String pName)
True if property has an yes or true value.

Parameters:
pName - name to test

isNo

public boolean isNo(java.lang.String pName)
True if property has a no or false value.

Parameters:
pName - name to test

isDefined

public boolean isDefined(java.lang.String pName)
Return true if name has a non empty value.

Parameters:
pName - name to test

size

public int size()
Get number of names.


clone

public java.lang.Object clone()
Clone ProperySet.


toString

public java.lang.String toString()
Return a String representation of data. NOTE: this is NOT suitable for reparsing - use dump if the output is to be reparsed.


save

public void save(java.lang.String pFilePath)
Save property set to disk.

Parameters:
pFilePath - path to save properties to

save

public void save(java.io.File pFile)
Save property set to disk.

Parameters:
pFile - File to save properties to

equals

public boolean equals(java.lang.Object pObject)
True if specified Object is equal to this PropertySet.

Parameters:
pObject - Object to test

contains

public boolean contains(PropertySet pPropertySet)
True if specified PropertySet is contained in this PropertySet. That is, all names and values found in the parameter are also in self.

Parameters:
pPropertySet - PropertySet to test

set

public void set(java.lang.String pName,
                boolean pValue)
Set name-value pair.

Parameters:
pName - name
pValue - boolean value

set

public void set(java.lang.Object pName,
                java.lang.Object pValue)
Set name-value pair. Convert null to empty String.

Parameters:
pName - name
pValue - value

set

public void set(PropertySet pPropertySet)
Set from a different PropertySet.

Parameters:
pPropertySet - names and values to copy

replaceAll

public void replaceAll(java.lang.String pFrom,
                       java.lang.String pTo)
Make a global replacement accross all properties. Use source value.


copy

public void copy(java.lang.String pFromName,
                 java.lang.String pToName)
Copy a value from one name to another.

Parameters:
pFromName - name to take value from
pToName - name to set value of

clear

public void clear()
Clear all name-value pairs.


parse

public void parse(java.lang.String pText)
           throws PropertySetException
Parse Text into name-value pairs.

Parameters:
pText - text to parse
Throws:
PropertySetException

load

public void load(java.lang.String pFilePath)
Parse file into name-value pairs.

Parameters:
pFilePath - path of file to parse

load

public void load(java.io.File pFile)
Parse file into name-value pairs.

Parameters:
pFile - File to parse.

overrideWith

public void overrideWith(PropertySet pPropertySet)
Override name-value pairs with name-value pairs from a different PropertySet. This results in a property set with the union of the names in both PropertySets, with values from the overiding set replacing values from this one where matching names occur.

Parameters:
pPropertySet - PropertySet to override this one

inheritFrom

public void inheritFrom(PropertySet pPropertySet)
Inherit name-value pairs from a different PropertySet. This results in a property set with the union of the names in both PropertySets, with values from this one replacing values from the other where matching names occur.

Parameters:
pPropertySet - PropertySet to inherit this one.

insertValues

public java.lang.String insertValues(java.lang.String pText)
Insert values by $ subsitution.

Parameters:
pText - String to perform subsitutions on


Copyright © 2000-2002 Richard Rodger