ConstrainedFieldPosition
open class ConstrainedFieldPosition
kotlin.Any | |
↳ | 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.
Summary
Public constructors | |
---|---|
Initializes a CategoryFieldPosition. |
Public methods | |
---|---|
open Unit |
constrainClass(classConstraint: Class<*>!) Sets a constraint on the field class. |
open Unit |
constrainField(field: Format.Field!) Sets a constraint on the field. |
open Format.Field! |
getField() Gets the field for the current position. |
open Any! |
Gets the value associated with the current field position. |
open Long |
Gets an int64 that FormattedValue implementations may use for storage. |
open Int |
getLimit() Gets the EXCLUSIVE end index stored for the current position. |
open Int |
getStart() Gets the INCLUSIVE start index for the current position. |
open Boolean |
matchesField(field: Format.Field!, fieldValue: Any!) Determines whether a given field and value should be included given the constraints. |
open Unit |
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. |
open Unit |
setInt64IterationContext(context: Long) Sets an int64 that FormattedValue implementations may use for storage. |
open Unit |
setState(field: Format.Field!, value: Any!, start: Int, limit: Int) Sets new values for the primary public getters. |
open String |
toString() Returns a string representation of the object. |
Public constructors
ConstrainedFieldPosition
ConstrainedFieldPosition()
Initializes a CategoryFieldPosition. By default, the CategoryFieldPosition has no iteration constraints.
Public methods
constrainClass
open fun constrainClass(classConstraint: Class<*>!): Unit
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. |
constrainField
open fun constrainField(field: Format.Field!): Unit
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. |
getField
open fun getField(): Format.Field!
Gets the field for the current position. The return value is well-defined and non-null only after FormattedValue#nextPosition returns true.
Return | |
---|---|
Format.Field! |
The field saved in the instance. See above for null conditions. |
getFieldValue
open fun getFieldValue(): Any!
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.
Return | |
---|---|
Any! |
The value for the current position. Might be null. |
getInt64IterationContext
open fun getInt64IterationContext(): Long
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.
Return | |
---|---|
Long |
The current iteration context from setInt64IterationContext . |
getLimit
open fun getLimit(): Int
Gets the EXCLUSIVE end index stored for the current position. The return value is well-defined only after FormattedValue#nextPosition returns true.
Return | |
---|---|
Int |
The end index saved in the instance. |
getStart
open fun getStart(): Int
Gets the INCLUSIVE start index for the current position. The return value is well-defined only after FormattedValue#nextPosition returns true.
Return | |
---|---|
Int |
The start index saved in the instance. |
matchesField
open fun matchesField(
field: Format.Field!,
fieldValue: Any!
): Boolean
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 |
Any!: The field value to test. Should be null if there is no value. |
Return | |
---|---|
Boolean |
Whether the field should be included given the constraints. |
reset
open fun reset(): Unit
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.
setInt64IterationContext
open fun setInt64IterationContext(context: Long): Unit
Sets an int64 that FormattedValue implementations may use for storage. Intended to be used by FormattedValue implementations.
Parameters | |
---|---|
context |
Long: The new iteration context. |
setState
open fun setState(
field: Format.Field!,
value: Any!,
start: Int,
limit: Int
): Unit
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 |
Any!: 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. |
toString
open fun toString(): String
Returns a string representation of the object.
Return | |
---|---|
String |
a string representation of the object. |