APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.text

public Class FieldPosition

extends Object
Class Inheritance
Known Direct Subclasses
java.text.DontCareFieldPosition
Imports
java.util.Objects

FieldPosition is a simple class used by Format and its subclasses to identify fields in formatted output. Fields can be identified in two ways:

FieldPosition keeps track of the position of the field within the formatted output with two indices: the index of the first character of the field and the index of the last character of the field.

One version of the format method in the various Format classes requires a FieldPosition object as an argument. You use this format method to perform partial formatting or to get information about the formatted output (such as the position of a field).

If you are interested in the positions of all attributes in the formatted string use the Format method formatToCharacterIterator.

Author
Mark Davis
Since
1.1
See Also
java.text.Format

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
FieldPosition.Delegate

An implementation of FieldDelegate that will adjust the begin/end of the FieldPosition if the arguments match the field of the FieldPosition.

Field Summary

Modifier and TypeField and Description
private Format.Field
attribute

Desired field this FieldPosition is for.

pack-priv int
beginIndex

Output: Start offset of field in text.

pack-priv int
endIndex

Output: End offset of field in text.

pack-priv int
field

Input: Desired field to determine start and end offsets for.

Constructor Summary

AccessConstructor and Description
public
FieldPosition(int
the field identifier
field
)

Creates a FieldPosition object for the given field.

public
FieldPosition(Format.Field
Format.Field constant identifying a field
attribute
)

Creates a FieldPosition object for the given field constant.

public
FieldPosition(Format.Field
Format.Field constant identifying a field
attribute
,
int
integer constant identifying a field
fieldID
)

Creates a FieldPosition object for the given field.

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Overrides equals

public int

Returns:

the begin index
getBeginIndex
()

Retrieves the index of the first character in the requested field.

public int

Returns:

the end index
getEndIndex
()

Retrieves the index of the character following the last character in the requested field.

public int

Returns:

the field identifier
getField
()

Retrieves the field identifier.

public Format.Field

Returns:

Identifier for the field
getFieldAttribute
()

Returns the field identifier as an attribute constant from one of the Field subclasses.

pack-priv Format.FieldDelegate
getFieldDelegate()

Returns a Format.FieldDelegate instance that is associated with the FieldPosition.

public int

Returns:

a hash code for this FieldPosition
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this FieldPosition.

private boolean
matchesField(Format.Field attribute)

Return true if the receiver wants a Format.Field value and attribute is equal to it.

private boolean
matchesField(Format.Field attribute, int field)

Return true if the receiver wants a Format.Field value and attribute is equal to it, or true if the receiver represents an integer constant and field equals it.

public void
setBeginIndex(int
the begin index
bi
)

Sets the begin index.

public void
setEndIndex(int
the end index
ei
)

Sets the end index.

public String

Returns:

a string representation of this object
toString
()

Overrides java.lang.Object.toString.

Return a string representation of this FieldPosition.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

attributeback to summary
private Format.Field attribute

Desired field this FieldPosition is for.

beginIndexback to summary
pack-priv int beginIndex

Output: Start offset of field in text. If the field does not occur in the text, 0 is returned.

endIndexback to summary
pack-priv int endIndex

Output: End offset of field in text. If the field does not occur in the text, 0 is returned.

fieldback to summary
pack-priv int field

Input: Desired field to determine start and end offsets for. The meaning depends on the subclass of Format.

Constructor Detail

FieldPositionback to summary
public FieldPosition(int field)

Creates a FieldPosition object for the given field. Fields are identified by constants, whose names typically end with _FIELD, in the various subclasses of Format.

Parameters
field:int

the field identifier

See Also
java.text.NumberFormat#INTEGER_FIELD, java.text.NumberFormat#FRACTION_FIELD, java.text.DateFormat#YEAR_FIELD, java.text.DateFormat#MONTH_FIELD
FieldPositionback to summary
public FieldPosition(Format.Field attribute)

Creates a FieldPosition object for the given field constant. Fields are identified by constants defined in the various Format subclasses. This is equivalent to calling new FieldPosition(attribute, -1).

Parameters
attribute:Format.Field

Format.Field constant identifying a field

Since
1.4
FieldPositionback to summary
public FieldPosition(Format.Field attribute, int fieldID)

Creates a FieldPosition object for the given field. The field is identified by an attribute constant from one of the Field subclasses as well as an integer field ID defined by the Format subclasses. Format subclasses that are aware of Field should give precedence to attribute and ignore fieldID if attribute is not null. However, older Format subclasses may not be aware of Field and rely on fieldID. If the field has no corresponding integer constant, fieldID should be -1.

Parameters
attribute:Format.Field

Format.Field constant identifying a field

fieldID:int

integer constant identifying a field

Since
1.4

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Overrides equals

Annotations
@Override
getBeginIndexback to summary
public int getBeginIndex()

Retrieves the index of the first character in the requested field.

Returns:int

the begin index

getEndIndexback to summary
public int getEndIndex()

Retrieves the index of the character following the last character in the requested field.

Returns:int

the end index

getFieldback to summary
public int getField()

Retrieves the field identifier.

Returns:int

the field identifier

getFieldAttributeback to summary
public Format.Field getFieldAttribute()

Returns the field identifier as an attribute constant from one of the Field subclasses. May return null if the field is specified only by an integer field ID.

Returns:Format.Field

Identifier for the field

Since
1.4
getFieldDelegateback to summary
pack-priv Format.FieldDelegate getFieldDelegate()

Returns a Format.FieldDelegate instance that is associated with the FieldPosition. When the delegate is notified of the same field the FieldPosition is associated with, the begin/end will be adjusted.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this FieldPosition.

Returns:int

a hash code for this FieldPosition

Annotations
@Override
matchesFieldback to summary
private boolean matchesField(Format.Field attribute)

Return true if the receiver wants a Format.Field value and attribute is equal to it.

matchesFieldback to summary
private boolean matchesField(Format.Field attribute, int field)

Return true if the receiver wants a Format.Field value and attribute is equal to it, or true if the receiver represents an integer constant and field equals it.

setBeginIndexback to summary
public void setBeginIndex(int bi)

Sets the begin index. For use by subclasses of Format.

Parameters
bi:int

the begin index

Since
1.2
setEndIndexback to summary
public void setEndIndex(int ei)

Sets the end index. For use by subclasses of Format.

Parameters
ei:int

the end index

Since
1.2
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Return a string representation of this FieldPosition.

Returns:String

a string representation of this object

java.text back to summary

private Class FieldPosition.Delegate

extends Object
implements FieldDelegate
Class Inheritance
All Implemented Interfaces
java.text.Format.FieldDelegate

An implementation of FieldDelegate that will adjust the begin/end of the FieldPosition if the arguments match the field of the FieldPosition.

Field Summary

Modifier and TypeField and Description
private boolean
encounteredField

Indicates whether the field has been encountered before.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
formatted(Format.Field attr, Object value, int start, int end, Format.StringBuf buffer)

Implements java.text.Format.FieldDelegate.formatted.

Notified when a particular region of the String is formatted.

public void
formatted(int fieldID, Format.Field attr, Object value, int start, int end, Format.StringBuf buffer)

Implements java.text.Format.FieldDelegate.formatted.

Notified when a particular region of the String is formatted.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

encounteredFieldback to summary
private boolean encounteredField

Indicates whether the field has been encountered before. If this is true, and formatted is invoked, the begin/end are not updated.

Constructor Detail

Delegateback to summary
private Delegate()

Method Detail

formattedback to summary
public void formatted(Format.Field attr, Object value, int start, int end, Format.StringBuf buffer)

Implements java.text.Format.FieldDelegate.formatted.

Doc from java.text.Format.FieldDelegate.formatted.

Notified when a particular region of the String is formatted. This method will be invoked if there is no corresponding integer field id matching attr.

formattedback to summary
public void formatted(int fieldID, Format.Field attr, Object value, int start, int end, Format.StringBuf buffer)

Implements java.text.Format.FieldDelegate.formatted.

Doc from java.text.Format.FieldDelegate.formatted.

Notified when a particular region of the String is formatted.