Added in API level 31

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

Sets a constraint on the field.

open Format.Field!

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

Gets the EXCLUSIVE end index stored for the current position.

open Int

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

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

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

Returns a string representation of the object.

Public constructors

ConstrainedFieldPosition

Added in API level 31
ConstrainedFieldPosition()

Initializes a CategoryFieldPosition. By default, the CategoryFieldPosition has no iteration constraints.

Public methods

constrainClass

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
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

Added in API level 31
open fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.