hu.birot.OTKit.dataType.violation
Class IntegerViolation

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

public class IntegerViolation
extends Violation

A violation with an integer value. This subclass of the abstract class Violation is used with constraints that are violated an integer number of times. In other words, with constraints whose range is the set of the integer numbers. In practice, most constraints used in linguistics belong to this type: they are either satisfied (zero violation), or violated once, twice, etc. (the number of stars in the tableau).

The method stars() transforms a violation into a string of stars, corresponding to the value of the violation, or to an empty string, for zero violations. The method can be used to fill traditional OT tableau cells. Although in linguistic practice a constraint applied to a candidate returns a non-negative integer, this class also allows "negative violations" (despite the fact that Biro (2006:76) requires that the set of violations assigned by a constraint to the elements of a candidate set be a well-ordered set, a totally ordered set in which any subset has a lower bound contained by that subset). Consequently, the method stars() introduces the hyphen symbol ("-") for negative violation levels.

Note the method v(integer), which returns an already constructed violation, unless no such violation was needed so far. Using this method instead of the constructor IntegerViolation(int violation_level) is more efficient, because of several reasons: the time needed for constructing new violations (and for the corresponding garbage collection) is saved, and the Violation.isEqual(Violation,Violation) is also faster if the two violations refer to the same object. So, the use of the static method v is highly recommended, unless extremely many different violation levels are needed.

Two constant violations complement this class: IntegerViolation.nullViolation (describing the case when the constraint is satisfied) and IntegerViolation.oneViolation (a single star).

See Also:
Violation

Field Summary
static java.lang.RuntimeException ArgumentNotIntegerViolation
          Exception "Argument is not IntegerViolation".
static IntegerViolation nullViolation
          Zero violation level: the constraint is satisfied.
static IntegerViolation oneViolation
          One violation level: the constraint is violated once.
 
Fields inherited from class hu.birot.OTKit.dataType.violation.Violation
thisclass
 
Constructor Summary
IntegerViolation(int violation_level)
          Construct a Violation (that is, a subclass IntegerViolation) with its value.
 
Method Summary
 boolean betterEqual(Violation v)
          Compares the present Violation to Violation v, and returns true if and only if this violation is better than or equal to v.
 Violation clone()
          Creates a clone of the Violation, with the same value.
 double difference(Violation v)
          Returns the difference of this violation and of violation v (in this order: "this-v").
 boolean equals(java.lang.Object o)
          Equality of two violations.
 int hashCode()
          A hash code corresponding to the Violation.
 java.lang.String stars()
          Violation level expressed as a string of *'s or of -'s.
 java.lang.String toString()
          Transforms a Violation into a String, returning the decimal representation of the violation.
static IntegerViolation v(int v)
          "Quick constructor".
 java.lang.Integer value()
          Returns the value of the violation.
 
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

nullViolation

public static final IntegerViolation nullViolation
Zero violation level: the constraint is satisfied. Using this pre-compiled value can speed up computations.


oneViolation

public static final IntegerViolation oneViolation
One violation level: the constraint is violated once. Using this pre-compiled value can speed up computations.


ArgumentNotIntegerViolation

public static java.lang.RuntimeException ArgumentNotIntegerViolation
Exception "Argument is not IntegerViolation". It is thrown by the method IntegerViolation.difference(Violation v) whenever the argument is not an IntegerViolation. To be more precise, whenever v.value() for the argument v cannot be cast to Integer.

See Also:
difference(Violation)
Constructor Detail

IntegerViolation

public IntegerViolation(int violation_level)
Construct a Violation (that is, a subclass IntegerViolation) with its value.

Parameters:
violation_level - : The integer value defining the violation level.
Method Detail

value

public java.lang.Integer value()

Returns the value of the violation.

Specified by:
value in class Violation
Returns:
The value represented by the violation, and integer number of violations.
See Also:
value(), FloatViolation.value()

v

public static IntegerViolation v(int v)

"Quick constructor". Return the violation with value v that has been already constructed earlier. If no violation with that value has ever been constructed, then it is first created.

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.

If the number of different violation levels is extremely high, and each of them is used only very seldom, then keeping all of them in memory may nevertheless be less efficient.

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

betterEqual

public boolean betterEqual(Violation v)

Compares the present Violation to Violation v, and returns true if and only if this violation is better than or equal to v.

More specifically, it returns true if and only if the integer value of this violation is less than or equal to v.value() – provided that v is also an instance of the IntegerViolation class. For other types of violations, the method always returns false. For instance, an instance of IntegerViolation cannot be compared to an instance of FloatViolation, even if everyday arithmetics would make their comparison possible.

This method implements Violation.betterEqual, and is used in the static comparison methods in Violation.

Specified by:
betterEqual in class Violation
Parameters:
v - The second violation, to which this violation is compared.
Returns:
true if this violation is better than or equal to v, and if they are both instances of IntegerViolation. Otherwise false is returned.
See Also:
Violation.betterEqual(Violation), Violation.isBetter(Violation, Violation), Violation.isEqual(Violation, Violation), Violation.notComparable(Violation, Violation)

difference

public double difference(Violation v)

Returns the difference of this violation and of violation v (in this order: "this-v").

If violation v is not an instance of IntegerViolation, or if v.value() cannot be cast to Integer, then exception IntegerViolation.ArgumentNotIntegerViolation is thrown. This happens even if v belongs to another numeric violation subclass, such as FloatViolation.

Otherwise, the arithmetic difference of the two values is returned: this.value()-v.value() (the value of the present violation minus the value of v).

Specified by:
difference in class Violation
Parameters:
v - The subtrahend violation.
Returns:
The difference of the two violations (this - v), cast to double.
See Also:
ArgumentNotIntegerViolation, Violation.difference(Violation)

equals

public boolean equals(java.lang.Object o)
Equality of two violations. Returns true if and only if o belongs to the same class (IntegerViolation) and the value() of the two violations are equal. This method overrides java.lang.Object.equals.

Overrides:
equals in class Violation
Parameters:
o - Object to be compared to the current violation.
Returns:
Value true for IntegerViolations whose value are equal to the value of the current violation; false in all other cases.
See Also:
Violation.equals(Object)

clone

public Violation clone()
Creates a clone of the Violation, with the same value. This method overrides java.lang.Object.clone.

Specified by:
clone in class Violation

toString

public java.lang.String toString()

Transforms a Violation into a String, returning the decimal representation of the violation. Overrides the method java.lang.Object.toString.

Specified by:
toString in class Violation
Returns:
A string representation of the Violation.

stars

public java.lang.String stars()

Violation level expressed as a string of *'s or of -'s.

If the violation level is a positive integer, stars are used. (The output can be used as the content of a cell in an OT tableau.) If the violation level is a negative integer, then as many as -1*IntegerViolation.value() hyphens are returned. If the violation level is 0, then an empty string is returned: no *'s and no -'s.

Returns:
Violation represented as a string: a series of stars (if the violation is positive) or of minus signs (for negative violation).

hashCode

public int hashCode()

A hash code corresponding to the Violation. It is simply the integer value of the violation.

Overrides:
hashCode in class Violation
Returns:
The hash code corresponding to the Violation