use of java.text.AttributedCharacterIterator in project robovm by robovm.
the class OldAttributedStringTest method test_getIterator$Ljava_text_AttributedCharacterIterator$Attribute.
/**
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[])
* Test of method
* java.text.AttributedString#getIterator(AttributedCharacterIterator.Attribute[]).
*/
public void test_getIterator$Ljava_text_AttributedCharacterIterator$Attribute() {
String test = "Test string";
try {
Map<AttributedCharacterIterator.Attribute, String> hm = new HashMap<AttributedCharacterIterator.Attribute, String>();
AttributedCharacterIterator.Attribute[] aci = new AttributedCharacterIterator.Attribute[3];
aci[0] = new TestAttributedCharacterIteratorAttribute("att1");
aci[1] = new TestAttributedCharacterIteratorAttribute("att2");
aci[2] = new TestAttributedCharacterIteratorAttribute("att3");
hm.put(aci[0], "value1");
hm.put(aci[1], "value2");
AttributedString attrString = new AttributedString(test, hm);
AttributedCharacterIterator it = attrString.getIterator(aci);
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[0]).equals("value1"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[1]).equals("value2"));
assertTrue("Incorrect iteration on AttributedString", it.getAttribute(aci[2]) == null);
} catch (Exception e) {
fail("Unexpected exceptiption " + e.toString());
}
}
use of java.text.AttributedCharacterIterator in project robovm by robovm.
the class OldDecimalFormatTest method test_formatToCharacterIterator.
public void test_formatToCharacterIterator() throws Exception {
AttributedCharacterIterator iterator;
int[] runStarts;
int[] runLimits;
String result;
char current;
// For BigDecimal with multiplier test.
DecimalFormat df = new DecimalFormat();
df.setMultiplier(10);
iterator = df.formatToCharacterIterator(new BigDecimal("12345678901234567890"));
result = "123,456,789,012,345,678,900";
current = iterator.current();
for (int i = 0; i < result.length(); i++) {
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
// For BigDecimal with multiplier test.
df = new DecimalFormat();
df.setMultiplier(-1);
df.setMaximumFractionDigits(20);
iterator = df.formatToCharacterIterator(new BigDecimal("1.23456789012345678901"));
result = "-1.23456789012345678901";
current = iterator.current();
for (int i = 0; i < result.length(); i++) {
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.23456789E1234"));
runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14 };
runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15 };
// 000,000,000,000....
result = "12,345,678,900,";
current = iterator.current();
for (int i = 0; i < runStarts.length; i++) {
assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
assertEquals(0, iterator.getBeginIndex());
assertEquals(1646, iterator.getEndIndex());
iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.23456789E301"));
runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7, 10, 11, 11, 11, 14 };
runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10, 11, 14, 14, 14, 15 };
// 000,000,000,000....
result = "12,345,678,900,";
current = iterator.current();
for (int i = 0; i < runStarts.length; i++) {
assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
assertEquals(0, iterator.getBeginIndex());
assertEquals(402, iterator.getEndIndex());
iterator = new DecimalFormat().formatToCharacterIterator(new BigDecimal("1.2345678E4"));
runStarts = new int[] { 0, 0, 2, 3, 3, 3, 6, 7, 7, 7 };
runLimits = new int[] { 2, 2, 3, 6, 6, 6, 7, 10, 10, 10 };
result = "12,345.678";
current = iterator.current();
for (int i = 0; i < runStarts.length; i++) {
assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
assertEquals(0, iterator.getBeginIndex());
assertEquals(10, iterator.getEndIndex());
iterator = new DecimalFormat().formatToCharacterIterator(new BigInteger("123456789"));
runStarts = new int[] { 0, 0, 0, 3, 4, 4, 4, 7, 8, 8, 8 };
runLimits = new int[] { 3, 3, 3, 4, 7, 7, 7, 8, 11, 11, 11 };
result = "123,456,789";
current = iterator.current();
for (int i = 0; i < runStarts.length; i++) {
assertEquals("wrong start @" + i, runStarts[i], iterator.getRunStart());
assertEquals("wrong limit @" + i, runLimits[i], iterator.getRunLimit());
assertEquals("wrong char @" + i, result.charAt(i), current);
current = iterator.next();
}
assertEquals(0, iterator.getBeginIndex());
assertEquals(11, iterator.getEndIndex());
}
use of java.text.AttributedCharacterIterator in project robovm by robovm.
the class OldFormatTest method test_formatToCharacterIteratorLjava_lang_Object.
public void test_formatToCharacterIteratorLjava_lang_Object() {
MockFormat mf = new MockFormat();
AttributedCharacterIterator aci = mf.formatToCharacterIterator("Test 123 Test");
assertEquals(0, aci.getBeginIndex());
try {
mf.formatToCharacterIterator(null);
fail("NullPointerException was not thrown.");
} catch (NullPointerException npe) {
//expected
}
try {
mf.formatToCharacterIterator("");
} catch (IllegalArgumentException iae) {
//expected
}
}
use of java.text.AttributedCharacterIterator in project robovm by robovm.
the class Support_Format method findFields.
/**
* finds attributes with regards to char index in this
* AttributedCharacterIterator, and puts them in a vector
*
* @param iterator
* @return a vector, each entry in this vector are of type FieldContainer ,
* which stores start and end indexes and an attribute this range
* has
*/
protected static Vector<FieldContainer> findFields(AttributedCharacterIterator iterator) {
Vector<FieldContainer> result = new Vector<FieldContainer>();
while (iterator.getIndex() != iterator.getEndIndex()) {
int start = iterator.getRunStart();
int end = iterator.getRunLimit();
Iterator<Attribute> it = iterator.getAttributes().keySet().iterator();
while (it.hasNext()) {
AttributedCharacterIterator.Attribute attribute = it.next();
Object value = iterator.getAttribute(attribute);
result.add(new FieldContainer(start, end, attribute, value));
// System.out.println(start + " " + end + ": " + attribute + ",
// " + value );
// System.out.println("v.add(new FieldContainer(" + start +"," +
// end +"," + attribute+ "," + value+ "));");
}
iterator.setIndex(end);
}
return result;
}
use of java.text.AttributedCharacterIterator in project robovm by robovm.
the class OldAttributedCharacterIteratorTest method test_getRunLimit.
public void test_getRunLimit() {
int limit = it.getRunLimit();
assertEquals(string.length(), limit);
AttributedString as = new AttributedString("");
assertEquals(0, as.getIterator().getRunLimit());
as = new AttributedString(new AttributedString("test text").getIterator(), 2, 7);
AttributedCharacterIterator it = as.getIterator();
assertEquals(5, it.getRunLimit());
}
Aggregations