com.topcoder.shared.problem
Class ProblemComponent

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

public class ProblemComponent
extends com.topcoder.shared.problem.BaseElement
implements Element, java.io.Serializable, java.lang.Cloneable, com.topcoder.shared.netCommon.CustomSerializable

This class fully represents a problem statement. This consists of the following elements:

Instances of this class are serializable and are suitable for client-side use. Instances of this class should generally be constructed by a ProblemComponentFactory. This class also provides a method to convert to its language-independent XML representation. The class also provides methods for obtaining and modifying specific elements.

Author:
Logan Hanks
See Also:
com.topcoder.shared.problemParser.ProblemComponentFactory, Element, BaseElement, DataType, Language, Serialized Form

Constructor Summary
ProblemComponent()
          Empty constructor required by custom serialization
ProblemComponent(boolean unsafe)
          A problem statement must be constructed with a set of known data types, the XML it was originally parsed from, and a flag specifying whether this instance is an 'unsafe' version.
 
Method Summary
 void addMessage(ProblemMessage message)
          Append a ProblemMessage to the list of messages.
 void clearMessages()
          Clears the list of problem messages.
 void customReadObject(com.topcoder.shared.netCommon.CSReader reader)
          Custom serialization
 void customWriteObject(com.topcoder.shared.netCommon.CSWriter writer)
          Custom serialization
static java.lang.String decodeXML(java.lang.String text)
          Undoes the encoding scheme in encodeXML.
static java.lang.String encodeHTML(java.lang.String text)
          Utility function for encoding HTML entities in text.
static java.lang.String encodeXML(java.lang.String text)
          Utility function for encoding "special" xml characters, or characters not allowing xml to properly parse.
 java.util.ArrayList getArgs()
          Deprecated. for old stuff, just gets array list of java types.
 java.lang.String getCacheKey()
          Get's the cache key for this component
static java.lang.String getCacheKey(int componentID)
          Get's the cache key for supplied component id
 java.lang.String getClassName()
          Get's the name of the class that should be defined in solutions to this problem.
 int getComponentId()
          Get's the component id
 int getComponentTypeID()
          Get's the component type id
 Constraint[] getConstraints()
          Get's the list of constraints.
 java.lang.String getDefaultSolution()
          Get's the default solution
 Element getIntro()
          The 'intro' is the required introductory text for a problem statement (shown before the signature).
 java.util.ArrayList getMessages()
          Get's the list of ProblemMessages generated by the parsing process.
 java.lang.String getMethodName()
          Get's the name of the method that should be defined in solutions to this problem.
 Element[] getNotes()
          Get's the list of notes.
 java.lang.String[] getParamNames()
          Get's the names of the arguments to the method that should be defined in solutions to this problem.
 DataType[] getParamTypes()
          Get's the data type of all of the arguments to the method that should be defined in solutions to this problem.
 int getProblemId()
          Get's the problem id that this component is associated with
 ElementRenderer getRenderer()
          Returns this elements renderer.
 java.lang.String getResultType()
          Deprecated.  
 DataType getReturnType()
          Get's the return type of the method that should be defined in solutions to this problem.
 java.lang.String getReturnType(int language)
          Get's the string representation of the return type for the required method for this component for the specified language
 Element getSpec()
          The 'spec' is the optional text following the signature, typically giving more technical information about the problem.
 TestCase[] getTestCases()
          Get's the list of test cases.
static java.lang.String handleTextElement(java.lang.String name, Element elem)
          Helper method to format an element between an opening/closing html tag
 boolean isUnsafe()
          If a problem component is unsafe, then it should not have all the system test cases, only those that are marked as examples.
 boolean isValid()
          A problem statement is valid if it was successfully parsed without errors.
static void main(java.lang.String[] args)
          Main method to test out the encodeXML/decodeXML function
 void setClassName(java.lang.String className)
          Set's the name of the class that should be defined in solutions to this problem.
 void setComponentId(int componentId)
          Set's the component id
 void setComponentTypeID(int componentTypeID)
          Set's the component type id
 void setConstraints(Constraint[] constraints)
          Set's the list of constraints.
 void setDefaultSolution(java.lang.String solution)
          Set's the default solution
 void setIntro(Element intro)
          Updates the 'intro' element.
 void setMessages(java.util.ArrayList messages)
          Set's the list of ProblemMessages generated by the parsing process.
 void setMethodName(java.lang.String methodName)
          Set's the name of the method that should be defined in solutions to this problem.
 void setNotes(Element[] notes)
          Set's the list of notes.
 void setParamNames(java.lang.String[] paramNames)
          Set's the names of the arguments to the method that should be defined in solutions to this problem.
 void setParamTypes(DataType[] paramTypes)
          Set's the data type of all of the arguments to the method that should be defined in solutions to this problem.
 void setProblemId(int problemId)
          Set's the problem id that this component is associated with
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 void setReturnType(DataType returnType)
          Set's the return type of the method that should be defined in solutions to this problem.
 void setSpec(Element spec)
          Updates the 'spec' element.
 void setTestCases(TestCase[] testCases)
          Set's the list of test cases.
 void setUnsafe(boolean unsafe)
          If a problem component is unsafe, then it should not have all the system test cases, only those that are marked as examples.
 void setValid(boolean valid)
          Set's the validity of the problem statement
 java.lang.String toString()
          Returns the string representation of this object
 java.lang.String toXML()
          Get's an XML representation for this component
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
getRenderer, setRenderer
 

Constructor Detail

ProblemComponent

public ProblemComponent()
Empty constructor required by custom serialization


ProblemComponent

public ProblemComponent(boolean unsafe)
A problem statement must be constructed with a set of known data types, the XML it was originally parsed from, and a flag specifying whether this instance is an 'unsafe' version.

Parameters:
unsafe - If true, specifies that the problem statement contains sensitive information that should be available only to MPSQAS
Method Detail

encodeXML

public static java.lang.String encodeXML(java.lang.String text)
Utility function for encoding "special" xml characters, or characters not allowing xml to properly parse. Replaces bad characters with /ASCIIXXX/ where XXX is the ascii value of the character.


decodeXML

public static java.lang.String decodeXML(java.lang.String text)
Undoes the encoding scheme in encodeXML.

Parameters:
text - the text to decode
Returns:
the decoded text

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
Custom serialization

Specified by:
customReadObject in interface Element
Parameters:
reader - the reader to read from.
Throws:
java.io.IOException - if an I/O error has occurred in the stream that backs the reader.

isUnsafe

public boolean isUnsafe()
If a problem component is unsafe, then it should not have all the system test cases, only those that are marked as examples.

Returns:
whether the component is unsafe or not

setUnsafe

public void setUnsafe(boolean unsafe)
If a problem component is unsafe, then it should not have all the system test cases, only those that are marked as examples.

Parameters:
unsafe - whether the component is unsafe or not

isValid

public boolean isValid()
A problem statement is valid if it was successfully parsed without errors.

Returns:
whether the problem statement is valid

setValid

public void setValid(boolean valid)
Set's the validity of the problem statement

Parameters:
valid - whether the problem statement was parsed without errors

getMessages

public java.util.ArrayList getMessages()
Get's the list of ProblemMessages generated by the parsing process.

Returns:
An ArrayList of ProblemMessages
See Also:
ProblemMessage

setMessages

public void setMessages(java.util.ArrayList messages)
Set's the list of ProblemMessages generated by the parsing process.

Parameters:
messages - the list of ProblemMessages generated by the parsing process.
See Also:
ProblemMessage

clearMessages

public void clearMessages()
Clears the list of problem messages.


addMessage

public void addMessage(ProblemMessage message)
Append a ProblemMessage to the list of messages.

Parameters:
message - the message to add
See Also:
ProblemMessage

getIntro

public Element getIntro()
The 'intro' is the required introductory text for a problem statement (shown before the signature).

Returns:
the introductory text
See Also:
Element

setIntro

public void setIntro(Element intro)
Updates the 'intro' element.

Parameters:
intro - the introductory text
See Also:
getIntro(), Element

getSpec

public Element getSpec()
The 'spec' is the optional text following the signature, typically giving more technical information about the problem.

Returns:
the specification text or null if none
See Also:
Element

setSpec

public void setSpec(Element spec)
Updates the 'spec' element.

Parameters:
spec - the specification text
See Also:
getSpec(), Element

getClassName

public java.lang.String getClassName()
Get's the name of the class that should be defined in solutions to this problem.

Returns:
the name of the class that should be defined in solutions to this problem.

setClassName

public void setClassName(java.lang.String className)
Set's the name of the class that should be defined in solutions to this problem.

Parameters:
className - the class name

getMethodName

public java.lang.String getMethodName()
Get's the name of the method that should be defined in solutions to this problem.

Returns:
the name of the method that should be defined in solutions to this problem.

setMethodName

public void setMethodName(java.lang.String methodName)
Set's the name of the method that should be defined in solutions to this problem.

Parameters:
methodName - the name of the method

getReturnType

public DataType getReturnType()
Get's the return type of the method that should be defined in solutions to this problem.

Returns:
the return type of the method that should be defined in solutions to this problem.
See Also:
DataType

setReturnType

public void setReturnType(DataType returnType)
Set's the return type of the method that should be defined in solutions to this problem.

Parameters:
returnType - the return type for the method
See Also:
DataType, getReturnType()

getParamTypes

public DataType[] getParamTypes()
Get's the data type of all of the arguments to the method that should be defined in solutions to this problem.

Returns:
An array of DataTypes, where the first value is the type of the first argument, the second value is the type of the second argument, and so on
See Also:
DataType

setParamTypes

public void setParamTypes(DataType[] paramTypes)
Set's the data type of all of the arguments to the method that should be defined in solutions to this problem.

Parameters:
paramTypes - An array of DataTypes, where the first value is the type of the first argument, the second value is the type of the second argument, and so on
See Also:
DataType, getParamTypes()

getParamNames

public java.lang.String[] getParamNames()
Get's the names of the arguments to the method that should be defined in solutions to this problem.

Returns:
An array of Strings, where the first value is the name of the first argument, the second value is the name of the second argument, and so on

setParamNames

public void setParamNames(java.lang.String[] paramNames)
Set's the names of the arguments to the method that should be defined in solutions to this problem.

Parameters:
paramNames - An array of Strings, where the first value is the name of the first argument, the second value is the name of the second argument, and so on
See Also:
getParamNames()

getNotes

public Element[] getNotes()
Get's the list of notes.

Returns:
An array of Elements, each Element representing a note
See Also:
Element

setNotes

public void setNotes(Element[] notes)
Set's the list of notes.

Parameters:
notes - An array of Elements, each Element representing a note
See Also:
Element

getConstraints

public Constraint[] getConstraints()
Get's the list of constraints.

Returns:
An array of Constraints, each Constraint representing a constraint
See Also:
Constraint

setConstraints

public void setConstraints(Constraint[] constraints)
Set's the list of constraints.

Parameters:
constraints - An array of Constraints, each Constraint representing a constraint
See Also:
Constraint

getTestCases

public TestCase[] getTestCases()
Get's the list of test cases. This will include at least all of the example test cases. If this is an unsafe version of the problem statement, it will include the system test cases as well.

Returns:
the test cases
See Also:
TestCase

setTestCases

public void setTestCases(TestCase[] testCases)
Set's the list of test cases.

Parameters:
testCases - the list of test cases

handleTextElement

public static java.lang.String handleTextElement(java.lang.String name,
                                                 Element elem)
Helper method to format an element between an opening/closing html tag

Parameters:
name - name of the html tag (unformatted)
elem - the element
Returns:
formatted string with the element between an opening/closing html tag

toXML

public java.lang.String toXML()
Get's an XML representation for this component

Specified by:
toXML in interface Element
Returns:
the XML representation

toString

public java.lang.String toString()
Returns the string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
the string representation of this object

getComponentTypeID

public int getComponentTypeID()
Get's the component type id

Returns:
the component type id

setComponentTypeID

public void setComponentTypeID(int componentTypeID)
Set's the component type id

Parameters:
componentTypeID - the component type id

setComponentId

public final void setComponentId(int componentId)
Set's the component id

Parameters:
componentId - the unique component id

setDefaultSolution

public final void setDefaultSolution(java.lang.String solution)
Set's the default solution

Parameters:
solution - the default solution

getComponentId

public final int getComponentId()
Get's the component id

Returns:
the unique component id

getDefaultSolution

public final java.lang.String getDefaultSolution()
Get's the default solution

Returns:
the default solution

getProblemId

public int getProblemId()
Get's the problem id that this component is associated with

Returns:
the unique problem identifier

setProblemId

public void setProblemId(int problemId)
Set's the problem id that this component is associated with

Parameters:
problemId - the unique problem identifier

getCacheKey

public static java.lang.String getCacheKey(int componentID)
Get's the cache key for supplied component id

Parameters:
componentID - the component id
Returns:
the cache key for supplied component id

getCacheKey

public final java.lang.String getCacheKey()
Get's the cache key for this component

Returns:
cache key for this component

getReturnType

public java.lang.String getReturnType(int language)
Get's the string representation of the return type for the required method for this component for the specified language

Parameters:
language - the languageID
Returns:
the return type for the languageID

getResultType

public java.lang.String getResultType()
Deprecated.  


getArgs

public java.util.ArrayList getArgs()
Deprecated. for old stuff, just gets array list of java types.


main

public static void main(java.lang.String[] args)
Main method to test out the encodeXML/decodeXML function

Parameters:
args - the first element will be encoded and decoded
Returns:
system.out messages of the encoding/decoding process

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.