public class ConstrainedFieldPosition extends Object
Constructor and Description |
---|
ConstrainedFieldPosition()
Initializes a CategoryFieldPosition.
|
Modifier and Type | Method and Description |
---|---|
void |
constrainClass(Class<?> classConstraint)
Sets a constraint on the field class.
|
void |
constrainField(Format.Field field)
Sets a constraint on the field.
|
void |
constrainFieldAndValue(Format.Field field,
Object fieldValue)
Deprecated.
This API is for technology preview and might be changed or removed in a future release.
|
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() |
public ConstrainedFieldPosition()
public void reset()
public void constrainField(Format.Field field)
FormattedValue.nextPosition(com.ibm.icu.text.ConstrainedFieldPosition)
, 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.
field
- The field to fix when iterating.public void constrainClass(Class<?> classConstraint)
FormattedValue.nextPosition(com.ibm.icu.text.ConstrainedFieldPosition)
, 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 }
classConstraint
- The field class to fix when iterating.@Deprecated public void constrainFieldAndValue(Format.Field field, Object fieldValue)
FormattedValue.nextPosition(com.ibm.icu.text.ConstrainedFieldPosition)
, positions are
skipped unless both the field and the field value are equal.
Any previously set constraints are cleared.
For example, to find the span a date interval corresponding to the first date:
ConstrainedFieldPosition cfpos; cfpos.constrainFieldAndValue(DateIntervalFormat.SpanField.DATE_INTERVAL_SPAN, 0); while (fmtval.nextPosition(cfpos)) { // handle the span of the first date in the date interval }
field
- The field to fix when iterating.fieldValue
- The field value to fix when iterating.public Format.Field getField()
public int getStart()
public int getLimit()
public Object getFieldValue()
public long getInt64IterationContext()
setInt64IterationContext(long)
.public void setInt64IterationContext(long context)
context
- The new iteration context.public void setState(Format.Field field, Object value, int start, int limit)
field
- The new field.value
- The new field value. Should be null if there is no value.start
- The new inclusive start index.limit
- The new exclusive end index.public boolean matchesField(Format.Field field, Object fieldValue)
field
- The field to test.fieldValue
- The field value to test. Should be null if there is no value.Copyright © 2016 Unicode, Inc. and others.