Top Description Inners Fields Constructors Methods
com.ibm.icu.text

public Class ConstrainedFieldPosition

extends Object
Class Inheritance
Imports
java.text.Format.Field, java.util.Objects

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.
Author
sffc
ICU Status
Stable since ICU 64.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
ConstrainedFieldPosition.ConstraintType

Represents the type of constraint for ConstrainedFieldPosition.

Field Summary

Modifier and TypeField and Description
private Class<?>
private ConstrainedFieldPosition.ConstraintType
private long
private Format.Field
private int
private int
private Object

Constructor Summary

AccessConstructor and Description
public
ConstrainedFieldPosition()

Initializes a CategoryFieldPosition.

Method Summary

Modifier and TypeMethod and Description
public void
constrainClass(Class<?>
The field class to fix when iterating.
classConstraint
)

Sets a constraint on the field class.

public void
constrainField(Format.Field
The field to fix when iterating.
field
)

Sets a constraint on the field.

public void
constrainFieldAndValue(Format.Field
The field to fix when iterating.
field
,
Object
The field value to fix when iterating.
fieldValue
)

Deprecated This API is for technology preview and might be changed or removed in a future release.
Sets a constraint on field and field value.
public Format.Field

Returns:

The field saved in the instance. See above for null conditions.
getField
()

Gets the field for the current position.

public Object

Returns:

The value for the current position. Might be null.
getFieldValue
()

Gets the value associated with the current field position.

public long

Returns:

The current iteration context from setInt64IterationContext.
getInt64IterationContext
()

Gets an int64 that FormattedValue implementations may use for storage.

public int

Returns:

The end index saved in the instance.
getLimit
()

Gets the EXCLUSIVE end index stored for the current position.

public int

Returns:

The start index saved in the instance.
getStart
()

Gets the INCLUSIVE start index for the current position.

public boolean

Returns:

Whether the field should be included given the constraints.
matchesField
(Format.Field
The field to test.
field
,
Object
The field value to test. Should be null if there is no value.
fieldValue
)

Determines whether a given field and value 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.

public void
setInt64IterationContext(long
The new iteration context.
context
)

Sets an int64 that FormattedValue implementations may use for storage.

public void
setState(Format.Field
The new field.
field
,
Object
The new field value. Should be null if there is no value.
value
,
int
The new inclusive start index.
start
,
int
The new exclusive end index.
limit
)

Sets new values for the primary public getters.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

fClassConstraintback to summary
private Class<?> fClassConstraint
fConstraintback to summary
private ConstrainedFieldPosition.ConstraintType fConstraint
fContextback to summary
private long fContext
fFieldback to summary
private Format.Field fField
fLimitback to summary
private int fLimit
fStartback to summary
private int fStart
fValueback to summary
private Object fValue

Constructor Detail

ConstrainedFieldPositionback to summary
public ConstrainedFieldPosition()

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

ICU Status
Stable since ICU 64.

Method Detail

constrainClassback to summary
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.

ICU Status
Stable since ICU 64.
constrainFieldback to summary
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.

ICU Status
Stable since ICU 64.
constrainFieldAndValueback to summary
public void constrainFieldAndValue(Format.Field field, Object fieldValue)

Deprecated

This API is for technology preview and might be changed or removed in a future release.

Sets a constraint on field and field value. When this instance of ConstrainedFieldPosition is passed to FormattedValue#nextPosition, 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
}
Parameters
field:Format.Field

The field to fix when iterating.

fieldValue:Object

The field value to fix when iterating.

Annotations
@Deprecated
ICU Status
Internal ICU component: 64 technology preview
getFieldback to summary
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.

ICU Status
Stable since ICU 64.
getFieldValueback to summary
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.

ICU Status
Stable since ICU 64.
getInt64IterationContextback to summary
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.

ICU Status
Stable since ICU 64.
getLimitback to summary
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.

ICU Status
Stable since ICU 64.
getStartback to summary
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.

ICU Status
Stable since ICU 64.
matchesFieldback to summary
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.

ICU Status
Stable since ICU 64.
resetback to summary
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.

ICU Status
Stable since ICU 64.
setInt64IterationContextback to summary
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.

ICU Status
Stable since ICU 64.
setStateback to summary
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.

ICU Status
Stable since ICU 64.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
ICU Status
Stable since ICU 64.
com.ibm.icu.text back to summary

private final Enum ConstrainedFieldPosition.ConstraintType

extends Enum<ConstrainedFieldPosition.ConstraintType>
Class Inheritance

Represents the type of constraint for ConstrainedFieldPosition. Constraints are used to control the behavior of iteration in FormattedValue.

Field Summary

Modifier and TypeField and Description
public static final ConstrainedFieldPosition.ConstraintType
CLASS

Represents that the field class is constrained.

public static final ConstrainedFieldPosition.ConstraintType
FIELD

Represents that the field is constrained.

public static final ConstrainedFieldPosition.ConstraintType
NONE

Represents the lack of a constraint.

public static final ConstrainedFieldPosition.ConstraintType
VALUE

Represents that the field value is constrained.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static ConstrainedFieldPosition.ConstraintType
public static ConstrainedFieldPosition.ConstraintType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CLASSback to summary
public static final ConstrainedFieldPosition.ConstraintType CLASS

Represents that the field class is constrained. This is the value of fConstraint after constrainClass is called. FormattedValue implementations should not change the field class when this constraint is active.

FIELDback to summary
public static final ConstrainedFieldPosition.ConstraintType FIELD

Represents that the field is constrained. This is the value of fConstraint after constrainField is called. FormattedValue implementations should not change the field when this constraint is active.

NONEback to summary
public static final ConstrainedFieldPosition.ConstraintType NONE

Represents the lack of a constraint. This is the value of fConstraint if no "constrain" methods were called.

VALUEback to summary
public static final ConstrainedFieldPosition.ConstraintType VALUE

Represents that the field value is constrained. This is the value of fConstraint after constrainField is called. FormattedValue implementations should not change the field or value with this constraint.

Constructor Detail

ConstraintTypeback to summary
private ConstraintType()

Method Detail

valueOfback to summary
public static ConstrainedFieldPosition.ConstraintType valueOf(String name)
valuesback to summary
public static ConstrainedFieldPosition.ConstraintType[] values()