public class ConstrainedFieldPosition extends Object
| 构造器 | 说明 |
|---|---|
ConstrainedFieldPosition() |
Initializes a CategoryFieldPosition.
|
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
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.
|
public ConstrainedFieldPosition()
public void reset()
public void constrainField(Format.Field field)
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.field - The field to fix when iterating.public void constrainClass(Class<?> classConstraint)
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
}
classConstraint - The field class 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.public String toString()
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())