standup.joke
Class JokeSet

java.lang.Object
  extended by standup.joke.JokeSet
All Implemented Interfaces:
XMLizable, XMLsaveable

public class JokeSet
extends Object
implements XMLsaveable

This class represents a set of JokeStructures. It defines all functions for manipulating sets of jokes, i.e. mutator methods:

Additionally, JokeSets can be loaded from/saved to XML-based files with a .jokes extension.

Author:
Ruli Manurung

Field Summary
private  Set<JokeStructure> jokes
          This Set contains the jokes themselves.
 
Constructor Summary
JokeSet()
           
 
Method Summary
 int add(JokeSet js)
           
 boolean add(JokeStructure j)
          ================ ACCESSOR METHODS ================
 boolean contains(JokeStructure j)
          Checks whether the given Joke j is contained within this JokeSet.
 JokeSet duplicate()
          Returns a shallow copy of this JokeSet -- but then again JokeStructures should be immutable objects so it shouldn't make a difference...
 int getCount()
           
 JokeStructure getJokeByID(String id)
          Returns the JokeStructure contained in this JokeSet specified by the given id argument, or null if no such joke is found.
 JokeSet getJokes(JokeConstraints jcs)
           
(package private)  JokeSet getJokes(String schemaLabel)
          This function is only used when checking schema instantiations against the generated joke log.
 Set<JokeStructure> getJokesAsSet()
           
 JokeStructure getRandom()
           
 boolean isEmpty()
           
static JokeSet load(File file)
           
static JokeSet load(URL url)
           
static JokeSet readXML(Element doc)
           
 void remove(JokeSet js)
           
 void remove(JokeStructure j)
           
 JokeStructure removeRandom()
           
 void save(File file)
          This method saves the necessary information contained within an instance to an XML file.
 String toString()
           
 void writeXML(Writer out, String indent)
          This method writes the necessary information contained within an instance to an XML file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

jokes

private Set<JokeStructure> jokes
This Set contains the jokes themselves.

Constructor Detail

JokeSet

public JokeSet()
Method Detail

getJokeByID

public JokeStructure getJokeByID(String id)
Returns the JokeStructure contained in this JokeSet specified by the given id argument, or null if no such joke is found.

Parameters:
id -
Returns:

duplicate

public JokeSet duplicate()
Returns a shallow copy of this JokeSet -- but then again JokeStructures should be immutable objects so it shouldn't make a difference...

Returns:

add

public boolean add(JokeStructure j)
================ ACCESSOR METHODS ================


add

public int add(JokeSet js)

remove

public void remove(JokeStructure j)

remove

public void remove(JokeSet js)

getJokesAsSet

public Set<JokeStructure> getJokesAsSet()

contains

public boolean contains(JokeStructure j)
Checks whether the given Joke j is contained within this JokeSet. Note that this assumes the equals method for Jokes is well defined. Particularly, we should see what happens when he compare JokeStructures with MockJokes!

Parameters:
j -
Returns:
whether or not this JokeSet contains j

getJokes

public JokeSet getJokes(JokeConstraints jcs)

getJokes

JokeSet getJokes(String schemaLabel)
This function is only used when checking schema instantiations against the generated joke log. This function returns all jokes whose instantiations are to be removed from the query results.

Parameters:
schemaLabel -
Returns:

isEmpty

public boolean isEmpty()

getCount

public int getCount()

getRandom

public JokeStructure getRandom()

removeRandom

public JokeStructure removeRandom()

toString

public String toString()
Overrides:
toString in class Object

writeXML

public void writeXML(Writer out,
                     String indent)
              throws IOException,
                     XMLException
Description copied from interface: XMLizable
This method writes the necessary information contained within an instance to an XML file.

Specified by:
writeXML in interface XMLizable
Parameters:
out - The output stream for the XML file, which is assumed to be already opened and writable.
indent - A string to be prepended before every line written by this method. If passed appropriate white space, e.g. XMLUtils.xmlIndent, it can be used to control indentation.
Throws:
IOException
XMLException

readXML

public static JokeSet readXML(Element doc)

save

public void save(File file)
Description copied from interface: XMLsaveable
This method saves the necessary information contained within an instance to an XML file. It should:

Specified by:
save in interface XMLsaveable
Parameters:
file - The file to be saved.

load

public static JokeSet load(URL url)

load

public static JokeSet load(File file)