com.topcoder.shared.problem
Class DataValue

java.lang.Object
  |
  +--com.topcoder.shared.problem.BaseElement
        |
        +--com.topcoder.shared.problem.DataValue
All Implemented Interfaces:
java.lang.Cloneable, com.topcoder.shared.netCommon.CustomSerializable, Element, java.io.Serializable
Direct Known Subclasses:
ArrayValue, CharacterValue, DecimalValue, IntegralValue, StringValue

public abstract class DataValue
extends com.topcoder.shared.problem.BaseElement
implements Element

A DataValue is a particular parameter or test value; the instance can be used to generate a human-readable encoding, an encoding for a particular programming language, or an actual Java object containing the represented value. In addition, this class supports the ability to parse the human-readable encoding into a new instance.

See Also:
Serialized Form

Constructor Summary
DataValue()
           
 
Method Summary
static java.lang.Object[] convertDataValuesToObjects(DataValue[] values, DataType[] types)
          Converts the given datavalues to an object given the corresponding datatype (ie a datatype of "int" would be converted to an java.lang.Integer).
static java.lang.Object convertDataValueToObject(DataValue value, DataType type)
          Converts the given datavalue to an object given the datatype (ie a datatype of "int" would be converted to an java.lang.Integer).
static DataValue[] convertObjectsToDataValues(java.lang.Object[] objs, DataType[] types)
          Converts the given objects to a DataValue given the corresponding datatypes (ie a object of "Integer" would be converted to an IntegralValue).
static DataValue convertObjectToDataValue(java.lang.Object obj, DataType type)
          Converts the given object to an DataValue given the corresponding datatype (ie a object of "Integer" would be converted to an IntegralValue).
abstract  java.lang.String encode()
          Encodes the given data value.
static java.lang.String encodeHTML(java.lang.String text)
          Utility function for encoding HTML entities in text.
 ElementRenderer getRenderer()
          Returns this elements renderer.
abstract  java.lang.Object getValue()
          Returns the value as an object.
abstract  void parse(DataValueReader reader, DataType type)
          Parses a data from a reader given the specific datatype.
static DataValue[] parseSequence(DataValueReader reader, DataType[] type)
          Parses data from a reader using the corresponding DataTypes into it's object representation (ie Integer, String, int[], etc).
static DataValue[] parseSequence(java.lang.String text, DataType[] type)
          Parses the text (which has multiple values embedded) using the corresponding DataType into it's object representation (ie Integer, String, int[], etc).
static DataValue parseValue(DataValueReader reader, DataType type)
          Parses data from a reader given the specific datatype.
static DataValue parseValue(java.lang.String text, DataType type)
          Parses data from the text given the specific datatype.
static DataValue[] parseValues(java.lang.String[] values, DataType[] types)
          Parses values from an array of strings given the corresponding array of types.
static java.lang.Object[] parseValuesToObjects(java.lang.String[] values, DataType[] types)
          Parses the specified array of values using the corresponding DataType into it's object.
static java.lang.Object parseValueToObject(java.lang.String text, DataType type)
          Parses the specified text using the specified DataType into it's object.
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 java.lang.String toXML()
          Returns the XML representation of the value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
customReadObject, customWriteObject, getRenderer, setRenderer
 

Constructor Detail

DataValue

public DataValue()
Method Detail

parse

public abstract void parse(DataValueReader reader,
                           DataType type)
                    throws java.io.IOException,
                           DataValueParseException
Parses a data from a reader given the specific datatype.

Parameters:
reader - the reader to read from.
type - the datatype used to parse with.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataValueReader, DataType

encode

public abstract java.lang.String encode()
Encodes the given data value.

Returns:
encoded data value.

getValue

public abstract java.lang.Object getValue()
Returns the value as an object.

Returns:
the value as an object.

toXML

public java.lang.String toXML()
Returns the XML representation of the value. Note: calls super.encodeHTML(encode()).

Specified by:
toXML in interface Element
Returns:
the XML representation of the value.

parseValue

public static DataValue parseValue(java.lang.String text,
                                   DataType type)
                            throws java.io.IOException,
                                   DataValueParseException
Parses data from the text given the specific datatype. Same result as calling "parseValue(new DataValueReader(text), type)".

Parameters:
text - the text of the raw data values.
type - the datatype used to parse with.
Returns:
the data value that was parsed.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

parseValue

public static DataValue parseValue(DataValueReader reader,
                                   DataType type)
                            throws java.io.IOException,
                                   DataValueParseException
Parses data from a reader given the specific datatype. Same result as calling "parseValue(new DataValueReader(text), type)".

Parameters:
type - the datatype used to parse with.
Returns:
the data value that was parsed.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType, DataValueReader

parseValues

public static DataValue[] parseValues(java.lang.String[] values,
                                      DataType[] types)
                               throws java.io.IOException,
                                      DataValueParseException
Parses values from an array of strings given the corresponding array of types.

Parameters:
values - the values to parse.
types - the types corresponding to the values.
Returns:
the datavalues that were parsed.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

parseValueToObject

public static java.lang.Object parseValueToObject(java.lang.String text,
                                                  DataType type)
                                           throws java.io.IOException,
                                                  DataValueParseException
Parses the specified text using the specified DataType into it's object. representation (ie Integer, String, int[], etc).

Parameters:
text - the text of the value.
type - the datatype used to parse the text.
Returns:
the object representation of the text.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

parseValuesToObjects

public static java.lang.Object[] parseValuesToObjects(java.lang.String[] values,
                                                      DataType[] types)
                                               throws java.io.IOException,
                                                      DataValueParseException
Parses the specified array of values using the corresponding DataType into it's object. representation (ie Integer, String, int[], etc).

Parameters:
values - the values.
types - the corresponding datatype used to parse the value.
Returns:
the object array representation of the values.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

parseSequence

public static DataValue[] parseSequence(java.lang.String text,
                                        DataType[] type)
                                 throws java.io.IOException,
                                        DataValueParseException
Parses the text (which has multiple values embedded) using the corresponding DataType into it's object representation (ie Integer, String, int[], etc). Same result as calling "parseSequence(new DataValueReader(text), type)".

Parameters:
text - the text containing multiple values.
Returns:
the object array representation of the values.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

parseSequence

public static DataValue[] parseSequence(DataValueReader reader,
                                        DataType[] type)
                                 throws java.io.IOException,
                                        DataValueParseException
Parses data from a reader using the corresponding DataTypes into it's object representation (ie Integer, String, int[], etc). Same result as calling "parseSequence(new DataValueReader(text), type)".

Parameters:
reader - the reader of the data.
Returns:
the object array representation of the values.
Throws:
java.io.IOException - if an exception occurred during reading.
DataValueParseException - if a parsing exception occurs.
See Also:
DataType

convertDataValueToObject

public static java.lang.Object convertDataValueToObject(DataValue value,
                                                        DataType type)
                                                 throws DataValueParseException
Converts the given datavalue to an object given the datatype (ie a datatype of "int" would be converted to an java.lang.Integer).

Parameters:
value - the value of the data.
type - the type fo the data.
Returns:
an object corresponding to the value/type (note: could be an array like "int[]" or "String[]".
Throws:
DataValueParseException - if a parsing exception occurs.
See Also:
DataType, DataValue

convertDataValuesToObjects

public static java.lang.Object[] convertDataValuesToObjects(DataValue[] values,
                                                            DataType[] types)
                                                     throws DataValueParseException
Converts the given datavalues to an object given the corresponding datatype (ie a datatype of "int" would be converted to an java.lang.Integer).

Parameters:
values - the values.
Returns:
an object array corresponding to the value/type.
Throws:
DataValueParseException - if a parsing exception occurs.
See Also:
DataType, DataValue

convertObjectToDataValue

public static DataValue convertObjectToDataValue(java.lang.Object obj,
                                                 DataType type)
                                          throws DataValueParseException
Converts the given object to an DataValue given the corresponding datatype (ie a object of "Integer" would be converted to an IntegralValue).

Parameters:
obj - the object to convert.
type - the datatype of the object.
Returns:
a datavalue for the object/type.
Throws:
DataValueParseException - if a parsing exception occurs.
See Also:
DataType, DataValue

convertObjectsToDataValues

public static DataValue[] convertObjectsToDataValues(java.lang.Object[] objs,
                                                     DataType[] types)
                                              throws DataValueParseException
Converts the given objects to a DataValue given the corresponding datatypes (ie a object of "Integer" would be converted to an IntegralValue).

Returns:
a datavalue for the object/type.
Throws:
DataValueParseException - if a parsing exception occurs.
See Also:
DataType, DataValue

setRenderer

public void setRenderer(ElementRenderer renderer)
Sets the renderer for this element.

Specified by:
setRenderer in interface Element
Parameters:
renderer - the element renderer.
See Also:
ElementRenderer

getRenderer

public ElementRenderer getRenderer()
Returns this elements renderer.

Specified by:
getRenderer in interface Element
Returns:
this elements renderer.
See Also:
ElementRenderer

encodeHTML

public static java.lang.String encodeHTML(java.lang.String text)
Utility function for encoding HTML entities in text. All occurrences of the <, >, and & characters are converted to &lt;, &gt;, and &amp;, respectively.

Parameters:
text - the text to encode.
Returns:
the encoded text.