hu.birot.OTKit.otBuildingBlocks
Class Constraint

java.lang.Object
  extended by hu.birot.OTKit.otBuildingBlocks.Constraint

public abstract class Constraint
extends java.lang.Object

Realizes a constraint.

A Constraint combines two pieces of information:

  1. a name, which serves as the only identification for the constraint (two constraints are equal if they share the same name), and
  2. a method assigning a Violation to any Candidate

Hence, to construct a Constraint, one must specify its name in the constructor, as well as specify method Constraint.value(Candidate). Class ConstraintExamples contain a number of predifined constraints.


Constructor Summary
Constraint(java.lang.String Name)
          To construct a constraint, you must define its name, besides specifying method Constraint.value(Candidate).
Constraint(java.lang.String Name, java.lang.String Description)
          To construct a constraint, you may define its name and its description, besides specifying method Constraint.value(Candidate).
 
Method Summary
 java.lang.String description()
          Description of the constraint.
static Constraint empty(java.lang.String name)
          Returning an "empty" Constraint, having only a name.
 boolean equals(java.lang.Object constr)
          Two constraints are equals iff their name are equal.
 int hashCode()
          Returns a hash code for this constraint.
 java.lang.String name()
          This method returns the name of the constraint.
 void rename(java.lang.String newname)
          Rename the constraint.
 void setDescription(java.lang.String Description)
          Set the description of the constraint.
 java.lang.String toString()
          The string corresponding to a constraint is its name.
abstract  Violation value(Candidate can)
          The violation level assigned by the constraint to candidate can.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Constraint

public Constraint(java.lang.String Name)
To construct a constraint, you must define its name, besides specifying method Constraint.value(Candidate).


Constraint

public Constraint(java.lang.String Name,
                  java.lang.String Description)
To construct a constraint, you may define its name and its description, besides specifying method Constraint.value(Candidate).

Method Detail

value

public abstract Violation value(Candidate can)
The violation level assigned by the constraint to candidate can. This abstract method must be instantiated for any constraint.

Parameters:
can - : The candidate being evaluated.
Returns:
A violation level.

name

public java.lang.String name()
This method returns the name of the constraint. Note that the name is the only identification for a constraint. For instance the equality of two constraints are defined as having the same name.

Returns:
The name of the constraint.

rename

public void rename(java.lang.String newname)
Rename the constraint. Note that the name is the only identification for a constraint. For instance the equality of two constraints are defined as having the same name.

Parameters:
newname - New name of the constraint.

description

public java.lang.String description()
Description of the constraint.


setDescription

public void setDescription(java.lang.String Description)
Set the description of the constraint. (Avoid using, if possible.)


equals

public boolean equals(java.lang.Object constr)
Two constraints are equals iff their name are equal. This method overrides java.lang.Object.equals.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Returns a hash code for this constraint. The output is the hash code for the string containing the name of the constraint.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
The string corresponding to a constraint is its name. (Remember that two constraints are equal if their names are equal.) This method overrides java.lang.Object.toString.

Overrides:
toString in class java.lang.Object

empty

public static Constraint empty(java.lang.String name)

Returning an "empty" Constraint, having only a name. Its value method throws an exception. This method can be used if, for technical reasons, you need a constraint that has a name, but otherwise is never used.

Parameters:
name - String containing the name of the returned Constraint.
Returns:
An empty, useless Constraint with a name.