diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificFormatHelper.java b/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificFormatHelper.java deleted file mode 100644 index 8daa31c081..0000000000 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificFormatHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2014, International Business Machines Corporation and - * others. All Rights Reserved. - ******************************************************************************* - */ -package com.ibm.icu.text; - -import java.text.AttributedCharacterIterator; - -/** - * A helper class for formatting in user-friendly scientific notation. - * - * ScientificFormatHelper instances are immutable and thread-safe. However, the - * AttributedCharacterIterator instances that ScientificFormatHelper instances format must - * not be shared across multiple threads. - * - * Sample code: - *
- * DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(new ULocale("en"));
- * AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(1.23456e-78);
- * ScientificFormatHelper helper = ScientificFormatHelper.getInstance(
-                decfmt.getDecimalFormatSymbols());
- * 
- * // Output: "1.23456×10-78"
- *  System.out.println(helper.insertMarkup(iterator, "", ""));
- * 
- * - * @see NumberFormat - * @draft ICU 54 - * @provisional This API might change or be removed in a future release. - * - */ -public final class ScientificFormatHelper { - - private final String preExponent; - - private ScientificFormatHelper(String preExponent) { - this.preExponent = preExponent; - } - - /** - * Returns a new ScientificFormatHelper. - * @param dfs comes from the DecimalFormat instance used for default scientific notation. - * @draft ICU 54 - * @provisional This API might change or be removed in a future release. - */ - public static ScientificFormatHelper getInstance(DecimalFormatSymbols dfs) { - return new ScientificFormatHelper(ScientificNumberFormatter.getPreExponent(dfs)); - } - - /** - * Makes scientific notation user-friendly by surrounding exponent with - * html to make it superscript. - * @param iterator the value that DecimalFormat.formatToCharacterIterator() returned. - * @param beginMarkup the start html for the exponent e.g "" - * @param endMarkup the end html for the exponent e.g "" - * @return the user-friendly scientific notation. - * @draft ICU 54 - * @provisional This API might change or be removed in a future release. - */ - public String insertMarkup( - AttributedCharacterIterator iterator, - CharSequence beginMarkup, - CharSequence endMarkup) { - return format( - iterator, - new ScientificNumberFormatter.MarkupStyle( - beginMarkup.toString(), endMarkup.toString())); - } - - /** - * Makes scientific notation user-friendly by using specific code points - * for superscript 0..9, -, and + in the exponent rather than by using - * html. - * @param iterator the value that DecimalFormat.formatToCharacterIterator() returned. - * @return the user-friendly scientific notation. - * @draft ICU 54 - * @provisional This API might change or be removed in a future release. - */ - public String toSuperscriptExponentDigits(AttributedCharacterIterator iterator) { - return format(iterator, ScientificNumberFormatter.SUPER_SCRIPT); - } - - private String format( - AttributedCharacterIterator iterator, ScientificNumberFormatter.Style option) { - return option.format(iterator, preExponent); - } -} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificNumberFormatter.java b/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificNumberFormatter.java index 1d6a1fc37a..2bf7528983 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificNumberFormatter.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/ScientificNumberFormatter.java @@ -128,9 +128,8 @@ public final class ScientificNumberFormatter { /** * A style type for ScientificNumberFormatter. All Style instances are immutable * and thread-safe. - * TODO: Make private once ScientificFormatHelper is deleted. */ - static abstract class Style { + private static abstract class Style { abstract String format( AttributedCharacterIterator iterator, String preExponent); // '* 10^' @@ -150,8 +149,7 @@ public final class ScientificNumberFormatter { } } - // TODO: make private - static class MarkupStyle extends Style { + private static class MarkupStyle extends Style { private final String beginMarkup; private final String endMarkup; @@ -201,8 +199,7 @@ public final class ScientificNumberFormatter { } } - // TODO: Make private - static class SuperscriptStyle extends Style { + private static class SuperscriptStyle extends Style { private static final char[] SUPERSCRIPT_DIGITS = { 0x2070, 0xB9, 0xB2, 0xB3, 0x2074, 0x2075, 0x2076, 0x2077, 0x2078, 0x2079 @@ -304,7 +301,7 @@ public final class ScientificNumberFormatter { } - static String getPreExponent(DecimalFormatSymbols dfs) { + private static String getPreExponent(DecimalFormatSymbols dfs) { StringBuilder preExponent = new StringBuilder(); preExponent.append(dfs.getExponentMultiplicationSign()); char[] digits = dfs.getDigits(); @@ -312,14 +309,14 @@ public final class ScientificNumberFormatter { return preExponent.toString(); } - static ScientificNumberFormatter getInstance( + private static ScientificNumberFormatter getInstance( DecimalFormat decimalFormat, Style style) { DecimalFormatSymbols dfs = decimalFormat.getDecimalFormatSymbols(); return new ScientificNumberFormatter( (DecimalFormat) decimalFormat.clone(), getPreExponent(dfs), style); } - static ScientificNumberFormatter getInstanceForLocale( + private static ScientificNumberFormatter getInstanceForLocale( ULocale locale, Style style) { DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getScientificInstance(locale); @@ -329,7 +326,7 @@ public final class ScientificNumberFormatter { style); } - static final Style SUPER_SCRIPT = new SuperscriptStyle(); + private static final Style SUPER_SCRIPT = new SuperscriptStyle(); private ScientificNumberFormatter( DecimalFormat decimalFormat, String preExponent, Style style) { diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ScientificFormatHelperTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ScientificFormatHelperTest.java deleted file mode 100644 index 3c49e237f6..0000000000 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/ScientificFormatHelperTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - ******************************************************************************* - * Copyright (C) 2014, International Business Machines Corporation and * - * others. All Rights Reserved. * - ******************************************************************************* - */ -package com.ibm.icu.dev.test.format; - -import java.text.AttributedCharacterIterator; - -import com.ibm.icu.dev.test.TestFmwk; -import com.ibm.icu.text.DecimalFormat; -import com.ibm.icu.text.NumberFormat; -import com.ibm.icu.text.ScientificFormatHelper; -import com.ibm.icu.util.ULocale; - -public class ScientificFormatHelperTest extends TestFmwk { - - public static void main(String[] args) throws Exception { - new ScientificFormatHelperTest().run(args); - } - - public void TestBasic() { - ULocale en = new ULocale("en"); - DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(en); - AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(1.23456e-78); - ScientificFormatHelper helper = ScientificFormatHelper.getInstance( - decfmt.getDecimalFormatSymbols()); - assertEquals( - "insetMarkup", - "1.23456\u00d710-78", - helper.insertMarkup(iterator, "", "")); - assertEquals( - "toSuperscriptExponentDigits", - "1.23456\u00d710\u207b\u2077\u2078", - helper.toSuperscriptExponentDigits(iterator)); - } - - public void TestPlusSignInExponentMarkup() { - ULocale en = new ULocale("en"); - DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(en); - decfmt.applyPattern("0.00E+0"); - AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(6.02e23); - ScientificFormatHelper helper = ScientificFormatHelper.getInstance( - decfmt.getDecimalFormatSymbols()); - assertEquals( - "", - "6.02\u00d710+23", - helper.insertMarkup(iterator, "", "")); - } - - - public void TestPlusSignInExponentSuperscript() { - ULocale en = new ULocale("en"); - DecimalFormat decfmt = (DecimalFormat) NumberFormat.getScientificInstance(en); - decfmt.applyPattern("0.00E+0"); - AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(6.02e23); - ScientificFormatHelper helper = ScientificFormatHelper.getInstance( - decfmt.getDecimalFormatSymbols()); - assertEquals( - "", - "6.02\u00d710\u207a\u00b2\u00b3", - helper.toSuperscriptExponentDigits(iterator)); - } - - public void TestFixedDecimalMarkup() { - ULocale en = new ULocale("en"); - DecimalFormat decfmt = (DecimalFormat) NumberFormat.getInstance(en); - AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(123456.0); - ScientificFormatHelper helper = ScientificFormatHelper.getInstance( - decfmt.getDecimalFormatSymbols()); - assertEquals("", "123,456", helper.insertMarkup(iterator, "", "")); - } - - public void TestFixedDecimalSuperscript() { - ULocale en = new ULocale("en"); - DecimalFormat decfmt = (DecimalFormat) NumberFormat.getInstance(en); - AttributedCharacterIterator iterator = decfmt.formatToCharacterIterator(123456.0); - ScientificFormatHelper helper = ScientificFormatHelper.getInstance( - decfmt.getDecimalFormatSymbols()); - assertEquals("", "123,456", helper.toSuperscriptExponentDigits(iterator)); - } -} diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java index d16ab61f69..52f267ba62 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TestAll.java @@ -59,7 +59,6 @@ public class TestAll extends TestGroup { "NumberFormatRoundTripTest", "NumberRegression", "NumberFormatRegressionTest", - "ScientificFormatHelperTest", "ScientificNumberFormatterTest", "IntlTestDecimalFormatAPI", "IntlTestDecimalFormatAPIC",