com.topcoder.shared.problem
Class Problem

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

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

This class contains data for a problem. Each problem consists of a number of components. The actual program interface data (className, etc.) of each component is contained in ProblemComponent objects. For single-coder contests, each problem has only one component.

Author:
Jing Xue
, Hao Kung
See Also:
Serialized Form

Constructor Summary
Problem()
          Empty constructor required by custom serialization
 
Method Summary
 java.lang.Object clone()
          Clones the problem object (note: incomplete)
 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.
 java.lang.String getCacheKey()
          Returns the cache key for this problem
static java.lang.String getCacheKey(int problemid)
          Utility method to return the cache key given a problem id
 ProblemComponent getComponent(int i)
          Gets the Problem Component at the given index
 java.lang.String getName()
          Returns the problem name
 ProblemComponent getPrimaryComponent()
          Returns the problem component considered the main component.
 ProblemComponent[] getProblemComponents()
          Returns the components for this problem
 int getProblemId()
          Returns the unique problem identifier
 java.lang.String getProblemText()
          Returns the problem text
 int getProblemTypeID()
          Returns the problem type identity
 ElementRenderer getRenderer()
          Returns this elements renderer.
 WebService[] getWebServices()
          Returns the web services for the problem
 boolean isValid()
          Returns whether the problem is valid or not.
 void setName(java.lang.String name)
          Sets the name of the problem
 void setProblemComponents(ProblemComponent[] problemComponents)
          Sets the components for this problem
 void setProblemId(int problemId)
          Sets the unique problem identifier
 void setProblemText(java.lang.String problemText)
          Sets the problem text
 void setProblemTypeID(int problemTypeID)
          Sets the problem type identity
 void setRenderer(ElementRenderer renderer)
          Sets the renderer for this element.
 void setWebServices(WebService[] webServices)
          Sets the web services for the problem
 java.lang.String toString()
          Returns a user readable version of the problem
 java.lang.String toXML()
          Returns an XML representation of the problem TODO: does anyone care this doesn't do anything?
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.topcoder.shared.problem.Element
getRenderer, setRenderer
 

Constructor Detail

Problem

public Problem()
Empty constructor required by custom serialization

Method Detail

getCacheKey

public final java.lang.String getCacheKey()
Returns the cache key for this problem

Returns:
the cache key for this problem

getCacheKey

public static java.lang.String getCacheKey(int problemid)
Utility method to return the cache key given a problem id

Parameters:
problemid - the unique problem identifier
Returns:
the cache key for the problem identifier

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.

setProblemId

public void setProblemId(int problemId)
Sets the unique problem identifier

Parameters:
problemId - the problem identifier

getProblemId

public int getProblemId()
Returns the unique problem identifier

Returns:
the unique problem identifier

clone

public java.lang.Object clone()
Clones the problem object (note: incomplete)

Overrides:
clone in class java.lang.Object
Returns:
the cloned problem

setName

public void setName(java.lang.String name)
Sets the name of the problem

Parameters:
name - the name of the problem

getName

public java.lang.String getName()
Returns the problem name

Returns:
the problem name

getProblemText

public java.lang.String getProblemText()
Returns the problem text

Returns:
the problem text

setProblemText

public void setProblemText(java.lang.String problemText)
Sets the problem text

Parameters:
problemText - the problem text

getProblemComponents

public ProblemComponent[] getProblemComponents()
Returns the components for this problem

Returns:
the components for this problem
See Also:
ProblemComponent

setProblemComponents

public void setProblemComponents(ProblemComponent[] problemComponents)
Sets the components for this problem

Parameters:
problemComponents - the components for this problem
See Also:
ProblemComponent

getPrimaryComponent

public ProblemComponent getPrimaryComponent()
Returns the problem component considered the main component. ie whose getComponentTypeID() returns ProblemConstants.MAIN_COMPONENT

Returns:
the main component of the problem or null if none found
See Also:
ProblemComponent, ProblemConstants

getProblemTypeID

public int getProblemTypeID()
Returns the problem type identity

Returns:
the problem type identity

setProblemTypeID

public void setProblemTypeID(int problemTypeID)
Sets the problem type identity

Parameters:
problemTypeID - the problem type identity

getComponent

public ProblemComponent getComponent(int i)
Gets the Problem Component at the given index

Parameters:
i - the index position
Returns:
the problem component at the given index or null if i doesn't exist (note: will throw an IndexOutOfBoundsException if < 0)

toString

public java.lang.String toString()
Returns a user readable version of the problem

Overrides:
toString in class java.lang.Object
Returns:
a user readable version of the problem

isValid

public boolean isValid()
Returns whether the problem is valid or not. (Simply if all the components are valid)

Returns:
true if valid, false if not

setWebServices

public void setWebServices(WebService[] webServices)
Sets the web services for the problem

Parameters:
webServices - the web services for the problem

getWebServices

public WebService[] getWebServices()
Returns the web services for the problem

Returns:
the web services for the problem

toXML

public java.lang.String toXML()
Returns an XML representation of the problem TODO: does anyone care this doesn't do anything?

Specified by:
toXML in interface Element
Returns:
blank string

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.