standup.joke
Class JokeConstraints

java.lang.Object
  extended by standup.joke.JokeConstraints

public class JokeConstraints
extends Object


Field Summary
private  Set<JokeConstraint> constraints
           
 
Constructor Summary
JokeConstraints()
           
 
Method Summary
 void add(JokeConstraint c)
           
 void add(JokeConstraints cs)
           
 boolean equals(Object obj)
           
private  List<SchemaTemplatePair> filterSTPs(List<SchemaTemplatePair> existingSTPs, JokeConstraintType jc)
          Returns the intersection between existingSTPs, a list of SchemaTemplatePairs, and jc, a JokeConstraintType.
 Collection<JokeConstraint> getConstraints()
           
 InstantiationConstraint[] getInstantiationConstraints()
          Takes all the InstantiationConstraints in this JokeConstraints and returns them as an InstantiationConstraint[] array.
 List<SchemaTemplatePair> getSchemaTemplatePairs(JokeType masterType)
           Takes all the JokeConstraintTypes and JokeConstraintAllowedSchemas in this JokeConstraints and returns a List of all the possible SchemaTemplatePairs that satisfy all of them.
 int hashCode()
           
 boolean isEmpty()
           
 void remove(JokeConstraint c)
           
 void remove(JokeConstraints cs)
           
 String toString()
           
 boolean validate(JokeStructure j)
          This boolean function returns true whether existing JokeStructure j satisfies all the constraints in this JokeConstraints, and false otherwise.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

constraints

private Set<JokeConstraint> constraints
Constructor Detail

JokeConstraints

public JokeConstraints()
Method Detail

isEmpty

public boolean isEmpty()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

add

public void add(JokeConstraint c)

add

public void add(JokeConstraints cs)

remove

public void remove(JokeConstraint c)

remove

public void remove(JokeConstraints cs)

validate

public boolean validate(JokeStructure j)
This boolean function returns true whether existing JokeStructure j satisfies all the constraints in this JokeConstraints, and false otherwise. It simply calls validate(JokeStructure) on all JokeConstraint objects within this JokeConstraints.

Parameters:
j - the JokeStructure being validated
Returns:
true if j satisfies all constraints, false otherwise.

toString

public String toString()
Overrides:
toString in class Object

getConstraints

public Collection<JokeConstraint> getConstraints()

getInstantiationConstraints

public InstantiationConstraint[] getInstantiationConstraints()
Takes all the InstantiationConstraints in this JokeConstraints and returns them as an InstantiationConstraint[] array.

If constraints is null or contains no InstantiationConstraints, it simply returns null.

Returns:
an array of all InstantiationConstraints

getSchemaTemplatePairs

public List<SchemaTemplatePair> getSchemaTemplatePairs(JokeType masterType)

Takes all the JokeConstraintTypes and JokeConstraintAllowedSchemas in this JokeConstraints and returns a List of all the possible SchemaTemplatePairs that satisfy all of them.

It starts with the SchemaTemplatePairs in the given JokeType, which would typically be the master joke type (as returned by Generator.getMasterJokeType(), and computes the valid intersection specified by all the given JokeConstraintTypes by repeatedly calling filterSTPs(List, JokeConstraintType). If there are no specified JokeConstraintTypes, it simply returns all the SchemaTemplatePairs in the given joke type.

Parameters:
masterType - the JokeType containing all the SchemaTemplatePairs that will be used as the starting point
Returns:
a List of SchemaTemplatePairs that satisfy all JokeConstraintTypes in the given JokeConstraints

filterSTPs

private List<SchemaTemplatePair> filterSTPs(List<SchemaTemplatePair> existingSTPs,
                                            JokeConstraintType jc)
Returns the intersection between existingSTPs, a list of SchemaTemplatePairs, and jc, a JokeConstraintType.

The intersection is computed at two levels: that of question and answer templates. For example, the intersection between {,>,,>} and {,>, ,>} is {,>}.

Parameters:
existingSTPs - an existing list of SchemaTemplatePairs
jc - a JokeConstraintType
Returns:
the intersection between existingSTPs and the SchemaTemplatePairs in jc