Search in sources :

Example 11 with Attribute

use of java.text.AttributedCharacterIterator.Attribute in project es6draft by anba.

the class NumberFormatConstructor method PartitionNumberPattern.

/**
 * PartitionNumberPattern(numberFormat, x)
 *
 * @param numberFormatObj
 *            the number format object
 * @param x
 *            the number value
 * @return the formatted number object
 */
private static List<Map.Entry<String, String>> PartitionNumberPattern(NumberFormatObject numberFormat, double x) {
    if (x == -0.0) {
        // -0 is not considered to be negative, cf. step 3a
        x = +0.0;
    }
    ArrayList<Map.Entry<String, String>> parts = new ArrayList<>();
    NumberFormat numFormat = numberFormat.getNumberFormat();
    AttributedCharacterIterator iterator = numFormat.formatToCharacterIterator(x);
    StringBuilder sb = new StringBuilder();
    for (char ch = iterator.first(); ch != CharacterIterator.DONE; ch = iterator.next()) {
        sb.append(ch);
        if (iterator.getIndex() + 1 == iterator.getRunLimit()) {
            Iterator<Attribute> keyIterator = iterator.getAttributes().keySet().iterator();
            String key;
            if (keyIterator.hasNext()) {
                key = fieldToString((NumberFormat.Field) keyIterator.next(), x);
            } else {
                key = "literal";
            }
            String value = sb.toString();
            sb.setLength(0);
            parts.add(new AbstractMap.SimpleImmutableEntry<>(key, value));
        }
    }
    return parts;
}
Also used : Attribute(java.text.AttributedCharacterIterator.Attribute) ArrayList(java.util.ArrayList) AttributedCharacterIterator(java.text.AttributedCharacterIterator) AbstractMap(java.util.AbstractMap) NumberFormat(com.ibm.icu.text.NumberFormat)

Aggregations

Attribute (java.text.AttributedCharacterIterator.Attribute)11 AttributedCharacterIterator (java.text.AttributedCharacterIterator)7 AbstractMap (java.util.AbstractMap)3 ArrayList (java.util.ArrayList)3 DateField (com.github.anba.es6draft.runtime.objects.intl.DateFieldSymbolTable.DateField)2 DateFormat (com.ibm.icu.text.DateFormat)2 SimpleDateFormat (com.ibm.icu.text.SimpleDateFormat)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Vector (java.util.Vector)2 NumberFormat (com.ibm.icu.text.NumberFormat)1 Toolkit (java.awt.Toolkit)1 TextAttribute (java.awt.font.TextAttribute)1 InputMethodHighlight (java.awt.im.InputMethodHighlight)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 NotSerializableException (java.io.NotSerializableException)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1