org.openbp.common.string
Class Object2StringConverter

java.lang.Object
  extended by org.openbp.common.string.Object2StringConverter

public class Object2StringConverter
extends java.lang.Object

Converter which converts arbitray object sets (usually things like integer enumerations) to string values and vice versa. Usually used for serialization/deserialization of integer values to more meaningful strings.

Author:
Heiko Erhardt

Constructor Summary
Object2StringConverter()
          Default constructor.
 
Method Summary
 void addIntValue(int value, java.lang.String name, java.lang.String displayName)
          Adds an integer value to the converter.
 void addValue(java.lang.Object value, java.lang.String name, java.lang.String displayName)
          Adds a value to the converter.
 boolean checkIntValue(int value)
          Checks if the supplied value is valid.
 boolean checkValue(java.lang.Object value)
          Checks if the supplied value is valid.
 java.lang.Object getDefaultValue()
          Gets the default value.
 java.util.Iterator getDisplayNames()
          Get the display names.
 java.util.Iterator getStrings()
          Gets the string.
 java.util.Iterator getValues()
          Gets the values.
 java.lang.String intValue2Str(int value)
          Converts an integer value to its corresponding string value.
 void setDefaultValue(java.lang.Object defaultValue)
          Sets the default value.
 int str2IntValue(java.lang.String str)
          Converts a string value to its corresponding integer value.
 java.lang.Object str2Value(java.lang.String str)
          Converts a string to its corresponding value.
 java.lang.String value2Str(java.lang.Object value)
          Converts an integer value to its corresponding string value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Object2StringConverter

public Object2StringConverter()
Default constructor.

Method Detail

addValue

public void addValue(java.lang.Object value,
                     java.lang.String name,
                     java.lang.String displayName)
Adds a value to the converter.

Parameters:
value - Value to add
name - Corresponding string value
displayName - Display name

str2Value

public java.lang.Object str2Value(java.lang.String str)
Converts a string to its corresponding value.

Parameters:
str - String to convert
Returns:
The corresponding value or the default value if the string is null or if it cannot be found in the mapping table.

value2Str

public java.lang.String value2Str(java.lang.Object value)
Converts an integer value to its corresponding string value.

Parameters:
value - Value to convert
Returns:
The corresponding string value or null if the value equals the default value or if it cannot be found in the mapping table.

checkValue

public boolean checkValue(java.lang.Object value)
Checks if the supplied value is valid.

Parameters:
value - Value to check
Returns:
true The value is either null or a valid value.
false The value is unknown

getValues

public java.util.Iterator getValues()
Gets the values.

Returns:
An iterator of objects. The objects are returned in the order they have been added.

getStrings

public java.util.Iterator getStrings()
Gets the string.

Returns:
An iterator of String objects. The objects are returned in the order they have been added.

getDisplayNames

public java.util.Iterator getDisplayNames()
Get the display names.

Returns:
An iterator of String objects. The objects are returned in the order they have been added.

getDefaultValue

public java.lang.Object getDefaultValue()
Gets the default value.


setDefaultValue

public void setDefaultValue(java.lang.Object defaultValue)
Sets the default value.


addIntValue

public void addIntValue(int value,
                        java.lang.String name,
                        java.lang.String displayName)
Adds an integer value to the converter.

Parameters:
value - Value to add
name - Corresponding string value
displayName - Display name

str2IntValue

public int str2IntValue(java.lang.String str)
Converts a string value to its corresponding integer value.

Parameters:
str - String value to convert
Returns:
The corresponding integer value or the default value if the string is null or if it cannot be found in the mapping table.

intValue2Str

public java.lang.String intValue2Str(int value)
Converts an integer value to its corresponding string value.

Parameters:
value - Value to convert
Returns:
The corresponding string value or null if the value equals the default value or if it cannot be found in the mapping table.

checkIntValue

public boolean checkIntValue(int value)
Checks if the supplied value is valid.

Parameters:
value - Value to check
Returns:
true The value is either null or a valid value.
false The value is unknown


Copyright © 2011. All Rights Reserved.