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 class
Holds a field value, together with the run range in which this value is valid.private static class
The object converter to use for filtering the keys in the map returned bygetAttributes()
.private static final class
The object converter to use for extractingFormattedCharacterIterator.Entry.value
in 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 theattributes
map.All fields associated to the text.private int
The 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 long
For cross-version compatibility.private int
The value to be returned bygetRunStart(…)
andgetRunLimit(…)
when the index value isvalidity
.private int
The value to be returned bygetRunStart(…)
andgetRunLimit(…)
when the index value isvalidity
.Fields inherited from class org.apache.sis.internal.util.SimpleCharacterIterator
lower, text, upper
Fields 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 void
addFieldLimit
(AttributedCharacterIterator.Attribute field, Object value, int start) Invoked byFormat
implementations when a field ended.(package private) final void
append
(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, ornull
if none.Returns the attributes defined on the current character.int
Returns the index of the first character following the run having all the same attributes than the current character.int
getRunLimit
(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.int
getRunLimit
(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.int
Returns the index of the first character of the run having all the same attributes than the current character.int
getRunStart
(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.int
getRunStart
(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 void
update
(AttributedCharacterIterator.Attribute attribute, Collection<FormattedCharacterIterator.Entry> entries) Ensures that thestart
,limit
andattributes
fields 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, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.text.CharacterIterator
clone, current, first, getBeginIndex, getEndIndex, getIndex, last, next, previous, setIndex
Methods inherited from interface java.lang.CharSequence
chars, codePoints, isEmpty
-
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
FormattedCharacterIterator
become 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 theattributes
map. 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 aStringBuilder
to be filled later.
-
-
Method Details
-
addFieldLimit
Invoked byFormat
implementations when a field ended. This method stores the given attribute value for the run ranging fromstart
inclusive 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
,limit
andattributes
fields 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 ifattribute
isnull
.
-
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:
getRunStart
in 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:
getRunStart
in 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:
getRunStart
in 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:
getRunLimit
in 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:
getRunLimit
in 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:
getRunLimit
in 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:
getAttributes
in interfaceAttributedCharacterIterator
-
getAttribute
Returns the value of the named attribute for the current character, ornull
if none.- Specified by:
getAttribute
in interfaceAttributedCharacterIterator
-
getAllAttributeKeys
Returns the keys of all attributes defined in the iterator text range.- Specified by:
getAllAttributeKeys
in interfaceAttributedCharacterIterator
-