de.unidu.is.util
Class PropertyMap

java.lang.Object
  extended byde.unidu.is.util.PropertyMap
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
DBKeyPropertyMap, DBPropertyMap, DelegatedPropertyMap

public abstract class PropertyMap
extends java.lang.Object
implements java.util.Map

A map which provides convenient setXYZ() and getXYZ() methods for setting and returning values of type XYZ, given String keys. In addition, ${foo.bar} is replaced by the value of the property foo.bar when a value is returned in one of the getXYZ() methods.

The map can be configured so that it can hold multiple values for a key. The methods inhereted from java.util.Map then operate on the first stored value, unless otherwise noted.

Since:
2003-06-20
Version:
$Revision: 1.13 $, $Date: 2005/03/14 17:33:13 $
Author:
Henrik Nottelmann

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
protected  boolean multipleValues
          A flag specifying if multiple values can be hold for a key.
 
Constructor Summary
PropertyMap()
          Creates a new instance with only one value per key.
PropertyMap(boolean multipleValues)
          Creates a new instance.
 
Method Summary
 void addDouble(double d)
          Adds the specified number to each value (considered as a double).
 void addDouble(java.lang.Object key, double d)
          Adds the specified number to the value (as a double) for the specified key.
 void addDouble(PropertyMap map)
          Adds each value (as a double) in the specified map to the corresponding value in this map, for each key occurring in the specified map.
 void addInt(int i)
          Adds the specified number to each value (considered as an integer).
 void addInt(java.lang.Object key, int i)
          Adds the specified number to the value (as an integer) for the specified key.
 void addInt(PropertyMap map)
          Adds each value (as an integer) in the specified map to the corresponding value in this map, for each key occurring in the specified map.
 void apply(Function func)
          Applies the specified function on every value (considered as a double), and replaces the original value.
 java.lang.String convertString(java.lang.Object value, PropertyMap map)
          Returns the specified String value, using another map from where values can be taken while converting.
 void divDouble(double d)
          Divides each value (considered as a double) by the specified number.
 void divDouble(java.lang.Object key, double d)
          Divides the value (considered as a double) for the specified key by the specified number.
 void divDouble(PropertyMap map)
          Divides each value (as a double) by the corresponding value in the specified map, for each key occurring in the specified map.
 void divInt(int i)
          Divides each value (considered as an integer) by the specified number.
 void divInt(java.lang.Object key, int i)
          Divides the value (considered as an integer) for the specified key by the specified number.
 void divInt(PropertyMap map)
          Divides each value (as an integer) by the corresponding value in the specified map, for each key occurring in the specified map.
abstract  java.util.List getAll(java.lang.Object key)
          Returns a list with all values stored for the specified key.
 boolean getBoolean(java.lang.Object key)
          Returns the boolean value of the specified key.
 double getDouble(java.lang.Object key)
          Returns the double value of the specified key.
 int getInt(java.lang.Object key)
          Returns the int value of the specified key.
 double getLength()
          Returns the sum of all values in this property map, considered as double values.
 long getLong(java.lang.Object key)
          Returns the long value of the specified key.
 double getMaxDouble()
          Returns the maximum double value in this property map.
 java.lang.Object getMaxKey()
          Returns the key with the maximum double value.
 double getMinDouble()
          Returns the minimum double value in this property map.
 java.lang.String getString(java.lang.Object key)
          Returns the String value of the specified key.
 java.lang.String getString(java.lang.Object key, PropertyMap map)
          Returns the String value of the specified key, using another map from where values can be taken while converting.
 double getSum()
          Returns the sum of all values in this property map, considered as double values.
 boolean hasMultipleValues()
          Deprecated. Use isMultipleValues() instead
 void inc(java.lang.Object key)
          Increments the value (considered as an integer) corresponding to the specified key by one.
 void initDouble(java.util.Collection keys, double init)
          Inits the property map by setting the value of every key in the specified collection to the specified initial double value.
 boolean isMultipleValues()
          Tests if multiple values for the same key are allowed.
 void multDouble(double d)
          Multiplies the specified number with each value (considered as a double).
 void multDouble(java.lang.Object key, double d)
          Multiplies the specified number with the value (as a double) for the specified key.
 void multDouble(PropertyMap map)
          Multiplies each value (as a double) in the specified map with the corresponding value in this map, for each key occurring in the specified map.
 void multDouble(PropertyMap map, boolean b)
          Multiplies each value (as a double) in the specified map with the corresponding value in this map, for each key occurring in the specified map.
 void multInt(int i)
          Multiplies the specified number with each value (considered as an integer).
 void multInt(java.lang.Object key, int i)
          Multiplies the specified number with the value (as an integer) for the specified key.
 void multInt(PropertyMap map)
          Multiplies each value (as an integer) in the specified map with the corresponding value in this map, for each key occurring in the specified map.
 void normalizeLength()
          Normalises the length of this property map, i.e. that afterwards the sum of all values in this property map is one.
abstract  void remove(java.lang.Object key, java.lang.Object value)
          Removes the specified value for the specified key.
 void removeCloseToZero()
          Removes all entries where the value is close to zero (considered as a double).
 void removeZero()
          Remove all entries where the value equals zero (considered as a double).
 void set(java.lang.Object key, java.lang.String value)
          Sets the string value of the specified key.
 void setBoolean(java.lang.Object key, boolean value)
          Sets the boolean value of the specified key.
 void setDouble(java.lang.Object key, double value)
          Sets the double value of the specified key.
 void setInt(java.lang.Object key, int value)
          Sets the int value of the specified key.
 void setLong(java.lang.Object key, long value)
          Sets the long value of the specified key.
 void setMultipleValues(boolean multipleValues)
          Sets whether multiple values for the same key are allowed.
 void setString(java.lang.Object key, java.lang.String value)
          Sets the String value of the specified key.
 void subDouble(double d)
          Subtracts the specified number from each value (considered as a double).
 void subDouble(java.lang.Object key, double d)
          Subtracts the specified number from the value (as a double) for the specified key.
 void subDouble(PropertyMap map)
          Subtracts each value (as a double) in the specified map from the corresponding value in this map, for each key occurring in the specified map.
 void subInt(int i)
          Subtracts the specified number from each value (considered as an integer).
 void subInt(java.lang.Object key, int i)
          Subtracts the specified number from the value (as an integer) for the specified key.
 void subInt(PropertyMap map)
          Subtracts each value (as an integer) in the specified map from the corresponding value in this map, for each key occurring in the specified map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Field Detail

multipleValues

protected boolean multipleValues
A flag specifying if multiple values can be hold for a key.

Constructor Detail

PropertyMap

public PropertyMap()
Creates a new instance with only one value per key.


PropertyMap

public PropertyMap(boolean multipleValues)
Creates a new instance.

Parameters:
multipleValues - values if true, multiple values can be hold for a key
Method Detail

isMultipleValues

public boolean isMultipleValues()
Tests if multiple values for the same key are allowed.

Returns:
returns true iff multiple values for the same key are allowed

setMultipleValues

public void setMultipleValues(boolean multipleValues)
Sets whether multiple values for the same key are allowed.

Parameters:
multipleValues - if true, multiple values for the same key are allowed

hasMultipleValues

public boolean hasMultipleValues()
Deprecated. Use isMultipleValues() instead

Tests if multiple values for the same key are allowed.

Returns:
returns true iff multiple values for the same key are allowed

set

public void set(java.lang.Object key,
                java.lang.String value)
Sets the string value of the specified key.

Parameters:
key - property key
value - string value of the specified key

getAll

public abstract java.util.List getAll(java.lang.Object key)
Returns a list with all values stored for the specified key.

Parameters:
key - property key
Returns:
list with all values stored for the specified key

remove

public abstract void remove(java.lang.Object key,
                            java.lang.Object value)
Removes the specified value for the specified key.

Parameters:
key - property key
value - value to be removed

getString

public java.lang.String getString(java.lang.Object key)
Returns the String value of the specified key.

Parameters:
key - property key
Returns:
String value of the specified key

getString

public java.lang.String getString(java.lang.Object key,
                                  PropertyMap map)
Returns the String value of the specified key, using another map from where values can be taken while converting.

Parameters:
key - property key
map - another map from where values can be taken while converting
Returns:
String value of the specified key

convertString

public java.lang.String convertString(java.lang.Object value,
                                      PropertyMap map)
Returns the specified String value, using another map from where values can be taken while converting.

Parameters:
value - value
map - another map from where values can be taken while converting
Returns:
converted String value

setString

public void setString(java.lang.Object key,
                      java.lang.String value)
Sets the String value of the specified key.

Parameters:
key - property key
value - String value of the specified key

getLong

public long getLong(java.lang.Object key)
Returns the long value of the specified key.

Parameters:
key - property key
Returns:
long value of the specified key

setLong

public void setLong(java.lang.Object key,
                    long value)
Sets the long value of the specified key.

Parameters:
key - property key
value - long value of the specified key

getInt

public int getInt(java.lang.Object key)
Returns the int value of the specified key.

Parameters:
key - property key
Returns:
int value of the specified key

setInt

public void setInt(java.lang.Object key,
                   int value)
Sets the int value of the specified key.

Parameters:
key - property key
value - int value of the specified key

getDouble

public double getDouble(java.lang.Object key)
Returns the double value of the specified key.

Parameters:
key - property key
Returns:
double value of the specified key

setDouble

public void setDouble(java.lang.Object key,
                      double value)
Sets the double value of the specified key.

Parameters:
key - property key
value - double value of the specified key

getBoolean

public boolean getBoolean(java.lang.Object key)
Returns the boolean value of the specified key.

Parameters:
key - property key
Returns:
int value of the specified key

setBoolean

public void setBoolean(java.lang.Object key,
                       boolean value)
Sets the boolean value of the specified key.

Parameters:
key - property key
value - boolean value of the specified key

getMaxKey

public java.lang.Object getMaxKey()
Returns the key with the maximum double value.

Returns:
key with the maximum double value

getSum

public double getSum()
Returns the sum of all values in this property map, considered as double values.

Returns:
sum of all values

getLength

public double getLength()
Returns the sum of all values in this property map, considered as double values.

Returns:
sum of all values

normalizeLength

public void normalizeLength()
Normalises the length of this property map, i.e. that afterwards the sum of all values in this property map is one.


removeCloseToZero

public void removeCloseToZero()
Removes all entries where the value is close to zero (considered as a double).


removeZero

public void removeZero()
Remove all entries where the value equals zero (considered as a double).


apply

public void apply(Function func)
Applies the specified function on every value (considered as a double), and replaces the original value.

Parameters:
func - function to be applied

getMaxDouble

public double getMaxDouble()
Returns the maximum double value in this property map.

Returns:
maximum double value in this property map

getMinDouble

public double getMinDouble()
Returns the minimum double value in this property map.

Returns:
minimum double value in this property map

initDouble

public void initDouble(java.util.Collection keys,
                       double init)
Inits the property map by setting the value of every key in the specified collection to the specified initial double value.

Parameters:
keys - keys for initialisation
init - initial double value

divInt

public void divInt(int i)
Divides each value (considered as an integer) by the specified number.

Parameters:
i - number

subInt

public void subInt(int i)
Subtracts the specified number from each value (considered as an integer).

Parameters:
i - number

multInt

public void multInt(int i)
Multiplies the specified number with each value (considered as an integer).

Parameters:
i - number

addInt

public void addInt(int i)
Adds the specified number to each value (considered as an integer).

Parameters:
i - number

divDouble

public void divDouble(double d)
Divides each value (considered as a double) by the specified number.

Parameters:
d - number

subDouble

public void subDouble(double d)
Subtracts the specified number from each value (considered as a double).

Parameters:
d - number

multDouble

public void multDouble(double d)
Multiplies the specified number with each value (considered as a double).

Parameters:
d - number

addDouble

public void addDouble(double d)
Adds the specified number to each value (considered as a double).

Parameters:
d - number

divInt

public void divInt(PropertyMap map)
Divides each value (as an integer) by the corresponding value in the specified map, for each key occurring in the specified map.

Parameters:
map - property map as operand

subInt

public void subInt(PropertyMap map)
Subtracts each value (as an integer) in the specified map from the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

multInt

public void multInt(PropertyMap map)
Multiplies each value (as an integer) in the specified map with the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

addInt

public void addInt(PropertyMap map)
Adds each value (as an integer) in the specified map to the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

divDouble

public void divDouble(PropertyMap map)
Divides each value (as a double) by the corresponding value in the specified map, for each key occurring in the specified map.

Parameters:
map - property map as operand

subDouble

public void subDouble(PropertyMap map)
Subtracts each value (as a double) in the specified map from the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

multDouble

public void multDouble(PropertyMap map)
Multiplies each value (as a double) in the specified map with the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

multDouble

public void multDouble(PropertyMap map,
                       boolean b)
Multiplies each value (as a double) in the specified map with the corresponding value in this map, for each key occurring in the specified map. If the boolean specified value is set to true, sets the value to one if no entries exists so far.

Parameters:
map - property map as operand Multiplies every value (considered as a double) with the specified
b - if true, sets the value to one if no entries exists so far

addDouble

public void addDouble(PropertyMap map)
Adds each value (as a double) in the specified map to the corresponding value in this map, for each key occurring in the specified map.

Parameters:
map - property map as operand

inc

public void inc(java.lang.Object key)
Increments the value (considered as an integer) corresponding to the specified key by one.

Parameters:
key - key

divInt

public void divInt(java.lang.Object key,
                   int i)
Divides the value (considered as an integer) for the specified key by the specified number.

Parameters:
key - key
i - number

subInt

public void subInt(java.lang.Object key,
                   int i)
Subtracts the specified number from the value (as an integer) for the specified key.

Parameters:
key - key
i - number

multInt

public void multInt(java.lang.Object key,
                    int i)
Multiplies the specified number with the value (as an integer) for the specified key.

Parameters:
key - key
i - number

addInt

public void addInt(java.lang.Object key,
                   int i)
Adds the specified number to the value (as an integer) for the specified key.

Parameters:
key - key
i - number

divDouble

public void divDouble(java.lang.Object key,
                      double d)
Divides the value (considered as a double) for the specified key by the specified number.

Parameters:
key - key
d - number

subDouble

public void subDouble(java.lang.Object key,
                      double d)
Subtracts the specified number from the value (as a double) for the specified key.

Parameters:
key - key
d - number

multDouble

public void multDouble(java.lang.Object key,
                       double d)
Multiplies the specified number with the value (as a double) for the specified key.

Parameters:
key - key
d - number

addDouble

public void addDouble(java.lang.Object key,
                      double d)
Adds the specified number to the value (as a double) for the specified key.

Parameters:
key - key
d - number