hu.birot.OTKit.dataType
Class Form

java.lang.Object
  extended by hu.birot.OTKit.dataType.Form

public class Form
extends java.lang.Object

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

Empty

public static final java.lang.String Empty
String describing the type of an empty Form.

See Also:
Constant Field Values

String

public static final java.lang.String String
String describing the type of a Form with a string.

See Also:
Constant Field Values

String1counter

public static final java.lang.String String1counter
String describing the type of a Form with a string and 1 counter.

See Also:
Constant Field Values

String2counters

public static final java.lang.String String2counters
String describing the type of a Form with a string and 2 counters.

See Also:
Constant Field Values

String3counters

public static final java.lang.String String3counters
String describing the type of a Form with a string and 3 counters.

See Also:
Constant Field Values

Form1counter

public static final java.lang.String Form1counter
String describing the type of a Form with 1 counter.

See Also:
Constant Field Values

Form2counters

public static final java.lang.String Form2counters
String describing the type of a Form with 2 counters.

See Also:
Constant Field Values

Form3counters

public static final java.lang.String Form3counters
String describing the type of a Form with 3 counters.

See Also:
Constant Field Values

thisclass

protected final java.lang.Class<? extends Form> thisclass
Constructor Detail

Form

public Form()
This constructor creates an empty Form. Its fields are not instantiated. (In practice, they are set to default, such as empty string, counters being zero, etc. But it is not good practice to rely on that.). Type becomes "empty" (the value of the static field Empty).


Form

public Form(java.lang.String str)
This constructor defines a new Form, with the field string being set to str. Its type is "string".

Parameters:
str - The value of the field string.

Form

public Form(double count1)
This constructor defines a new Form, with the field counter1 being set to count1. Its type is "1 counter" (the value of Field Form1counter).

Parameters:
count1 - The value of the field counter1.

Form

public Form(double count1,
            double count2)
This constructor defines a new Form, with the field counter1 being set to count1 and counter2 to count2. Its type is "2 counters" (the value of the static field Form2counters).

Parameters:
count1 - The value of the field counter1.
count2 - The value of the field counter2.

Form

public 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. Its type is "3 counters" (the value of the static field Form3counters).

Parameters:
count1 - The value of the field counter1.
count2 - The value of the field counter2.
count3 - The value of the field counter3.

Form

public 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. Its type is "string + 1 counter".

Parameters:
str - The value of the field string.
count1 - The value of the field counter1.

Form

public 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. Its type is "string + 2 counters" (the value of the static field String2counters).

Parameters:
str - The value of the field string.
count1 - The value of the field counter1.
count2 - The value of the field counter2.

Form

public 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. Its type is "string + 3 counters" (the value of the static field String3counters).

Parameters:
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.

Form

public Form(java.lang.Object O,
            java.lang.String Type)
This constructor creates a Form with field object set to O. Its type is simultaneously set to Type.

Parameters:
O - The value of field object.
Type - The type of the form.
Method Detail

type

public java.lang.String type()
This method returns the type of the Form.


string

public java.lang.String string()
This method returns the value of the field string.


counter

public double counter()
This method returns the value of the field counter1.


counter1

public double counter1()
This method returns the value of the field counter1.


counter2

public double counter2()
This method returns the value of the field counter2.


counter3

public double counter3()
This method returns the value of the field counter3.


object

public java.lang.Object object()
This method returns the value of the field object.


changeString

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.

Parameters:
str - The new value of field string.
Returns:
A Form that is the same as the original one, but field string is str.

changeCounter1

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.

Parameters:
val - The new value of field counter1.
Returns:
A Form that is the same as the original one, but field counter1 is val.

changeCounter2

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.

Parameters:
val - The new value of field counter2.
Returns:
A Form that is the same as the original one, but field counter2 is val.

changeCounter3

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.

Parameters:
val - The new value of field counter3.
Returns:
A Form that is the same as the original one, but field counter3 is val.

changeObject

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.

Parameters:
o - The new value of field object.
Returns:
A Form that is the same as the original one, but field object is set to o.

equals

public boolean equals(java.lang.Object form)
Two forms are equal if their type and all their fields (values) are equal. This method overrides java.lang.Object.equals. If field object is used, then the users must make sure they have defined the equality of those objects.

Overrides:
equals in class java.lang.Object
Returns:
true if their types and all their fields are equal; otherwise false.

clone

public Form clone()
This method creates a clone of the Form. The clone has the same type as the original one, and the fields relevant for that type are also set identical. This method overrides java.lang.Object.clone.

Overrides:
clone in class java.lang.Object

toString

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.

Overrides:
toString in class java.lang.Object

hashCode

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.

Overrides:
hashCode in class java.lang.Object
Returns:
An integer that can be used as the hash code of the Form.