FileDocCategorySizeDatePackage
FieldPosition.javaAPI DocAndroid 1.5 API5598Wed May 06 22:41:06 BST 2009java.text

FieldPosition

public class FieldPosition extends Object
Identifies fields in formatted strings. If a {@code 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 {@code FieldPosition} can be created by using the integer constants in the various format classes (for example {@code NumberFormat.INTEGER_FIELD}) or one of the fields of type {@code Format.Field}.

If more than one field information is needed, the method {@link NumberFormat#formatToCharacterIterator(Object)} should be used.

since
Android 1.0

Fields Summary
private int
myField
private int
beginIndex
private int
endIndex
private Format$Field
myAttribute
Constructors Summary
public FieldPosition(int field)
Constructs a new {@code FieldPosition} for the specified field.

param
field the field to identify.
since
Android 1.0

        myField = field;
    
public FieldPosition(Format$Field attribute)
Constructs a new {@code FieldPosition} for the specified {@code Field} attribute.

param
attribute the field attribute to identify.
since
Android 1.0

        myAttribute = attribute;
        myField = -1;
    
public FieldPosition(Format$Field attribute, int field)
Constructs a new {@code FieldPosition} for the specified {@code Field} attribute and field id.

param
attribute the field attribute to identify.
param
field the field to identify.
since
Android 1.0

        myAttribute = attribute;
        myField = field;
    
Methods Summary
voidclear()

        beginIndex = endIndex = 0;
    
public booleanequals(java.lang.Object object)
Compares the specified object to this field position and indicates if they are equal. In order to be equal, {@code object} must be an instance of {@code FieldPosition} with the same field, begin index and end index.

param
object the object to compare with this object.
return
{@code true} if the specified object is equal to this field position; {@code false} otherwise.
see
#hashCode
since
Android 1.0

        if (!(object instanceof FieldPosition)) {
            return false;
        }
        FieldPosition pos = (FieldPosition) object;
        return myField == pos.myField && myAttribute == pos.myAttribute
                && beginIndex == pos.beginIndex && endIndex == pos.endIndex;
    
public intgetBeginIndex()
Returns the index of the beginning of the field.

return
the first index of the field.
since
Android 1.0

        return beginIndex;
    
public intgetEndIndex()
Returns the index one past the end of the field.

return
one past the index of the last character in the field.
since
Android 1.0

        return endIndex;
    
public intgetField()
Returns the field which is being identified.

return
the field constant.
since
Android 1.0

        return myField;
    
public java.text.Format$FieldgetFieldAttribute()
Returns the attribute which is being identified.

return
the field.
since
Android 1.0

        return myAttribute;
    
public inthashCode()

        int attributeHash = (myAttribute == null) ? 0 : myAttribute.hashCode();
        return attributeHash + myField * 10 + beginIndex * 100 + endIndex;
    
public voidsetBeginIndex(int index)
Sets the index of the beginning of the field.

param
index the index of the first character in the field.
since
Android 1.0

        beginIndex = index;
    
public voidsetEndIndex(int index)
Sets the index of the end of the field.

param
index one past the index of the last character in the field.
since
Android 1.0

        endIndex = index;
    
public java.lang.StringtoString()
Returns the string representation of this field position.

return
the string representation of this field position.
since
Android 1.0

        return getClass().getName() + "[attribute=" + myAttribute + ", field=" //$NON-NLS-1$ //$NON-NLS-2$
                + myField + ", beginIndex=" + beginIndex + ", endIndex=" //$NON-NLS-1$ //$NON-NLS-2$
                + endIndex + "]"; //$NON-NLS-1$