/** * Returns the value of the named attribute for the current character, or {@code null} if none. */ @Override public Object getAttribute(final Attribute attribute) { final int index = getIndex(); for (Entry e = attributes.get(attribute); e != null; e = e.previous) { if (index >= e.start && index < e.limit) { return e.value; } } return null; }
/** * 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. */ @Override public int getRunLimit(final Set<? extends Attribute> attributes) { update(null, entries(attributes)); return limit; }
/** * Tests an iteration without attribute. */ @Test public void testWithoutAttribute() { final String text = LATITUDE_STRING; final FormattedCharacterIterator it = new FormattedCharacterIterator(text); assertTrue(it.getAllAttributeKeys().isEmpty()); assertEquals(text, it.toString()); int i = 0; for (char c=it.first(); c!=DONE; c=it.next()) { assertEquals(text.charAt(i), c); assertEquals(it .charAt(i), c); assertEquals("getIndex", i++, it.getIndex()); assertEquals("getRunStart", 0, it.getRunStart()); assertEquals("getRunLimit", text.length(), it.getRunLimit()); assertTrue(it.getAttributes().isEmpty()); } assertEquals(text.length(), i); for (char c=it.last(); c!=DONE; c=it.previous()) { assertEquals(text.charAt(--i), c); assertEquals(it .charAt( i), c); assertEquals("getIndex", i, it.getIndex()); assertEquals("getRunStart", 0, it.getRunStart()); assertEquals("getRunLimit", text.length(), it.getRunLimit()); assertTrue(it.getAttributes().isEmpty()); } assertEquals(0, i); }
characterIterator.append(format.formatToCharacterIterator(value), toAppendTo); } else { format.format(value, toAppendTo, new FieldPosition(-1)); characterIterator.addFieldLimit(Field.forCode(field), value, startPosition);
/** * Creates and returns an attributed {@link FormattedCharacterIterator} * with the attributes. */ FormattedCharacterIterator iterator(final boolean o) { final FormattedCharacterIterator it = new FormattedCharacterIterator(this); int start=0; upper= 2; if (o) it.addFieldLimit(INTEGER, 45, start); upper= 3; it.addFieldLimit(DEGREES, 45, start); start=upper; upper= 5; if (o) it.addFieldLimit(INTEGER, 30, start); upper= 6; it.addFieldLimit(MINUTES, 30, start); start=upper; upper= 8; if (o) it.addFieldLimit(INTEGER, 15, start); start=upper; upper= 9; if (o) it.addFieldLimit(DECIMAL_SEPARATOR, '.', start); start=upper; upper=10; if (o) it.addFieldLimit(FRACTION, 0, start); start=6; upper=11; it.addFieldLimit(SECONDS, 15f, start); start=upper; upper=12; it.addFieldLimit(HEMISPHERE, 'N', start); assertEquals(text.length(), upper); return it; } }
public AttributedCharacterIterator formatToCharacterIterator(final Object value) { final StringBuffer buffer = new StringBuffer(); final FormattedCharacterIterator it = new FormattedCharacterIterator(buffer); try { characterIterator = it;
/** * Formats a latitude or longitude value in the given buffer. The magnitude of the * angular value will be formatted according the pattern given to the last call of * {@link #applyPattern(String)}, and one of the given suffix will be appended * according the angle sign. */ private StringBuffer format(final double angle, StringBuffer toAppendTo, final FieldPosition pos, final char positiveSuffix, final char negativeSuffix) { try { showLeadingFields = true; toAppendTo = format(Math.abs(angle), toAppendTo, pos); } finally { showLeadingFields = false; } final int startPosition = toAppendTo.length(); final char suffix = isNegative(angle) ? negativeSuffix : positiveSuffix; toAppendTo.append(suffix); if (getField(pos) == HEMISPHERE_FIELD) { pos.setBeginIndex(startPosition); pos.setEndIndex(toAppendTo.length()); } if (characterIterator != null) { characterIterator.addFieldLimit(Field.HEMISPHERE, suffix, startPosition); } return toAppendTo; }
characterIterator.append(format.formatToCharacterIterator(value), toAppendTo); } else { format.format(value, toAppendTo, new FieldPosition(-1)); characterIterator.addFieldLimit(Field.forCode(field), value, startPosition);
public AttributedCharacterIterator formatToCharacterIterator(final Object value) { final StringBuffer buffer = new StringBuffer(); final FormattedCharacterIterator it = new FormattedCharacterIterator(buffer); try { characterIterator = it;
/** * Formats a latitude or longitude value in the given buffer. The magnitude of the * angular value will be formatted according the pattern given to the last call of * {@link #applyPattern(String)}, and one of the given suffix will be appended * according the angle sign. */ private StringBuffer format(final double angle, StringBuffer toAppendTo, final FieldPosition pos, final char positiveSuffix, final char negativeSuffix) { try { showLeadingFields = true; toAppendTo = format(Math.abs(angle), toAppendTo, pos); } finally { showLeadingFields = false; } final int startPosition = toAppendTo.length(); final char suffix = isNegative(angle) ? negativeSuffix : positiveSuffix; toAppendTo.append(suffix); if (getField(pos) == HEMISPHERE_FIELD) { pos.setBeginIndex(startPosition); pos.setEndIndex(toAppendTo.length()); } if (characterIterator != null) { characterIterator.addFieldLimit(Field.HEMISPHERE, suffix, startPosition); } return toAppendTo; }
if (characterIterator != null) { final FormattedCharacterIterator it = characterIterator; it.append(numberFormat.formatToCharacterIterator(value), toAppendTo); if (suffix != null) { toAppendTo.append(suffix); it.addFieldLimit(Field.forCode(field), userObject, startPosition); } else { toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
/** * Returns the value of the named attribute for the current character, or {@code null} if none. */ @Override public Object getAttribute(final Attribute attribute) { final int index = getIndex(); for (Entry e = attributes.get(attribute); e != null; e = e.previous) { if (index >= e.start && index < e.limit) { return e.value; } } return null; }
/** * 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. */ @Override public int getRunStart(final Set<? extends Attribute> attributes) { update(null, entries(attributes)); return start; }
public AttributedCharacterIterator formatToCharacterIterator(final Object range) { final StringBuffer buffer = new StringBuffer(); final FormattedCharacterIterator it = new FormattedCharacterIterator(buffer); format(cast(range), buffer, null, it); return it;
if (characterIterator != null) { final FormattedCharacterIterator it = characterIterator; it.append(numberFormat.formatToCharacterIterator(value), toAppendTo); if (suffix != null) { toAppendTo.append(suffix); it.addFieldLimit(Field.forCode(field), userObject, startPosition); } else { toAppendTo = numberFormat.format(value, toAppendTo, dummyFieldPosition());
final int index = getIndex(); if (attribute == null || attribute != runAttribute || index != validity) { runAttribute = attribute;
/** * 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. */ @Override public int getRunStart(final Set<? extends Attribute> attributes) { update(null, entries(attributes)); return start; }
public AttributedCharacterIterator formatToCharacterIterator(final Object range) { final StringBuffer buffer = new StringBuffer(); final FormattedCharacterIterator it = new FormattedCharacterIterator(buffer); format(cast(range), buffer, null, it); return it;
final int index = getIndex(); if (attribute == null || attribute != runAttribute || index != validity) { runAttribute = attribute;
/** * 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. */ @Override public int getRunLimit(final Set<? extends Attribute> attributes) { update(null, entries(attributes)); return limit; }