info.aduna.gee.publication.util
Class WProperties

java.lang.Object
  extended by java.util.Dictionary<K,V>
      extended by java.util.Hashtable
          extended by info.aduna.gee.publication.util.WProperties
All Implemented Interfaces:
Serializable, Cloneable, Map
Direct Known Subclasses:
SzState

public class WProperties
extends Hashtable

WProperties is the ZPad equivalent of java.util.Properties.

 It differs from java.util.Properties in:
                        - SPEED
                                        -- WProperties in optimized especially in "load".
                        - MEMORY
                                        -- Key and Value strings are shared.
                        - STORAGE
                                        -- WProperties does not generate comment or dates.
                        - DEFAULTS AND EMPTY VALUES
                                        -- A getProperty returns the value or "".
                                        -- So a "" value can not be destinguished from non-presence of the key.
                                                -- But note: you still have to store key="" pairs in order
                                                                         support the correct containsKey() !


 We don't support line continuation.
 We do support blanks in keys, except for \n or \r.
 We do support \r as line separator, besides the default \n. This is manual editing in Windows only.

 

See Also:
Serialized Form

Constructor Summary
WProperties()
          Creates an empty property list.
WProperties(byte[] in)
          Constructs a property list and loads the byte array.
WProperties(Properties p)
          Convert a Properties to a WProperties.
WProperties(String s)
          Constructs a property list and loads s.
 
Method Summary
protected  int _getExpandedSize(char[] anArray)
           
 boolean equals(Object other)
          Two WProperties are equal * if their number of keys are equal * every key in "this" is also key in "that" * if for every key, the corresponding values are equal.
 int getIntProperty(String key)
          Gets a int-property with the specified key.
 String getKeyOf(String value)
          In a lot of circumstances the WProperties is a one-to-one mapping of key and value.
 WProperties getProperties(int key)
          Gets a WProperties with the specified key.
 WProperties getProperties(String key)
          Gets a WProperties with the specified key.
 String getProperty(int key)
          Gets a property with the specified key.
 String getProperty(String key)
          Gets a property with the specified key.
 void load(InputStream in)
          Loads properties from an InputStream.
 WProperties mergeWith(WProperties other)
          (Re)set all key-value pairs in this WProperties that are defined in the other WProperties.
 Object put(int key, Object value)
          A lot of ZPad WProperties are used to store N.
 Object put(String key, int value)
          A lot of ZPad WProperties are used to store "int" values.
 Object put(String key, String value)
          Share all Key and Value strings.
 void save(OutputStream out)
          Save properties to an OutputStream.
 void save(OutputStream prnt, boolean localize, int level)
          Save properties at a certain level to a PrintStream.
 Properties toProperties()
          Convert a WProperties to a Properties.
 String toString()
           
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WProperties

public WProperties()
Creates an empty property list.


WProperties

public WProperties(Properties p)
Convert a Properties to a WProperties.

Parameters:
p - null or a Properties containing the initial key/value pairs

WProperties

public WProperties(String s)
Constructs a property list and loads s.


WProperties

public WProperties(byte[] in)
Constructs a property list and loads the byte array.

Method Detail

toProperties

public Properties toProperties()
Convert a WProperties to a Properties.


load

public void load(InputStream in)
          throws IOException
Loads properties from an InputStream.

Parameters:
in - the input stream
Throws:
IOException - Error when reading from input stream.

save

public void save(OutputStream out)
          throws IOException
Save properties to an OutputStream.

Throws:
IOException

save

public void save(OutputStream prnt,
                 boolean localize,
                 int level)
          throws IOException
Save properties at a certain level to a PrintStream.

Parameters:
prnt - the OutputStream to save to
localize - if true, localization by the PrintStream is automatic
level - the nesting level of Properties
Throws:
IOException

put

public Object put(int key,
                  Object value)
A lot of ZPad WProperties are used to store N. objects. The keys used for those objects are simply 0, 1, 2, ... N - 1. The original Hashtable's put has two Objects as parameters. This one an "int" (basic type) and an Object.

Parameters:
key - the hashtable key.
value - the value.

put

public Object put(String key,
                  int value)
A lot of ZPad WProperties are used to store "int" values.

Parameters:
key - the hashtable key.
value - the value.

put

public Object put(String key,
                  String value)
Share all Key and Value strings.


getProperty

public String getProperty(String key)
Gets a property with the specified key. NOTE: this function is different from Properties' getProperty in that it NEVER returns null. Use "containsKey" to check for the presence of a key if required.

Parameters:
key - the key to look for
Returns:
the property with the specified key or "".

getProperty

public String getProperty(int key)
Gets a property with the specified key. The key is stored as an integer string an can be asked for as an integer.

Parameters:
key - the key to look for.
the - property stored under 'key', "" if not found.

getIntProperty

public int getIntProperty(String key)
Gets a int-property with the specified key. Use "containsKey" to check for the presence of a key if required.

Parameters:
key - the key to look for
Returns:
the int value of the property with the specified key or 0 if not present or not a legal int.

getProperties

public WProperties getProperties(String key)
Gets a WProperties with the specified key.


getProperties

public WProperties getProperties(int key)
Gets a WProperties with the specified key.


getKeyOf

public String getKeyOf(String value)
In a lot of circumstances the WProperties is a one-to-one mapping of key and value.

Returns:
the first key (or null) of which this is the value.

mergeWith

public WProperties mergeWith(WProperties other)
(Re)set all key-value pairs in this WProperties that are defined in the other WProperties.

Parameters:
other - contains the key-value pairs to be set or is null
Returns:
this

equals

public boolean equals(Object other)
Two WProperties are equal * if their number of keys are equal * every key in "this" is also key in "that" * if for every key, the corresponding values are equal.

Specified by:
equals in interface Map
Overrides:
equals in class Hashtable

toString

public String toString()
Overrides:
toString in class Hashtable
Returns:
A String that represents this.

_getExpandedSize

protected int _getExpandedSize(char[] anArray)


Copyright © 1997-2008 Aduna. All Rights Reserved.