com.topcoder.shared.problem
Class DataType

java.lang.Object
  |
  +--com.topcoder.shared.problem.BaseElement
        |
        +--com.topcoder.shared.problem.DataType
All Implemented Interfaces:
java.lang.Cloneable, com.topcoder.shared.netCommon.CustomSerializable, Element, java.io.Serializable

public class DataType
extends com.topcoder.shared.problem.BaseElement
implements Element

A DataType represents a data type in a language-independent manner. This class has all the semantics of an Element.

Author:
Logan Hanks
See Also:
Element, BaseElement, Serialized Form

Constructor Summary
DataType()
          This is the default constructor, available for serialization.
DataType(int id, java.lang.String description)
          A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.
DataType(int id, java.lang.String description, java.util.HashMap typeMapping)
          A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.
DataType(java.lang.String description)
          A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.
 
Method Summary
 void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
          Custom serialization
 void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
          Custom serialization
static java.lang.String encodeHTML(java.lang.String text)
          Utility function for encoding HTML entities in text.
 boolean equals(java.lang.Object o)
          Returns true if o is a DataType with the same description as this.
 java.lang.String getBaseName()
          The base name of a data type is the type of elements it ultimately contains (regardless of dimensionality).
 java.lang.String getDescription()
          Returns the description of the datatype
 java.lang.String getDescriptor(int id)
          The getDescriptor method generates a type descriptor for this data type that is appropriate for the given language.
 java.lang.String getDescriptor(Language language)
          The getDescriptor method generates a type descriptor for this data type that is appropriate for the given language.
 int getDimension()
          The dimensionality of a data type refers to how many dimensions the type has.
 int getID()
          Returns the unique identifier for the datatype
 ElementRenderer getRenderer()
          Returns this elements renderer.
 java.util.HashMap getTypeMapping()
          Get's the type mappings for the data type
 DataType reduceDimension()
          Constructs and returns a new type, similar to this type, but with its dimension reduced.
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 void setTypeMapping(java.util.HashMap typeMapping)
          Sets the type mapping for the data type
 java.lang.String toXML()
          Returns the datatype described in XML
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
getRenderer, setRenderer
 

Constructor Detail

DataType

public DataType()
This is the default constructor, available for serialization.


DataType

public DataType(java.lang.String description)
A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.

Parameters:
description - For example, "String[]" (pulled from data_type.data_type_desc)

DataType

public DataType(int id,
                java.lang.String description)
A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.

Parameters:
id - A unique integer identifier (pulled from data_type.data_type_id)
description - For example, "String[]" (pulled from data_type.data_type_desc)

DataType

public DataType(int id,
                java.lang.String description,
                java.util.HashMap typeMapping)
A DataType consists of a numeric id a description, and a mapping between language ids and language-specific descriptors.

Parameters:
id - A unique integer identifier (pulled from data_type.data_type_id)
description - For example, "String[]" (pulled from data_type.data_type_desc)
typeMapping - A HashMap containing all of the language->descriptor mappings that are defined for this data type. Each mapping is from Integer to String, and should be populated with information obtained from the data_type_mapping table.
Method Detail

setTypeMapping

public void setTypeMapping(java.util.HashMap typeMapping)
Sets the type mapping for the data type

Parameters:
typeMapping - A HashMap containing all of the language->descriptor mappings that are defined for this data type. Each mapping is from Integer to String, and should be populated with information obtained from the data_type_mapping table.

getTypeMapping

public java.util.HashMap getTypeMapping()
Get's the type mappings for the data type

Returns:
the type mappings for the data type

customWriteObject

public void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
                       throws java.io.IOException
Custom serialization

Specified by:
customWriteObject in interface Element
Parameters:
writer - the writer to write to.
Throws:
java.io.IOException - if an I/O error has occurred in the stream that backs the writer.

customReadObject

public void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
                      throws java.io.IOException,
                             java.io.ObjectStreamException
Custom serialization

Specified by:
customReadObject in interface Element
Parameters:
reader - the reader to read from.
Throws:
java.io.ObjectStreamException - if the information that is read is inconsistent (stream corrupted or incompatibility between writers and readers)
java.io.IOException - if an I/O error has occurred in the stream that backs the reader.

getDescription

public java.lang.String getDescription()
Returns the description of the datatype

Returns:
the description of the datatype

getDescriptor

public java.lang.String getDescriptor(Language language)
The getDescriptor method generates a type descriptor for this data type that is appropriate for the given language.

Parameters:
language - The language in which to present the type descriptor.
Returns:
A string reperesentation of the data type, presented in the given language. If the descriptor for the given language is undefined (in the database), this method returns null.
See Also:
Language

getDescriptor

public java.lang.String getDescriptor(int id)
The getDescriptor method generates a type descriptor for this data type that is appropriate for the given language.

Parameters:
id - The language identifier in which to present the type descriptor.
Returns:
A string reperesentation of the data type, presented in the given language. If the descriptor for the given language is undefined (in the database), this method returns null.
See Also:
Language

getBaseName

public java.lang.String getBaseName()
The base name of a data type is the type of elements it ultimately contains (regardless of dimensionality). E.g., the base name of String[][] is String.


getDimension

public int getDimension()
The dimensionality of a data type refers to how many dimensions the type has. Example: the dimensionality of String[][] is 2.

Returns:
the dimension.

reduceDimension

public DataType reduceDimension()
                         throws InvalidTypeException
Constructs and returns a new type, similar to this type, but with its dimension reduced.

Returns:
A new DataType with the same base type as this one, but with a dimension of one less.
Throws:
InvalidTypeException - if the dimension of this type is 0

toXML

public java.lang.String toXML()
Returns the datatype described in XML

Specified by:
toXML in interface Element
Returns:
the datatype described in XML

equals

public boolean equals(java.lang.Object o)
Returns true if o is a DataType with the same description as this.

Overrides:
equals in class java.lang.Object

getID

public int getID()
Returns the unique identifier for the datatype

Returns:
the unique identifier for the datatype

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.