# Print output for @column tags ?>
public
class
ConstrainedFieldPosition
extends Object
java.lang.Object | |
↳ | android.icu.text.ConstrainedFieldPosition |
Represents a span of a string containing a given field. This class differs from FieldPosition in the following ways: 1. It has information on the field category. 2. It allows you to set constraints to use when iterating over field positions. 3. It is used for the newer FormattedValue APIs.
Public constructors | |
---|---|
ConstrainedFieldPosition()
Initializes a CategoryFieldPosition. |
Public methods | |
---|---|
void
|
constrainClass(Class<?> classConstraint)
Sets a constraint on the field class. |
void
|
constrainField(Format.Field field)
Sets a constraint on the field. |
Format.Field
|
getField()
Gets the field for the current position. |
Object
|
getFieldValue()
Gets the value associated with the current field position. |
long
|
getInt64IterationContext()
Gets an int64 that FormattedValue implementations may use for storage. |
int
|
getLimit()
Gets the EXCLUSIVE end index stored for the current position. |
int
|
getStart()
Gets the INCLUSIVE start index for the current position. |
boolean
|
matchesField(Format.Field field, Object fieldValue)
Determines whether a given field and value should be included given the constraints. |
void
|
reset()
Resets this ConstrainedFieldPosition to its initial state, as if it were newly created: - Removes any constraints that may have been set on the instance. |
void
|
setInt64IterationContext(long context)
Sets an int64 that FormattedValue implementations may use for storage. |
void
|
setState(Format.Field field, Object value, int start, int limit)
Sets new values for the primary public getters. |
String
|
toString()
Returns a string representation of the object. |
Inherited methods | |
---|---|
public ConstrainedFieldPosition ()
Initializes a CategoryFieldPosition. By default, the CategoryFieldPosition has no iteration constraints.
public void constrainClass (Class<?> classConstraint)
Sets a constraint on the field class.
When this instance of ConstrainedFieldPosition is passed to FormattedValue#nextPosition
, positions are
skipped unless the field is an instance of the class constraint, including subclasses.
Any previously set constraints are cleared.
For example, to loop over only the number-related fields:
ConstrainedFieldPosition cfpos; cfpos.constrainClass(NumberFormat.Field.class); while (fmtval.nextPosition(cfpos)) { // handle the number-related field position }
Parameters | |
---|---|
classConstraint |
Class : The field class to fix when iterating. |
public void constrainField (Format.Field field)
Sets a constraint on the field.
When this instance of ConstrainedFieldPosition is passed to FormattedValue#nextPosition
, positions are
skipped unless they have the given field.
Any previously set constraints are cleared.
For example, to loop over all grouping separators:
ConstrainedFieldPosition cfpos; cfpos.constrainField(NumberFormat.Field.GROUPING_SEPARATOR); while (fmtval.nextPosition(cfpos)) { // handle the grouping separator position }Changing the constraint while in the middle of iterating over a FormattedValue does not generally have well-defined behavior.
Parameters | |
---|---|
field |
Format.Field : The field to fix when iterating. |
public Format.Field getField ()
Gets the field for the current position. The return value is well-defined and non-null only after FormattedValue#nextPosition returns TRUE.
Returns | |
---|---|
Format.Field |
The field saved in the instance. See above for null conditions. |
public Object getFieldValue ()
Gets the value associated with the current field position. The field value is often not set. The return value is well-defined only after FormattedValue#nextPosition returns TRUE.
Returns | |
---|---|
Object |
The value for the current position. Might be null. |
public long getInt64IterationContext ()
Gets an int64 that FormattedValue implementations may use for storage. The initial value is zero. Users of FormattedValue should not need to call this method.
Returns | |
---|---|
long |
The current iteration context from setInt64IterationContext(long) . |
public int getLimit ()
Gets the EXCLUSIVE end index stored for the current position. The return value is well-defined only after FormattedValue#nextPosition returns TRUE.
Returns | |
---|---|
int |
The end index saved in the instance. |
public int getStart ()
Gets the INCLUSIVE start index for the current position. The return value is well-defined only after FormattedValue#nextPosition returns TRUE.
Returns | |
---|---|
int |
The start index saved in the instance. |
public boolean matchesField (Format.Field field, Object fieldValue)
Determines whether a given field and value should be included given the constraints. Intended to be used by FormattedValue implementations.
Parameters | |
---|---|
field |
Format.Field : The field to test. |
fieldValue |
Object : The field value to test. Should be null if there is no value. |
Returns | |
---|---|
boolean |
Whether the field should be included given the constraints. |
public void reset ()
Resets this ConstrainedFieldPosition to its initial state, as if it were newly created: - Removes any constraints that may have been set on the instance. - Resets the iteration position.
public void setInt64IterationContext (long context)
Sets an int64 that FormattedValue implementations may use for storage. Intended to be used by FormattedValue implementations.
Parameters | |
---|---|
context |
long : The new iteration context. |
public void setState (Format.Field field, Object value, int start, int limit)
Sets new values for the primary public getters. Intended to be used by FormattedValue implementations. It is up to the implementation to ensure that the user-requested constraints are satisfied. This method does not check!
Parameters | |
---|---|
field |
Format.Field : The new field. |
value |
Object : The new field value. Should be null if there is no value. |
start |
int : The new inclusive start index. |
limit |
int : The new exclusive end index. |
public String toString ()
Returns a string representation of the object. In general, the
toString
method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString
method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@
', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Returns | |
---|---|
String |
a string representation of the object. |