// NOTE: outArray MUST have at least ARRAY_LENGTH entries. No bounds checking is performed.
- private static void getMeasureData(ULocale locale, MeasureUnit unit, UnitWidth width, String[] outArray) {
+ private static void getMeasureData(
+ ULocale locale,
+ MeasureUnit unit,
+ UnitWidth width,
+ String[] outArray) {
PluralTableSink sink = new PluralTableSink(outArray);
ICUResourceBundle resource;
- resource = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_UNIT_BASE_NAME, locale);
+ resource = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_UNIT_BASE_NAME,
+ locale);
StringBuilder key = new StringBuilder();
key.append("units");
if (width == UnitWidth.NARROW) {
// Example pattern from data: "{0} {1}"
// Example output after find-and-replace: "{0} US dollars"
simpleFormat = simpleFormat.replace("{1}", longName);
- // String compiled = SimpleFormatterImpl.compileToStringMinMaxArguments(simpleFormat, sb, 1, 1);
+ // String compiled = SimpleFormatterImpl.compileToStringMinMaxArguments(simpleFormat, sb, 1,
+ // 1);
// SimpleModifier mod = new SimpleModifier(compiled, Field.CURRENCY, false);
outArray[index] = simpleFormat;
}
private static String getPerUnitFormat(ULocale locale, UnitWidth width) {
ICUResourceBundle resource;
- resource = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_UNIT_BASE_NAME, locale);
+ resource = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_UNIT_BASE_NAME,
+ locale);
StringBuilder key = new StringBuilder();
key.append("units");
if (width == UnitWidth.NARROW) {
try {
return resource.getStringWithFallback(key.toString());
} catch (MissingResourceException e) {
- throw new IllegalArgumentException("Could not find x-per-y format for " + locale + ", width " + width);
+ throw new IllegalArgumentException(
+ "Could not find x-per-y format for " + locale + ", width " + width);
}
}
private final PluralRules rules;
private final MicroPropsGenerator parent;
- private LongNameHandler(Map<StandardPlural, SimpleModifier> modifiers, PluralRules rules,
+ private LongNameHandler(
+ Map<StandardPlural, SimpleModifier> modifiers,
+ PluralRules rules,
MicroPropsGenerator parent) {
this.modifiers = modifiers;
this.rules = rules;
this.parent = parent;
}
- public static LongNameHandler forCurrencyLongNames(ULocale locale, Currency currency, PluralRules rules,
+ public static LongNameHandler forCurrencyLongNames(
+ ULocale locale,
+ Currency currency,
+ PluralRules rules,
MicroPropsGenerator parent) {
String[] simpleFormats = new String[ARRAY_LENGTH];
getCurrencyLongNameData(locale, currency, simpleFormats);
return new LongNameHandler(modifiers, rules, parent);
}
- public static LongNameHandler forMeasureUnit(ULocale locale, MeasureUnit unit, MeasureUnit perUnit, UnitWidth width,
- PluralRules rules, MicroPropsGenerator parent) {
+ public static LongNameHandler forMeasureUnit(
+ ULocale locale,
+ MeasureUnit unit,
+ MeasureUnit perUnit,
+ UnitWidth width,
+ PluralRules rules,
+ MicroPropsGenerator parent) {
if (perUnit != null) {
// Compound unit: first try to simplify (e.g., meters per second is its own unit).
MeasureUnit simplified = MeasureUnit.resolveUnitPerUnit(unit, perUnit);
return new LongNameHandler(modifiers, rules, parent);
}
- private static LongNameHandler forCompoundUnit(ULocale locale, MeasureUnit unit, MeasureUnit perUnit,
- UnitWidth width, PluralRules rules, MicroPropsGenerator parent) {
+ private static LongNameHandler forCompoundUnit(
+ ULocale locale,
+ MeasureUnit unit,
+ MeasureUnit perUnit,
+ UnitWidth width,
+ PluralRules rules,
+ MicroPropsGenerator parent) {
String[] primaryData = new String[ARRAY_LENGTH];
getMeasureData(locale, unit, width, primaryData);
String[] secondaryData = new String[ARRAY_LENGTH];
// rawPerUnitFormat is something like "{0}/{1}"; we need to substitute in the secondary unit.
// TODO: Lots of thrashing. Improve?
StringBuilder sb = new StringBuilder();
- String compiled = SimpleFormatterImpl.compileToStringMinMaxArguments(rawPerUnitFormat, sb, 2, 2);
+ String compiled = SimpleFormatterImpl
+ .compileToStringMinMaxArguments(rawPerUnitFormat, sb, 2, 2);
String secondaryFormat = getWithPlural(secondaryData, StandardPlural.ONE);
- String secondaryCompiled = SimpleFormatterImpl.compileToStringMinMaxArguments(secondaryFormat, sb, 1, 1);
- String secondaryString = SimpleFormatterImpl.getTextWithNoArguments(secondaryCompiled).trim();
+ String secondaryCompiled = SimpleFormatterImpl
+ .compileToStringMinMaxArguments(secondaryFormat, sb, 1, 1);
+ String secondaryString = SimpleFormatterImpl.getTextWithNoArguments(secondaryCompiled)
+ .trim();
perUnitFormat = SimpleFormatterImpl.formatCompiledPattern(compiled, "{0}", secondaryString);
}
// TODO: What field to use for units?
return new LongNameHandler(modifiers, rules, parent);
}
- private static void simpleFormatsToModifiers(String[] simpleFormats, NumberFormat.Field field,
+ private static void simpleFormatsToModifiers(
+ String[] simpleFormats,
+ NumberFormat.Field field,
Map<StandardPlural, SimpleModifier> output) {
StringBuilder sb = new StringBuilder();
for (StandardPlural plural : StandardPlural.VALUES) {
}
}
- private static void multiSimpleFormatsToModifiers(String[] leadFormats, String trailFormat,
- NumberFormat.Field field, Map<StandardPlural, SimpleModifier> output) {
+ private static void multiSimpleFormatsToModifiers(
+ String[] leadFormats,
+ String trailFormat,
+ NumberFormat.Field field,
+ Map<StandardPlural, SimpleModifier> output) {
StringBuilder sb = new StringBuilder();
String trailCompiled = SimpleFormatterImpl.compileToStringMinMaxArguments(trailFormat, sb, 1, 1);
for (StandardPlural plural : StandardPlural.VALUES) {
String leadFormat = getWithPlural(leadFormats, plural);
String compoundFormat = SimpleFormatterImpl.formatCompiledPattern(trailCompiled, leadFormat);
- String compoundCompiled = SimpleFormatterImpl.compileToStringMinMaxArguments(compoundFormat, sb, 1, 1);
+ String compoundCompiled = SimpleFormatterImpl
+ .compileToStringMinMaxArguments(compoundFormat, sb, 1, 1);
output.put(plural, new SimpleModifier(compoundCompiled, field, false));
}
}
import com.ibm.icu.text.NumberFormat.Field;
/**
- * A StringBuilder optimized for number formatting. It implements the following key features beyond a normal JDK
- * StringBuilder:
+ * A StringBuilder optimized for number formatting. It implements the following key features beyond a
+ * normal JDK StringBuilder:
*
* <ol>
* <li>Efficient prepend as well as append.
}
/**
- * Inserts the specified CharSequence at the specified index in the string, reading from the CharSequence from start
- * (inclusive) to end (exclusive).
+ * Inserts the specified CharSequence at the specified index in the string, reading from the
+ * CharSequence from start (inclusive) to end (exclusive).
*
* @return The number of chars added, which is the length of CharSequence.
*/
}
/**
- * Appends the chars in the specified char array to the end of the string, and associates them with the fields in
- * the specified field array, which must have the same length as chars.
+ * Appends the chars in the specified char array to the end of the string, and associates them with
+ * the fields in the specified field array, which must have the same length as chars.
*
* @return The number of chars added, which is the length of the char array.
*/
}
/**
- * Inserts the chars in the specified char array at the specified index in the string, and associates them with the
- * fields in the specified field array, which must have the same length as chars.
+ * Inserts the chars in the specified char array at the specified index in the string, and associates
+ * them with the fields in the specified field array, which must have the same length as chars.
*
* @return The number of chars added, which is the length of the char array.
*/
}
private int prepareForInsertHelper(int index, int count) {
- // Java note: Keeping this code out of prepareForInsert() increases the speed of append operations.
+ // Java note: Keeping this code out of prepareForInsert() increases the speed of append
+ // operations.
int oldCapacity = getCapacity();
int oldZero = zero;
char[] oldChars = chars;
// First copy the prefix and then the suffix, leaving room for the new chars that the
// caller wants to insert.
System.arraycopy(oldChars, oldZero, newChars, newZero, index);
- System.arraycopy(oldChars, oldZero + index, newChars, newZero + index + count, length - index);
+ System.arraycopy(oldChars,
+ oldZero + index,
+ newChars,
+ newZero + index + count,
+ length - index);
System.arraycopy(oldFields, oldZero, newFields, newZero, index);
- System.arraycopy(oldFields, oldZero + index, newFields, newZero + index + count, length - index);
+ System.arraycopy(oldFields,
+ oldZero + index,
+ newFields,
+ newZero + index + count,
+ length - index);
chars = newChars;
fields = newFields;
// First copy the entire string to the location of the prefix, and then move the suffix
// to make room for the new chars that the caller wants to insert.
System.arraycopy(oldChars, oldZero, oldChars, newZero, length);
- System.arraycopy(oldChars, newZero + index, oldChars, newZero + index + count, length - index);
+ System.arraycopy(oldChars,
+ newZero + index,
+ oldChars,
+ newZero + index + count,
+ length - index);
System.arraycopy(oldFields, oldZero, oldFields, newZero, length);
- System.arraycopy(oldFields, newZero + index, oldFields, newZero + index + count, length - index);
+ System.arraycopy(oldFields,
+ newZero + index,
+ oldFields,
+ newZero + index + count,
+ length - index);
zero = newZero;
length += count;
* Returns a string that includes field information, for debugging purposes.
*
* <p>
- * For example, if the string is "-12.345", the debug string will be something like "<NumberStringBuilder
- * [-123.45] [-iii.ff]>"
+ * For example, if the string is "-12.345", the debug string will be something like
+ * "<NumberStringBuilder [-123.45] [-iii.ff]>"
*
* @return A string for debugging purposes.
*/
}
/**
- * @return Whether the contents and field values of this string builder are equal to the given chars and fields.
+ * @return Whether the contents and field values of this string builder are equal to the given chars
+ * and fields.
* @see #toCharArray
* @see #toFieldArray
*/
Field _field = (i < zero + length) ? fields[i] : null;
if (seenStart && field != _field) {
// Special case: GROUPING_SEPARATOR counts as an INTEGER.
- if (field == NumberFormat.Field.INTEGER && _field == NumberFormat.Field.GROUPING_SEPARATOR) {
+ if (field == NumberFormat.Field.INTEGER
+ && _field == NumberFormat.Field.GROUPING_SEPARATOR) {
continue;
}
fp.setEndIndex(i - zero + offset);
int currentStart = -1;
for (int i = 0; i < length; i++) {
Field field = fields[i + zero];
- if (current == NumberFormat.Field.INTEGER && field == NumberFormat.Field.GROUPING_SEPARATOR) {
+ if (current == NumberFormat.Field.INTEGER
+ && field == NumberFormat.Field.GROUPING_SEPARATOR) {
// Special case: GROUPING_SEPARATOR counts as an INTEGER.
- as.addAttribute(NumberFormat.Field.GROUPING_SEPARATOR, NumberFormat.Field.GROUPING_SEPARATOR, i, i + 1);
+ as.addAttribute(NumberFormat.Field.GROUPING_SEPARATOR,
+ NumberFormat.Field.GROUPING_SEPARATOR,
+ i,
+ i + 1);
} else if (current != field) {
if (current != null) {
as.addAttribute(current, current, currentStart, i);
import com.ibm.icu.text.NumberFormat.Field;
/**
- * The second primary implementation of {@link Modifier}, this one consuming a {@link com.ibm.icu.text.SimpleFormatter}
- * pattern.
+ * The second primary implementation of {@link Modifier}, this one consuming a
+ * {@link com.ibm.icu.text.SimpleFormatter} pattern.
*/
public class SimpleModifier implements Modifier {
private final String compiledPattern;
count += Character.codePointCount(compiledPattern, 2, 2 + prefixLength);
}
if (suffixLength > 0) {
- count += Character.codePointCount(compiledPattern, 1 + suffixOffset, 1 + suffixOffset + suffixLength);
+ count += Character
+ .codePointCount(compiledPattern, 1 + suffixOffset, 1 + suffixOffset + suffixLength);
}
return count;
}
/**
* TODO: This belongs in SimpleFormatterImpl. The only reason I haven't moved it there yet is because
- * DoubleSidedStringBuilder is an internal class and SimpleFormatterImpl feels like it should not depend on it.
+ * DoubleSidedStringBuilder is an internal class and SimpleFormatterImpl feels like it should not
+ * depend on it.
*
* <p>
- * Formats a value that is already stored inside the StringBuilder <code>result</code> between the indices
- * <code>startIndex</code> and <code>endIndex</code> by inserting characters before the start index and after the
- * end index.
+ * Formats a value that is already stored inside the StringBuilder <code>result</code> between the
+ * indices <code>startIndex</code> and <code>endIndex</code> by inserting characters before the start
+ * index and after the end index.
*
* <p>
* This is well-defined only for patterns with exactly one argument.
* The right index of the value within the string builder.
* @return The number of characters (UTF-16 code points) that were added to the StringBuilder.
*/
- public int formatAsPrefixSuffix(NumberStringBuilder result, int startIndex, int endIndex, Field field) {
+ public int formatAsPrefixSuffix(
+ NumberStringBuilder result,
+ int startIndex,
+ int endIndex,
+ Field field) {
if (prefixLength > 0) {
result.insert(startIndex, compiledPattern, 2, 2 + prefixLength, field);
}
if (suffixLength > 0) {
- result.insert(endIndex + prefixLength, compiledPattern, 1 + suffixOffset, 1 + suffixOffset + suffixLength,
+ result.insert(endIndex + prefixLength,
+ compiledPattern,
+ 1 + suffixOffset,
+ 1 + suffixOffset + suffixLength,
field);
}
return prefixLength + suffixLength;