diff --git a/src/java.base/share/classes/java/text/BreakIterator.java b/src/java.base/share/classes/java/text/BreakIterator.java index 8d535bd89b2..965d9a4e2c1 100644 --- a/src/java.base/share/classes/java/text/BreakIterator.java +++ b/src/java.base/share/classes/java/text/BreakIterator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -115,7 +115,7 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * Examples:
* Creating and using text boundaries: *
- ** * Print each element in order: *+ * {@snippet lang=java : * public static void main(String args[]) { * if (args.length == 1) { * String stringToExamine = args[0]; @@ -131,12 +131,12 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * printLast(boundary, stringToExamine); * } * } - *+ * } *
- ** * Print each element in reverse order: *+ * {@snippet lang=java : * public static void printEachForward(BreakIterator boundary, String source) { * int start = boundary.first(); * for (int end = boundary.next(); @@ -145,12 +145,12 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * System.out.println(source.substring(start,end)); * } * } - *+ * } *
- ** * Print first element: *+ * {@snippet lang=java : * public static void printEachBackward(BreakIterator boundary, String source) { * int end = boundary.last(); * for (int start = boundary.previous(); @@ -159,45 +159,45 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * System.out.println(source.substring(start,end)); * } * } - *+ * } *
- ** * Print last element: *+ * {@snippet lang=java : * public static void printFirst(BreakIterator boundary, String source) { * int start = boundary.first(); * int end = boundary.next(); * System.out.println(source.substring(start,end)); * } - *+ * } *
- ** * Print the element at a specified position: *+ * {@snippet lang=java : * public static void printLast(BreakIterator boundary, String source) { * int end = boundary.last(); * int start = boundary.previous(); * System.out.println(source.substring(start,end)); * } - *+ * } *
- ** * Find the next word: *+ *{@snippet lang=java : * public static void printAt(BreakIterator boundary, int pos, String source) { * int end = boundary.following(pos); * int start = boundary.previous(); * System.out.println(source.substring(start,end)); * } - *+ * } *
- ** *{@code + * {@snippet lang=java : * public static int nextWordStartAfter(int pos, String text) { * BreakIterator wb = BreakIterator.getWordInstance(); * wb.setText(text); @@ -213,7 +213,7 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * } * return BreakIterator.DONE; * } - * }+ * } * (The iterator returned by BreakIterator.getWordInstance() is unique in that * the break positions it returns don't represent both the start and end of the * thing being iterated over. That is, a sentence-break iterator returns breaks diff --git a/src/java.base/share/classes/java/text/CharacterIterator.java b/src/java.base/share/classes/java/text/CharacterIterator.java index b6e5e8b1196..8ff4249ab86 100644 --- a/src/java.base/share/classes/java/text/CharacterIterator.java +++ b/src/java.base/share/classes/java/text/CharacterIterator.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -62,27 +62,27 @@ package java.text; *Examples:
* * Traverse the text from start to finish - *
{@code + * {@snippet lang=java : * public void traverseForward(CharacterIterator iter) { - * for(char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { + * for (char c = iter.first(); c != CharacterIterator.DONE; c = iter.next()) { * processChar(c); * } * } - * }+ * } * * Traverse the text backwards, from end to start - *{@code + * {@snippet lang=java : * public void traverseBackward(CharacterIterator iter) { - * for(char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) { + * for (char c = iter.last(); c != CharacterIterator.DONE; c = iter.previous()) { * processChar(c); * } * } - * }+ * } * * Traverse both forward and backward from a given position in the text. * Calls to notBoundary() in this example represents some * additional stopping criteria. - *{@code + * {@snippet lang=java : * public void traverseOut(CharacterIterator iter, int pos) { * for (char c = iter.setIndex(pos); * c != CharacterIterator.DONE && notBoundary(c); @@ -96,7 +96,7 @@ package java.text; * int start = iter.getIndex(); * processSection(start, end); * } - * }+ * } * * @since 1.1 * @see StringCharacterIterator diff --git a/src/java.base/share/classes/java/text/DateFormatSymbols.java b/src/java.base/share/classes/java/text/DateFormatSymbols.java index f621b1d115c..76708d6bf78 100644 --- a/src/java.base/share/classes/java/text/DateFormatSymbols.java +++ b/src/java.base/share/classes/java/text/DateFormatSymbols.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -78,9 +78,9 @@ import sun.util.locale.provider.TimeZoneNameUtility; * If you decide to create a date-time formatter with a specific * format pattern for a specific locale, you can do so with: *- ** *- * new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)). - *+ * {@snippet lang=java : + * new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)); + * } *If the locale contains "rg" (region override) diff --git a/src/java.base/share/classes/java/text/DecimalFormat.java b/src/java.base/share/classes/java/text/DecimalFormat.java index ff126971019..618e4685e00 100644 --- a/src/java.base/share/classes/java/text/DecimalFormat.java +++ b/src/java.base/share/classes/java/text/DecimalFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -70,12 +70,12 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter; * {@code DecimalFormat}. If you need to customize the format object, do * something like this: * - *
+ * }- * NumberFormat f = NumberFormat.getInstance(loc); - * if (f instanceof DecimalFormat) { - * ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); + *{@snippet lang=java : + * NumberFormat numFormat = NumberFormat.getInstance(loc); + * if (numFormat instanceof DecimalFormat decFormat) { + * decFormat.setDecimalSeparatorAlwaysShown(true); * } - *
A {@code DecimalFormat} comprises a pattern and a set of * symbols. The pattern may be set directly using @@ -338,31 +338,27 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter; * *
+ * } * * @see Java Tutorial * @see NumberFormat diff --git a/src/java.base/share/classes/java/text/NumberFormat.java b/src/java.base/share/classes/java/text/NumberFormat.java index 18c078f1a4e..07c1c18a94e 100644 --- a/src/java.base/share/classes/java/text/NumberFormat.java +++ b/src/java.base/share/classes/java/text/NumberFormat.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -71,28 +71,28 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * To format a number for the current Locale, use one of the factory * class methods: *{@code + *{@snippet lang=java : * // Print out a number using the localized number, integer, currency, - * // and percent format for each locale}{@code + * // and percent format for each locale * Locale[] locales = NumberFormat.getAvailableLocales(); * double myNumber = -1234.56; * NumberFormat form; * for (int j = 0; j < 4; ++j) { * System.out.println("FORMAT"); - * for (int i = 0; i < locales.length; ++i) { - * if (locales[i].getCountry().length() == 0) { - * continue; // Skip language-only locales + * for (Locale locale : locales) { + * if (locale.getCountry().length() == 0) { + * continue; // Skip language-only locales * } - * System.out.print(locales[i].getDisplayName()); - * switch (j) { - * case 0: - * form = NumberFormat.getInstance(locales[i]); break; - * case 1: - * form = NumberFormat.getIntegerInstance(locales[i]); break; - * case 2: - * form = NumberFormat.getCurrencyInstance(locales[i]); break; - * default: - * form = NumberFormat.getPercentInstance(locales[i]); break; - * } - * if (form instanceof DecimalFormat) { - * System.out.print(": " + ((DecimalFormat) form).toPattern()); + * System.out.print(locale.getDisplayName()); + * form = switch (j) { + * case 0 -> NumberFormat.getInstance(locale); + * case 1 -> NumberFormat.getIntegerInstance(locale); + * case 2 -> NumberFormat.getCurrencyInstance(locale); + * default -> NumberFormat.getPercentInstance(locale); + * }; + * if (form instanceof DecimalFormat decForm) { + * System.out.print(": " + decForm.toPattern()); * } * System.out.print(" -> " + form.format(myNumber)); * try { @@ -370,7 +366,7 @@ import sun.util.locale.provider.ResourceBundleBasedAdapter; * } catch (ParseException e) {} * } * } - * }
- ** If you are formatting multiple numbers, it is * more efficient to get the format and use it multiple times so that * the system doesn't have to fetch the information about the local * language and country conventions multiple times. *{@code + * {@snippet lang=java : * myString = NumberFormat.getInstance().format(myNumber); - * }+ * } *
- ** To format a number for a different Locale, specify it in the * call to {@code getInstance}. *{@code + * {@snippet lang=java : * NumberFormat nf = NumberFormat.getInstance(); * for (int i = 0; i < myNumber.length; ++i) { * output.println(nf.format(myNumber[i]) + "; "); * } - * }+ * } *
- ** *{@code + * {@snippet lang=java : * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH); - * }+ * } *
If the locale contains "nu" (numbers) and/or "rg" (region override) @@ -103,9 +103,9 @@ import sun.util.locale.provider.LocaleServiceProviderPool; * *
You can also use a {@code NumberFormat} to parse numbers: *
- ** Use {@code getInstance} or {@code getNumberInstance} to get the * normal number format. Use {@code getIntegerInstance} to get an{@code + * {@snippet lang=java : * myNumber = nf.parse(myString); - * }+ * } *