org.dartra.standard
Class StringProperties

java.lang.Object
  extended byorg.dartra.standard.StringProperties

public class StringProperties
extends java.lang.Object

Simple class to hold properties (name-value) pairs. This class can parse name-value strings and returns the contained properties as a name-value pair string using the toString() method.

This class is used by game implementation classes to put their specific properties in a string representation. This representation can be saved to a persistent store. Since it is a string it allows for queries that take these specialized properties into account (e.g. give me all x01-games with as start score 301).

Author:
Erwin Vervaet

Constructor Summary
StringProperties()
          Create an empty collection of string name-value properties.
StringProperties(java.lang.String properties)
          Create a collection of name-value properties based on the properties present in given string.
 
Method Summary
 boolean getBooleanProperty(java.lang.String name)
          Returns the value of named property as a boolean.
 int[] getIntArrayProperty(java.lang.String name)
          Returns the value of named comma separated property as an int[].
 int getIntProperty(java.lang.String name)
          Returns the value of named property as an int.
 java.lang.String getProperty(java.lang.String name)
          Returns the value of named property, or null if the property is not known.
 java.util.Enumeration getPropertyNames()
          Get an iterator listing the known property names.
 java.lang.String[] getStringArrayProperty(java.lang.String name)
          Returns the value of named comma separated property as an String[].
 void setAllProperties(StringProperties props)
          Add all properties of given properties collection to this collection;
 void setProperty(java.lang.String name, boolean value)
          Set named property to given value.
 void setProperty(java.lang.String name, int value)
          Set named property to given value.
 void setProperty(java.lang.String name, int[] values)
          Set named property to given value.
 void setProperty(java.lang.String name, java.lang.String value)
          Set named property to given value.
 void setProperty(java.lang.String name, java.lang.String[] values)
          Set named property to given value.
 int size()
          Returns the number of known properties.
 java.lang.String toString()
          Returns a string representation of the properties contained by this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StringProperties

public StringProperties()

Create an empty collection of string name-value properties.


StringProperties

public StringProperties(java.lang.String properties)

Create a collection of name-value properties based on the properties present in given string.

Parameters:
properties - The properties string, of format (name=value' ')*, for instance "a=b c=d".
Method Detail

setProperty

public void setProperty(java.lang.String name,
                        java.lang.String value)

Set named property to given value. If a property with given name already exists, the previous value is replaced.


setProperty

public void setProperty(java.lang.String name,
                        boolean value)

Set named property to given value. If a property with given name already exists, the previous value is replaced.


setProperty

public void setProperty(java.lang.String name,
                        int value)

Set named property to given value. If a property with given name already exists, the previous value is replaced.


setProperty

public void setProperty(java.lang.String name,
                        int[] values)

Set named property to given value. If a property with given name already exists, the previous value is replaced.


setProperty

public void setProperty(java.lang.String name,
                        java.lang.String[] values)

Set named property to given value. If a property with given name already exists, the previous value is replaced.


getProperty

public java.lang.String getProperty(java.lang.String name)

Returns the value of named property, or null if the property is not known.


getBooleanProperty

public boolean getBooleanProperty(java.lang.String name)

Returns the value of named property as a boolean.


getIntProperty

public int getIntProperty(java.lang.String name)

Returns the value of named property as an int.


getIntArrayProperty

public int[] getIntArrayProperty(java.lang.String name)

Returns the value of named comma separated property as an int[].


getStringArrayProperty

public java.lang.String[] getStringArrayProperty(java.lang.String name)

Returns the value of named comma separated property as an String[].


getPropertyNames

public java.util.Enumeration getPropertyNames()

Get an iterator listing the known property names.


size

public int size()

Returns the number of known properties.


setAllProperties

public void setAllProperties(StringProperties props)

Add all properties of given properties collection to this collection;


toString

public java.lang.String toString()

Returns a string representation of the properties contained by this object. This string can be parsed by the contructor.