hu.birot.OTKit.dataType.violation
Class BooleanViolation

java.lang.Object
  extended by hu.birot.OTKit.dataType.violation.Violation
      extended by hu.birot.OTKit.dataType.violation.BooleanViolation

public class BooleanViolation
extends Violation

Violation with Boolean values (true or false). Value true is better than false. Their difference is -1.

Value true is better than false, but not vice versa:

v1v2v1.betterEqual(v2)
falsefalsetrue
falsetrue false
true falsetrue
true true true

Value false minus value true is 1, and vice versa it gives -1:

v1v2v1.difference(v2)
falsefalse0
falsetrue 1
true false-1
true true 0

For efficiency, the use of the static method v is highly recommended (for instance, in the definition of constraints) instead of the standard constructor.

See Also:
Violation

Field Summary
static BooleanViolation FALSE
          The boolean violation with value false.
static BooleanViolation TRUE
          The boolean violation with value true.
 
Fields inherited from class hu.birot.OTKit.dataType.violation.Violation
thisclass
 
Constructor Summary
BooleanViolation(boolean v)
          Construct a new boolean violation, whose value is v.
 
Method Summary
 boolean betterEqual(Violation v)
          Compares this violation to (boolean) violation v: returns whether this is better than or equal to v.
 BooleanViolation clone()
          Return a new BooleanViolatio with the same boolean value.
 double difference(Violation v)
          Computes the difference of this violation and of the (boolean) violation v ("this – v").
 boolean equals(java.lang.Object o)
          This violation is equal to object o, if and only if o is also a BooleanViolation with the same boolean value.
 int hashCode()
          A hash code for the violation.
 java.lang.String toString()
          String representation of the violation.
static BooleanViolation v(boolean v)
          "Quick constructor".
 java.lang.Boolean value()
          Return the actual (boolean) value represented by this BooleanViolation.
 
Methods inherited from class hu.birot.OTKit.dataType.violation.Violation
isBetter, isEqual, notComparable
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRUE

public static final BooleanViolation TRUE
The boolean violation with value true.


FALSE

public static final BooleanViolation FALSE
The boolean violation with value false.

Constructor Detail

BooleanViolation

public BooleanViolation(boolean v)
Construct a new boolean violation, whose value is v.

Parameters:
v - Boolean value of the new BooleanViolation to be constructed.
Method Detail

value

public java.lang.Boolean value()
Return the actual (boolean) value represented by this BooleanViolation.

Specified by:
value in class Violation
Returns:
the value of the violation.
See Also:
IntegerViolation.value(), FloatViolation.value()

v

public static BooleanViolation v(boolean v)

"Quick constructor". Returns the violation with value v that has been already constructed earlier: either BooleanViolation.TRUE or BooleanViolation.FALSE.

With equal arguments, this method always returns the same violation; that is, not only equal violations, with respect to the equals method. Subsequently, several methods comparing two violations run more efficiently, and less time is spent on constructing new violations, and then on collecting garbage. Therefore it is recommended to use this static method in the definition of constraints, and not the standard constructor of the violations.

Parameters:
v - Value of the violation to be returned.
Returns:
The violation with value v, the only one constructed.
See Also:
TRUE, FALSE

clone

public BooleanViolation clone()
Return a new BooleanViolatio with the same boolean value.

Specified by:
clone in class Violation

betterEqual

public boolean betterEqual(Violation v)

Compares this violation to (boolean) violation v: returns whether this is better than or equal to v.

Value true is better than false, but not vice versa:

v1v2v1.betterEqual(v2)
falsefalsetrue
falsetrue false
true falsetrue
true true true

Consequently, v1.betterEqual(v2) equals the implication v2 -> v1, which is the same as the expression v1.value() || !v2.value().

If v is not a BooleanViolation, then false is returned.

If a constraint assigns violations of type BooleanViolation, then – as explained in the introduction to the abstract class Violation – all candidates must be assigned such violations. Consequently, in practice this method receives only violations of the same type as its argument.

Specified by:
betterEqual in class Violation
Parameters:
v - boolean violation to which this violation is compared.
Returns:
the comparison of the two violations, as explained above.
See Also:
Violation, Violation.betterEqual(Violation)

difference

public double difference(Violation v)

Computes the difference of this violation and of the (boolean) violation v ("this – v").

Value false minus value true is 1, and vice versa it gives -1:

v1v2v1.difference(v2)
falsefalse0
falsetrue 1
true false-1
true true 0

The second violation must also be boolean. If a constraint assigns violations of type BooleanViolation, then – as explained in the introduction to the abstract class Violation – all candidates must be assigned such violations. Consequently, in practice this method receives only violations of the same type as its argument.

Specified by:
difference in class Violation
Parameters:
v - the subtrahend, by which this violation is "diminished".
Returns:
the difference of the two violations, as explained above.
See Also:
Violation, Violation.difference(Violation)

equals

public boolean equals(java.lang.Object o)
This violation is equal to object o, if and only if o is also a BooleanViolation with the same boolean value.

Overrides:
equals in class Violation
Parameters:
o - Object to be compared to this violation.
Returns:
Whether the two objects are equal: whether o is a BooleanViolation && whether o has the same boolean value as this boolean violation.

toString

public java.lang.String toString()
String representation of the violation.

Specified by:
toString in class Violation
Returns:
""+this.value().

hashCode

public int hashCode()
A hash code for the violation.

Overrides:
hashCode in class Violation
Returns:
1 if value is true, and 0 if value is false.