Package java.text
Class FieldPosition
java.lang.Object
java.text.FieldPosition
public class FieldPosition extends Object
Identifies fields in formatted strings. If a
FieldPosition is passed
to the format method with such a parameter, then the indices will be set to
the start and end indices of the field in the formatted string.
A FieldPosition can be created by using the integer constants in the
various format classes (for example NumberFormat.INTEGER_FIELD) or
one of the fields of type Format.Field.
If more than one field information is needed, the method
Format.formatToCharacterIterator(Object) should be used.
-
Constructor Summary
Constructors Constructor Description FieldPosition(int field)Constructs a newFieldPositionfor the specified field.FieldPosition(Format.Field attribute)Constructs a newFieldPositionfor the specifiedFieldattribute.FieldPosition(Format.Field attribute, int field)Constructs a newFieldPositionfor the specifiedFieldattribute and field id. -
Method Summary
Modifier and Type Method Description booleanequals(Object object)Compares the specified object to this field position and indicates if they are equal.intgetBeginIndex()Returns the index of the beginning of the field.intgetEndIndex()Returns the index one past the end of the field.intgetField()Returns the field which is being identified.Format.FieldgetFieldAttribute()Returns the attribute which is being identified.inthashCode()Returns an integer hash code for this object.voidsetBeginIndex(int index)Sets the index of the beginning of the field.voidsetEndIndex(int index)Sets the index of the end of the field.StringtoString()Returns the string representation of this field position.
-
Constructor Details
-
FieldPosition
public FieldPosition(int field)Constructs a newFieldPositionfor the specified field.- Parameters:
field- the field to identify.
-
FieldPosition
Constructs a newFieldPositionfor the specifiedFieldattribute.- Parameters:
attribute- the field attribute to identify.
-
FieldPosition
Constructs a newFieldPositionfor the specifiedFieldattribute and field id.- Parameters:
attribute- the field attribute to identify.field- the field to identify.
-
-
Method Details
-
equals
Compares the specified object to this field position and indicates if they are equal. In order to be equal,objectmust be an instance ofFieldPositionwith the same field, begin index and end index.- Overrides:
equalsin classObject- Parameters:
object- the object to compare with this object.- Returns:
trueif the specified object is equal to this field position;falseotherwise.- See Also:
hashCode()
-
getBeginIndex
public int getBeginIndex()Returns the index of the beginning of the field.- Returns:
- the first index of the field.
-
getEndIndex
public int getEndIndex()Returns the index one past the end of the field.- Returns:
- one past the index of the last character in the field.
-
getField
public int getField()Returns the field which is being identified.- Returns:
- the field constant.
-
getFieldAttribute
Returns the attribute which is being identified.- Returns:
- the field.
-
hashCode
public int hashCode()Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually override both methods or neither method.Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
setBeginIndex
public void setBeginIndex(int index)Sets the index of the beginning of the field.- Parameters:
index- the index of the first character in the field.
-
setEndIndex
public void setEndIndex(int index)Sets the index of the end of the field.- Parameters:
index- one past the index of the last character in the field.
-
toString
Returns the string representation of this field position.
-