|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object hu.birot.OTKit.dataType.Form
public class Form
Data structure representing a linguistic form, such as the ones used for an underlying form, a surface form or an overt form.
A Form has several (private) fields: string
,
counter1
, counter2
, counter3
and
object
. The first is of type String, the counters
are floating point fields, whereas field object
can contain any object. These fields can be filled
in by the constructors, and read via the different methods.
They cannot be modified, because the idea is to see a Form
as an atomic object: similarly to a number or a string,
a form is different if its values are different. Methods
equals
and clone
are thus overridden. A Form
is meant to be immutable and OTKit uses this assumption all
over (for the sake of speed); hence, if a Form is
constructed using a mutable object, you must not alter it,
but create clones.
Field object
allows for more complex, user-defined
data structures: trees, autosegmental representations, AVSs,
etc. For how to use them, refer to the examples given in
the description of class Violation.
Finally, a Form also has a type. The type must be set by the users whenever they construct a Form with an object. In the other cases, the types are "string", "1 counter", "2 counters", "3 counters", "string + 1 counter", etc.
Unless you use the counters with (mathematically) integer values only, you should be careful about possible inaccuracies in floating point arithmetics. For example, the method equals checks whether the counters of two Forms are equal, and floating point rounding errors might cause a wrong return value. Yet, I guess, in most of the cases you will either use small integer values or values not causing such errors. Therefore, I have not slowed down the algorithm by including extra checks for such possible errors. If your model requires Forms that may cause such problems (and it is not possible to recast your model to the integer domain), it is probably better practice to employ the field object with something like java.math.BigDecimal.
A frequently asked question: a candidate differs from a form in that the candidate is a pair of forms: an underlying one and a surface one. Or, a candidate can also contain more level of representations.
NB: This class may be reconsidered in the future, replacing
it by an abstract class Form
with subclasses realizing different
types of forms (a string, a set of counters, a metrical phonological parse, a
syntax tree, and so on). This change has already happened to the class
Violation
. Yet, it remains to be found out which solution would be
quicker, more efficient.
Field Summary | |
---|---|
static java.lang.String |
Empty
String describing the type of an empty Form. |
static java.lang.String |
Form1counter
String describing the type of a Form with 1 counter. |
static java.lang.String |
Form2counters
String describing the type of a Form with 2 counters. |
static java.lang.String |
Form3counters
String describing the type of a Form with 3 counters. |
static java.lang.String |
String
String describing the type of a Form with a string. |
static java.lang.String |
String1counter
String describing the type of a Form with a string and 1 counter. |
static java.lang.String |
String2counters
String describing the type of a Form with a string and 2 counters. |
static java.lang.String |
String3counters
String describing the type of a Form with a string and 3 counters. |
protected java.lang.Class<? extends Form> |
thisclass
|
Constructor Summary | |
---|---|
Form()
This constructor creates an empty Form. |
|
Form(double count1)
This constructor defines a new Form, with the field counter1 being set to count1. |
|
Form(double count1,
double count2)
This constructor defines a new Form, with the field counter1 being set to count1 and counter2 to count2. |
|
Form(double count1,
double count2,
double count3)
This constructor defines a new Form, with the field counter1 being set to count1, counter2 to count2 and finally counter3 to count3. |
|
Form(java.lang.Object O,
java.lang.String Type)
This constructor creates a Form with field object set to O. |
|
Form(java.lang.String str)
This constructor defines a new Form, with the field string being set to str. |
|
Form(java.lang.String str,
double count1)
This constructor defines a new Form, with the field string being set to str, and counter1 to count1. |
|
Form(java.lang.String str,
double count1,
double count2)
This constructor defines a new Form, with the field string being set to str, counter1 to count1 and counter2 to count2. |
|
Form(java.lang.String str,
double count1,
double count2,
double count3)
This constructor defines a new Form, with the field string being set to str, counter1 to count1, counter2 to count2 and finally counter3 to count3. |
Method Summary | |
---|---|
Form |
changeCounter1(java.lang.String val)
This method "changes" the value of field counter1. |
Form |
changeCounter2(java.lang.String val)
This method "changes" the value of field counter2. |
Form |
changeCounter3(java.lang.String val)
This method "changes" the value of field counter3. |
Form |
changeObject(java.lang.Object o)
This method "changes" the value of field object. |
Form |
changeString(java.lang.String str)
This method "changes" the value of field string. |
Form |
clone()
This method creates a clone of the Form. |
double |
counter()
This method returns the value of the field counter1. |
double |
counter1()
This method returns the value of the field counter1. |
double |
counter2()
This method returns the value of the field counter2. |
double |
counter3()
This method returns the value of the field counter3. |
boolean |
equals(java.lang.Object form)
Two forms are equal if their type and all their fields (values) are equal. |
int |
hashCode()
This method generates a hash code for the form, overriding method java.lang.Object.hashCode. |
java.lang.Object |
object()
This method returns the value of the field object. |
java.lang.String |
string()
This method returns the value of the field string. |
java.lang.String |
toString()
This method creates a string from the Form. |
java.lang.String |
type()
This method returns the type of the Form. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String Empty
public static final java.lang.String String
public static final java.lang.String String1counter
public static final java.lang.String String2counters
public static final java.lang.String String3counters
public static final java.lang.String Form1counter
public static final java.lang.String Form2counters
public static final java.lang.String Form3counters
protected final java.lang.Class<? extends Form> thisclass
Constructor Detail |
---|
public Form()
public Form(java.lang.String str)
str
- The value of the field string.public Form(double count1)
count1
- The value of the field counter1.public Form(double count1, double count2)
count1
- The value of the field counter1.count2
- The value of the field counter2.public Form(double count1, double count2, double count3)
count1
- The value of the field counter1.count2
- The value of the field counter2.count3
- The value of the field counter3.public Form(java.lang.String str, double count1)
str
- The value of the field string.count1
- The value of the field counter1.public Form(java.lang.String str, double count1, double count2)
str
- The value of the field string.count1
- The value of the field counter1.count2
- The value of the field counter2.public Form(java.lang.String str, double count1, double count2, double count3)
str
- The value of the field string.count1
- The value of the field counter1.count2
- The value of the field counter2.count3
- The value of the field counter3.public Form(java.lang.Object O, java.lang.String Type)
O
- The value of field object.Type
- The type of the form.Method Detail |
---|
public java.lang.String type()
public java.lang.String string()
public double counter()
public double counter1()
public double counter2()
public double counter3()
public java.lang.Object object()
public Form changeString(java.lang.String str)
This method "changes" the value of field string. It returns a new Form that is the same as the original one (same type, same fields), but the field string is changed to str. If the Form does not contain a field string, then this method returns a clone of the original Form.
str
- The new value of field string.
public Form changeCounter1(java.lang.String val)
This method "changes" the value of field counter1. It returns a new Form that is the same as the original one (same type, same fields), but the field counter1 is changed to val. If the Form does not contain a field counter1, then this method returns a clone of the original Form.
val
- The new value of field counter1.
public Form changeCounter2(java.lang.String val)
This method "changes" the value of field counter2. It returns a new Form that is the same as the original one (same type, same fields), but the field counter2 is changed to val. If the Form does not contain a field counter2, then this method returns a clone of the original Form.
val
- The new value of field counter2.
public Form changeCounter3(java.lang.String val)
This method "changes" the value of field counter3. It returns a new Form that is the same as the original one (same type, same fields), but the field counter3 is changed to val. If the Form does not contain a field counter3, then this method returns a clone of the original Form.
val
- The new value of field counter3.
public Form changeObject(java.lang.Object o)
This method "changes" the value of field object. It returns a new Form that is the same as the original one (same type, same fields), but the field object is set to o. If the Form does not contain a field object, then this method returns a clone of the original Form.
o
- The new value of field object.
public boolean equals(java.lang.Object form)
equals
in class java.lang.Object
public Form clone()
clone
in class java.lang.Object
public java.lang.String toString()
This method creates a string from the Form. It overrides java.lang.Object.toString.
Depending on the type of the Form, the output can be an empty string (for type "empty"), the value of field string (for type "string"), a number (for type "1 counter"), a coma-separated list of numbers (for types involving more than one counters), a coma-separated list of a string and number(s) (for types involving both a string and counter(s)), or the value of object.tyString otherwise.
toString
in class java.lang.Object
public int hashCode()
This method generates a hash code for the form, overriding method java.lang.Object.hashCode. The hash code generated for a Form is the hash code generated by the method String.hashCode() for the String that is returned for this Form by method toString.
You may want to override this method, if you use it frequently with relatively simple forms.
Note that if two Forms are equal, then their hash code will also be equal, but not vice versa. For instance Form() and Form("") are not equal according the equals method, but both result in a hash code of 0.
hashCode
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |