Package org.apache.sis.measure
Class FormattedCharacterIterator
java.lang.Object
org.apache.sis.internal.util.SimpleCharacterIterator
org.apache.sis.measure.FormattedCharacterIterator
- All Implemented Interfaces:
Serializable,CharSequence,Cloneable,AttributedCharacterIterator,CharacterIterator
final class FormattedCharacterIterator
extends SimpleCharacterIterator
implements AttributedCharacterIterator
The attributed character iterator to be returned by
Format
implementations in the org.apache.sis.measure package.
Implementation assumption
EverygetRunStart(…) and getRunLimit(…) methods defined in this class check
only for attribute existence, ignoring the actual attribute value. This is a departure from
the AttributedCharacterIterator contract, but should be invisible to the
users if there are no juxtaposed fields with the same attribute value (which is usually the
case). A violation occurs if different fields are formatted without separator. For example
if an angle is formatted as "DDMMSS" without any field separator, then we have 3 juxtaposed
integer fields. If those fields have the same value, then the whole "DDMMSS" text should be
seen as a single run according the AttributedCharacterIterator contract, while they
will still been seen as 3 separated fields by this implementation.- Since:
- 0.3
- Version:
- 0.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classHolds a field value, together with the run range in which this value is valid.private static classThe object converter to use for filtering the keys in the map returned bygetAttributes().private static final classThe object converter to use for extractingFormattedCharacterIterator.Entry.valuein the map returned bygetAttributes().Nested classes/interfaces inherited from interface java.text.AttributedCharacterIterator
AttributedCharacterIterator.Attribute -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Set<AttributedCharacterIterator.Attribute>An unmodifiable view over the keys of theattributesmap.All fields associated to the text.private intThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity.The attribute given in the last call to agetRunStart(…)orgetRunLimit(…)method.private static final longFor cross-version compatibility.private intThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity.private intThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity.Fields inherited from class org.apache.sis.internal.util.SimpleCharacterIterator
lower, text, upperFields inherited from interface java.text.CharacterIterator
DONE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new character iterator for the given character sequence. -
Method Summary
Modifier and TypeMethodDescription(package private) final voidaddFieldLimit(AttributedCharacterIterator.Attribute field, Object value, int start) Invoked byFormatimplementations when a field ended.(package private) final voidappend(AttributedCharacterIterator it, StringBuffer toAppendTo) Appends all characters and attributes from the given iterator.entries(Set<? extends AttributedCharacterIterator.Attribute> requested) Returns the entries for the given attributes.Returns the keys of all attributes defined in the iterator text range.Returns the value of the named attribute for the current character, ornullif none.Returns the attributes defined on the current character.intReturns the index of the first character following the run having all the same attributes than the current character.intgetRunLimit(AttributedCharacterIterator.Attribute attribute) Returns the index of the first character following the run having the same "value" for the given attribute than the current character.intgetRunLimit(Set<? extends AttributedCharacterIterator.Attribute> attributes) Returns the index of the first character following the run having the same "values" for the given attributes than the current character.intReturns the index of the first character of the run having all the same attributes than the current character.intgetRunStart(AttributedCharacterIterator.Attribute attribute) Returns the index of the first character of the run having the same "value" for the given attribute than the current character.intgetRunStart(Set<? extends AttributedCharacterIterator.Attribute> attributes) Returns the index of the first character of the run having the same "values" for the given attributes than the current character.private voidupdate(AttributedCharacterIterator.Attribute attribute, Collection<FormattedCharacterIterator.Entry> entries) Ensures that thestart,limitandattributesfields are valid for the current index position and the given attribute.Methods inherited from class org.apache.sis.internal.util.SimpleCharacterIterator
charAt, clone, current, first, getBeginIndex, getEndIndex, getIndex, last, length, next, previous, setIndex, subSequence, toStringMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.text.CharacterIterator
clone, current, first, getBeginIndex, getEndIndex, getIndex, last, next, previous, setIndexMethods inherited from interface java.lang.CharSequence
chars, codePoints
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDFor cross-version compatibility.- See Also:
-
attributes
private final Map<AttributedCharacterIterator.Attribute,FormattedCharacterIterator.Entry> attributesAll fields associated to the text.This map shall not be modified after this
FormattedCharacterIteratorbecome visible to the user. If this map could be modified, then we would need to override theSimpleCharacterIterator.clone()method in order to clone this map too. -
attributeKeys
An unmodifiable view over the keys of theattributesmap. This view is created when first needed.- See Also:
-
runAttribute
-
start
private transient int startThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity. Those values are updated when needed by theupdate(Attribute, Collection)method. -
limit
private transient int limitThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity. Those values are updated when needed by theupdate(Attribute, Collection)method. -
validity
private transient int validityThe value to be returned bygetRunStart(…)andgetRunLimit(…)when the index value isvalidity. Those values are updated when needed by theupdate(Attribute, Collection)method.
-
-
Constructor Details
-
FormattedCharacterIterator
FormattedCharacterIterator(CharSequence text) Creates a new character iterator for the given character sequence.- Parameters:
text- the formatted text. Can be aStringBuilderto be filled later.
-
-
Method Details
-
addFieldLimit
Invoked byFormatimplementations when a field ended. This method stores the given attribute value for the run ranging fromstartinclusive to the current SimpleCharacterIterator.text length, exclusive. -
append
Appends all characters and attributes from the given iterator.- Parameters:
toAppendTo- shall be the same instance thanSimpleCharacterIterator.text.
-
update
private void update(AttributedCharacterIterator.Attribute attribute, Collection<FormattedCharacterIterator.Entry> entries) Ensures that thestart,limitandattributesfields are valid for the current index position and the given attribute.- Parameters:
attribute- the attribute which shall have the same value in the run range.entries- the entries on which to iterate for computing the run range. Mandatory ifattributeisnull.
-
getRunStart
public int getRunStart()Returns the index of the first character of the run having all the same attributes than the current character. See this class javadoc for a note about which attributes are considered equal.- Specified by:
getRunStartin interfaceAttributedCharacterIterator
-
getRunStart
Returns the index of the first character of the run having the same "value" for the given attribute than the current character. See this class javadoc for a note about which attribute "values" are considered equal.- Specified by:
getRunStartin interfaceAttributedCharacterIterator
-
getRunStart
Returns the index of the first character of the run having the same "values" for the given attributes than the current character. See this class javadoc for a note about which attribute "values" are considered equal.- Specified by:
getRunStartin interfaceAttributedCharacterIterator
-
getRunLimit
public int getRunLimit()Returns the index of the first character following the run having all the same attributes than the current character. See this class javadoc for a note about which attributes are considered equal.- Specified by:
getRunLimitin interfaceAttributedCharacterIterator
-
getRunLimit
Returns the index of the first character following the run having the same "value" for the given attribute than the current character. See this class javadoc for a note about which attribute "values" are considered equal.- Specified by:
getRunLimitin interfaceAttributedCharacterIterator
-
getRunLimit
Returns the index of the first character following the run having the same "values" for the given attributes than the current character. See this class javadoc for a note about which attribute "values" are considered equal.- Specified by:
getRunLimitin interfaceAttributedCharacterIterator
-
entries
private Collection<FormattedCharacterIterator.Entry> entries(Set<? extends AttributedCharacterIterator.Attribute> requested) Returns the entries for the given attributes. This is a helper method for thegetRunStart(Set)andgetRunLimit(Set)methods. -
getAttributes
Returns the attributes defined on the current character.- Specified by:
getAttributesin interfaceAttributedCharacterIterator
-
getAttribute
Returns the value of the named attribute for the current character, ornullif none.- Specified by:
getAttributein interfaceAttributedCharacterIterator
-
getAllAttributeKeys
Returns the keys of all attributes defined in the iterator text range.- Specified by:
getAllAttributeKeysin interfaceAttributedCharacterIterator
-