|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hu.birot.OTKit.dataType.violation.Violation hu.birot.OTKit.dataType.violation.IntegerViolation
public class IntegerViolation
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).
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 |
---|
public static final IntegerViolation nullViolation
public static final IntegerViolation oneViolation
public static java.lang.RuntimeException ArgumentNotIntegerViolation
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
.
difference(Violation)
Constructor Detail |
---|
public IntegerViolation(int violation_level)
violation_level
- : The integer value defining the violation level.Method Detail |
---|
public java.lang.Integer value()
Returns the value of the violation.
value
in class Violation
value()
,
FloatViolation.value()
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.
v
- Value of the violation to be returned.
v
, the only one constructed.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
.
betterEqual
in class Violation
v
- The second violation, to which this violation is compared.
true
if this violation is better than or
equal to v
, and if they are both instances of
IntegerViolation
. Otherwise false
is returned.Violation.betterEqual(Violation)
,
Violation.isBetter(Violation, Violation)
,
Violation.isEqual(Violation, Violation)
,
Violation.notComparable(Violation, Violation)
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
).
difference
in class Violation
v
- The subtrahend violation.
this - v
), cast to double.- See Also:
ArgumentNotIntegerViolation
,
Violation.difference(Violation)
public boolean equals(java.lang.Object o)
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.
equals
in class Violation
o
- Object to be compared to the current violation.
true
for IntegerViolations whose value are
equal to the value of the current violation; false
in all other cases.Violation.equals(Object)
public Violation clone()
clone
in class Violation
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.
toString
in class Violation
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.
public int hashCode()
A hash code corresponding to the Violation. It is simply the integer value of the violation.
hashCode
in class Violation
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |