You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/10/24 12:33:21 UTC
[commons-text] 01/02: Sort members
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 670680a4f950a2f11ebd282ac3f23c53306eccbb
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Tue Oct 24 08:25:55 2023 -0400
Sort members
---
.../org/apache/commons/text/TextStringBuilder.java | 88 ++++-----
.../commons/text/lookup/StringLookupFactory.java | 84 ++++-----
.../apache/commons/text/numbers/DoubleFormat.java | 36 ++--
.../apache/commons/text/TextStringBuilderTest.java | 210 ++++++++++-----------
.../commons/text/numbers/DoubleFormatTest.java | 50 ++---
5 files changed, 234 insertions(+), 234 deletions(-)
diff --git a/src/main/java/org/apache/commons/text/TextStringBuilder.java b/src/main/java/org/apache/commons/text/TextStringBuilder.java
index e8fe2110..3b0f907b 100644
--- a/src/main/java/org/apache/commons/text/TextStringBuilder.java
+++ b/src/main/java/org/apache/commons/text/TextStringBuilder.java
@@ -293,6 +293,31 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
*/
private static final int MAX_BUFFER_SIZE = Integer.MAX_VALUE - 8;
+ /**
+ * Creates a positive capacity at least as large the minimum required capacity.
+ * If the minimum capacity is negative then this throws an OutOfMemoryError as no array
+ * can be allocated.
+ *
+ * @param minCapacity the minimum capacity
+ * @return the capacity
+ * @throws OutOfMemoryError if the {@code minCapacity} is negative
+ */
+ private static int createPositiveCapacity(final int minCapacity) {
+ if (minCapacity < 0) {
+ // overflow
+ throw new OutOfMemoryError("Unable to allocate array size: " + Integer.toUnsignedString(minCapacity));
+ }
+ // This is called when we require buffer expansion to a very big array.
+ // Use the conservative maximum buffer size if possible, otherwise the biggest required.
+ //
+ // Note: In this situation JDK 1.8 java.util.ArrayList returns Integer.MAX_VALUE.
+ // This excludes some VMs that can exceed MAX_BUFFER_SIZE but not allocate a full
+ // Integer.MAX_VALUE length array.
+ // The result is that we may have to allocate an array of this size more than once if
+ // the capacity must be expanded again.
+ return Math.max(minCapacity, MAX_BUFFER_SIZE);
+ }
+
/**
* Constructs an instance from a reference to a character array. Changes to the input chars are reflected in this
* instance until the internal buffer needs to be reallocated. Using a reference to an array allows the instance to
@@ -1871,50 +1896,6 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
}
}
- /**
- * Resizes the buffer to at least the size specified.
- *
- * @param minCapacity the minimum required capacity
- * @throws OutOfMemoryError if the {@code minCapacity} is negative
- */
- private void resizeBuffer(final int minCapacity) {
- // Overflow-conscious code treats the min and new capacity as unsigned.
- final int oldCapacity = buffer.length;
- int newCapacity = oldCapacity * 2;
- if (Integer.compareUnsigned(newCapacity, minCapacity) < 0) {
- newCapacity = minCapacity;
- }
- if (Integer.compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
- newCapacity = createPositiveCapacity(minCapacity);
- }
- reallocate(newCapacity);
- }
-
- /**
- * Creates a positive capacity at least as large the minimum required capacity.
- * If the minimum capacity is negative then this throws an OutOfMemoryError as no array
- * can be allocated.
- *
- * @param minCapacity the minimum capacity
- * @return the capacity
- * @throws OutOfMemoryError if the {@code minCapacity} is negative
- */
- private static int createPositiveCapacity(final int minCapacity) {
- if (minCapacity < 0) {
- // overflow
- throw new OutOfMemoryError("Unable to allocate array size: " + Integer.toUnsignedString(minCapacity));
- }
- // This is called when we require buffer expansion to a very big array.
- // Use the conservative maximum buffer size if possible, otherwise the biggest required.
- //
- // Note: In this situation JDK 1.8 java.util.ArrayList returns Integer.MAX_VALUE.
- // This excludes some VMs that can exceed MAX_BUFFER_SIZE but not allocate a full
- // Integer.MAX_VALUE length array.
- // The result is that we may have to allocate an array of this size more than once if
- // the capacity must be expanded again.
- return Math.max(minCapacity, MAX_BUFFER_SIZE);
- }
-
/**
* Tests the contents of this builder against another to see if they contain the same character content.
*
@@ -2904,6 +2885,25 @@ public class TextStringBuilder implements CharSequence, Appendable, Serializable
return this;
}
+ /**
+ * Resizes the buffer to at least the size specified.
+ *
+ * @param minCapacity the minimum required capacity
+ * @throws OutOfMemoryError if the {@code minCapacity} is negative
+ */
+ private void resizeBuffer(final int minCapacity) {
+ // Overflow-conscious code treats the min and new capacity as unsigned.
+ final int oldCapacity = buffer.length;
+ int newCapacity = oldCapacity * 2;
+ if (Integer.compareUnsigned(newCapacity, minCapacity) < 0) {
+ newCapacity = minCapacity;
+ }
+ if (Integer.compareUnsigned(newCapacity, MAX_BUFFER_SIZE) > 0) {
+ newCapacity = createPositiveCapacity(minCapacity);
+ }
+ reallocate(newCapacity);
+ }
+
/**
* Reverses the string builder placing each character in the opposite index.
*
diff --git a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
index bea9143b..5ee53ae1 100644
--- a/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
+++ b/src/main/java/org/apache/commons/text/lookup/StringLookupFactory.java
@@ -1313,138 +1313,138 @@ public final class StringLookupFactory {
}
/**
- * Returns the XmlStringLookup singleton instance.
+ * Returns the XmlDecoderStringLookup singleton instance.
* <p>
- * Looks up the value for the key in the format "DocumentPath:XPath".
+ * Decodes strings according to the XML 1.0 specification.
* </p>
* <p>
- * For example: "com/domain/document.xml:/path/to/node".
+ * For example: "&lt;element&gt;" becomes "<element>".
* </p>
* <p>
* Using a {@link StringLookup} from the {@link StringLookupFactory}:
* </p>
*
* <pre>
- * StringLookupFactory.INSTANCE.xmlStringLookup().lookup("com/domain/document.xml:/path/to/node");
+ * StringLookupFactory.INSTANCE.xmlDecoderStringLookup().lookup("&lt;element&gt;");
* </pre>
* <p>
* Using a {@link StringSubstitutor}:
* </p>
*
* <pre>
- * StringSubstitutor.createInterpolator().replace("... ${xml:com/domain/document.xml:/path/to/node} ..."));
+ * StringSubstitutor.createInterpolator().replace("... ${xmlDecoder:&lt;element&gt;} ..."));
* </pre>
* <p>
- * The above examples convert {@code "com/domain/document.xml:/path/to/node"} to the value of the XPath in the XML
- * document.
+ * The above examples convert {@code "<element>"} to {@code "<element>"}.
* </p>
*
- * @return The XmlStringLookup singleton instance.
- * @since 1.5
+ * @return The XmlDecoderStringLookup singleton instance.
+ * @since 1.11.0
*/
- public StringLookup xmlStringLookup() {
- return XmlStringLookup.INSTANCE;
+ public StringLookup xmlDecoderStringLookup() {
+ return XmlDecoderStringLookup.INSTANCE;
}
/**
- * Returns the XmlStringLookup singleton instance.
+ * Returns the XmlEncoderStringLookup singleton instance.
* <p>
- * Looks up the value for the key in the format "DocumentPath:XPath".
+ * Encodes strings according to the XML 1.0 specification.
* </p>
* <p>
- * For example: "com/domain/document.xml:/path/to/node".
+ * For example: "<element>" becomes "&lt;element&gt;".
* </p>
* <p>
* Using a {@link StringLookup} from the {@link StringLookupFactory}:
* </p>
*
* <pre>
- * StringLookupFactory.INSTANCE.xmlStringLookup().lookup("com/domain/document.xml:/path/to/node");
+ * StringLookupFactory.INSTANCE.xmlEncoderStringLookup().lookup("<element>");
* </pre>
* <p>
* Using a {@link StringSubstitutor}:
* </p>
*
* <pre>
- * StringSubstitutor.createInterpolator().replace("... ${xml:com/domain/document.xml:/path/to/node} ..."));
+ * StringSubstitutor.createInterpolator().replace("... ${xmlEncoder:<element>} ..."));
* </pre>
* <p>
- * The above examples convert {@code "com/domain/document.xml:/path/to/node"} to the value of the XPath in the XML
- * document.
+ * The above examples convert {@code "<element>"} to {@code "<element>"}.
* </p>
*
- * @param xPathFactoryFeatures XPathFactory features to set.
- * @return The XmlStringLookup singleton instance.
- * @see XPathFactory#setFeature(String, boolean)
+ * @return The XmlEncoderStringLookup singleton instance.
* @since 1.11.0
*/
- public StringLookup xmlStringLookup(final Map<String, Boolean> xPathFactoryFeatures) {
- return new XmlStringLookup(xPathFactoryFeatures);
+ public StringLookup xmlEncoderStringLookup() {
+ return XmlEncoderStringLookup.INSTANCE;
}
/**
- * Returns the XmlDecoderStringLookup singleton instance.
+ * Returns the XmlStringLookup singleton instance.
* <p>
- * Decodes strings according to the XML 1.0 specification.
+ * Looks up the value for the key in the format "DocumentPath:XPath".
* </p>
* <p>
- * For example: "&lt;element&gt;" becomes "<element>".
+ * For example: "com/domain/document.xml:/path/to/node".
* </p>
* <p>
* Using a {@link StringLookup} from the {@link StringLookupFactory}:
* </p>
*
* <pre>
- * StringLookupFactory.INSTANCE.xmlDecoderStringLookup().lookup("&lt;element&gt;");
+ * StringLookupFactory.INSTANCE.xmlStringLookup().lookup("com/domain/document.xml:/path/to/node");
* </pre>
* <p>
* Using a {@link StringSubstitutor}:
* </p>
*
* <pre>
- * StringSubstitutor.createInterpolator().replace("... ${xmlDecoder:&lt;element&gt;} ..."));
+ * StringSubstitutor.createInterpolator().replace("... ${xml:com/domain/document.xml:/path/to/node} ..."));
* </pre>
* <p>
- * The above examples convert {@code "<element>"} to {@code "<element>"}.
+ * The above examples convert {@code "com/domain/document.xml:/path/to/node"} to the value of the XPath in the XML
+ * document.
* </p>
*
- * @return The XmlDecoderStringLookup singleton instance.
- * @since 1.11.0
+ * @return The XmlStringLookup singleton instance.
+ * @since 1.5
*/
- public StringLookup xmlDecoderStringLookup() {
- return XmlDecoderStringLookup.INSTANCE;
+ public StringLookup xmlStringLookup() {
+ return XmlStringLookup.INSTANCE;
}
/**
- * Returns the XmlEncoderStringLookup singleton instance.
+ * Returns the XmlStringLookup singleton instance.
* <p>
- * Encodes strings according to the XML 1.0 specification.
+ * Looks up the value for the key in the format "DocumentPath:XPath".
* </p>
* <p>
- * For example: "<element>" becomes "&lt;element&gt;".
+ * For example: "com/domain/document.xml:/path/to/node".
* </p>
* <p>
* Using a {@link StringLookup} from the {@link StringLookupFactory}:
* </p>
*
* <pre>
- * StringLookupFactory.INSTANCE.xmlEncoderStringLookup().lookup("<element>");
+ * StringLookupFactory.INSTANCE.xmlStringLookup().lookup("com/domain/document.xml:/path/to/node");
* </pre>
* <p>
* Using a {@link StringSubstitutor}:
* </p>
*
* <pre>
- * StringSubstitutor.createInterpolator().replace("... ${xmlEncoder:<element>} ..."));
+ * StringSubstitutor.createInterpolator().replace("... ${xml:com/domain/document.xml:/path/to/node} ..."));
* </pre>
* <p>
- * The above examples convert {@code "<element>"} to {@code "<element>"}.
+ * The above examples convert {@code "com/domain/document.xml:/path/to/node"} to the value of the XPath in the XML
+ * document.
* </p>
*
- * @return The XmlEncoderStringLookup singleton instance.
+ * @param xPathFactoryFeatures XPathFactory features to set.
+ * @return The XmlStringLookup singleton instance.
+ * @see XPathFactory#setFeature(String, boolean)
* @since 1.11.0
*/
- public StringLookup xmlEncoderStringLookup() {
- return XmlEncoderStringLookup.INSTANCE;
+ public StringLookup xmlStringLookup(final Map<String, Boolean> xPathFactoryFeatures) {
+ return new XmlStringLookup(xPathFactoryFeatures);
}
}
diff --git a/src/main/java/org/apache/commons/text/numbers/DoubleFormat.java b/src/main/java/org/apache/commons/text/numbers/DoubleFormat.java
index cd42017b..6527574c 100644
--- a/src/main/java/org/apache/commons/text/numbers/DoubleFormat.java
+++ b/src/main/java/org/apache/commons/text/numbers/DoubleFormat.java
@@ -341,6 +341,24 @@ public enum DoubleFormat {
/** Default decimal digit characters. */
private static final String DEFAULT_DECIMAL_DIGITS = "0123456789";
+ /**
+ * Gets a string containing the localized digits 0-9 for the given symbols object. The string is constructed by starting at the
+ * {@link DecimalFormatSymbols#getZeroDigit() zero digit} and adding the next 9 consecutive characters.
+ *
+ * @param symbols symbols object
+ * @return string containing the localized digits 0-9
+ */
+ private static String getDigitString(final DecimalFormatSymbols symbols) {
+ final int zeroDelta = symbols.getZeroDigit() - DEFAULT_DECIMAL_DIGITS.charAt(0);
+
+ final char[] digitChars = new char[DEFAULT_DECIMAL_DIGITS.length()];
+ for (int i = 0; i < DEFAULT_DECIMAL_DIGITS.length(); ++i) {
+ digitChars[i] = (char) (DEFAULT_DECIMAL_DIGITS.charAt(i) + zeroDelta);
+ }
+
+ return String.valueOf(digitChars);
+ }
+
/** Function used to construct format instances. */
private final Function<Builder, DoubleFunction<String>> factory;
@@ -502,24 +520,6 @@ public enum DoubleFormat {
.minusSign(symbols.getMinusSign()).exponentSeparator(symbols.getExponentSeparator()).infinity(symbols.getInfinity()).nan(symbols.getNaN());
}
- /**
- * Gets a string containing the localized digits 0-9 for the given symbols object. The string is constructed by starting at the
- * {@link DecimalFormatSymbols#getZeroDigit() zero digit} and adding the next 9 consecutive characters.
- *
- * @param symbols symbols object
- * @return string containing the localized digits 0-9
- */
- private static String getDigitString(final DecimalFormatSymbols symbols) {
- final int zeroDelta = symbols.getZeroDigit() - DEFAULT_DECIMAL_DIGITS.charAt(0);
-
- final char[] digitChars = new char[DEFAULT_DECIMAL_DIGITS.length()];
- for (int i = 0; i < DEFAULT_DECIMAL_DIGITS.length(); ++i) {
- digitChars[i] = (char) (DEFAULT_DECIMAL_DIGITS.charAt(i) + zeroDelta);
- }
-
- return String.valueOf(digitChars);
- }
-
/**
* Sets the character used to separate groups of thousands. Default value is {@code ','}.
*
diff --git a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java
index 44efe51a..9fe1bb44 100644
--- a/src/test/java/org/apache/commons/text/TextStringBuilderTest.java
+++ b/src/test/java/org/apache/commons/text/TextStringBuilderTest.java
@@ -77,6 +77,28 @@ public class TextStringBuilderTest {
return 0;
};
+ /**
+ * Clear the string builder and fill up to the specified length.
+ *
+ * @param sb the string builder
+ * @param length the length
+ */
+ private static void fill(final TextStringBuilder sb, final int length) {
+ sb.clear();
+ // Some initial data.
+ final int limit = Math.min(64, length);
+ for (int i = 0; i < limit; i++) {
+ sb.append(' ');
+ }
+ // Fill by doubling
+ while (sb.length() * 2L <= length) {
+ sb.append(sb);
+ }
+ // Remaining fill
+ sb.append(sb, 0, length - sb.length());
+ assertEquals(length, sb.length(), "Expected the buffer to be full to the given length");
+ }
+
@Test
public void test_LANG_1131_EqualsWithNullTextStringBuilder() throws Exception {
final TextStringBuilder sb = new TextStringBuilder();
@@ -894,111 +916,6 @@ public class TextStringBuilderTest {
assertThrows(OutOfMemoryError.class, () -> sb.ensureCapacity(Integer.MAX_VALUE));
}
- @Test
- public void testOutOfMemoryError() {
- // This test is memory hungry requiring at least 7GiB of memory.
- // By default expansion will double the buffer size. If we repeat
- // add 1GiB of char data then we require at maximum:
- // 1GiB char[] data
- // 2GiB char[] buffer
- // ~4GiB char[] new buffer during reallocation
-
- // Attempts to guess the amount of free memory available using
- // the java.lang.Runtime/java.lang.management objects to
- // skip the test often did not work.
- // So here we just run the test and return a skip result if the
- // OutOfMemoryError occurs too early.
-
- final TextStringBuilder sb = new TextStringBuilder();
- sb.minimizeCapacity();
- assertEquals(0, sb.capacity());
-
- // 1GiB char[] buffer: length is roughly 1/4 the maximum array size
- final char[] chars = new char[1 << 29];
-
- // With infinite memory it should be possible to add this 3 times.
- try {
- for (int i = 0; i < 3; i++) {
- sb.append(chars);
- }
- } catch (OutOfMemoryError ignored) {
- Assumptions.abort("Not enough memory for the test");
- }
-
- // Now at 3/4 of the maximum array length.
- // Adding is not possible so we expect an OOM error.
- assertThrows(OutOfMemoryError.class, () -> sb.append(chars));
- }
-
- @Test
- public void testOutOfMemoryError2() {
- // This test is memory hungry requiring at least 4GiB of memory
- // in a single allocation. If not possible then skip the test.
-
- final TextStringBuilder sb = new TextStringBuilder();
- sb.minimizeCapacity();
- assertEquals(0, sb.capacity());
-
- // Allocate a lot
- final int small = 10;
- final int big = Integer.MAX_VALUE - small;
- final char[] extra = new char[small + 1];
- try {
- sb.ensureCapacity(big);
- } catch (OutOfMemoryError ignored) {
- Assumptions.abort("Not enough memory for the test");
- }
-
- fill(sb, big);
-
- // Adding more than the maximum array size is not possible so we expect an OOM error.
- assertThrows(OutOfMemoryError.class, () -> sb.append(extra));
- }
-
- @Test
- public void testOutOfMemoryError3() {
- // This test is memory hungry requiring at least 2GiB of memory
- // in a single allocation. If not possible then skip the test.
-
- final TextStringBuilder sb = new TextStringBuilder();
- sb.minimizeCapacity();
- assertEquals(0, sb.capacity());
-
- final int length = 1 << 30;
- try {
- sb.ensureCapacity(length);
- } catch (OutOfMemoryError ignored) {
- Assumptions.abort("Not enough memory for the test");
- }
-
- fill(sb, length);
-
- // Adding to itself requires a new buffer above the limits of an array
- assertThrows(OutOfMemoryError.class, () -> sb.append(sb));
- }
-
- /**
- * Clear the string builder and fill up to the specified length.
- *
- * @param sb the string builder
- * @param length the length
- */
- private static void fill(final TextStringBuilder sb, final int length) {
- sb.clear();
- // Some initial data.
- final int limit = Math.min(64, length);
- for (int i = 0; i < limit; i++) {
- sb.append(' ');
- }
- // Fill by doubling
- while (sb.length() * 2L <= length) {
- sb.append(sb);
- }
- // Remaining fill
- sb.append(sb, 0, length - sb.length());
- assertEquals(length, sb.length(), "Expected the buffer to be full to the given length");
- }
-
@Test
public void testEquals() {
final TextStringBuilder sb1 = new TextStringBuilder(50);
@@ -1593,6 +1510,89 @@ public class TextStringBuilderTest {
assertEquals(10, sb.capacity());
}
+ @Test
+ public void testOutOfMemoryError() {
+ // This test is memory hungry requiring at least 7GiB of memory.
+ // By default expansion will double the buffer size. If we repeat
+ // add 1GiB of char data then we require at maximum:
+ // 1GiB char[] data
+ // 2GiB char[] buffer
+ // ~4GiB char[] new buffer during reallocation
+
+ // Attempts to guess the amount of free memory available using
+ // the java.lang.Runtime/java.lang.management objects to
+ // skip the test often did not work.
+ // So here we just run the test and return a skip result if the
+ // OutOfMemoryError occurs too early.
+
+ final TextStringBuilder sb = new TextStringBuilder();
+ sb.minimizeCapacity();
+ assertEquals(0, sb.capacity());
+
+ // 1GiB char[] buffer: length is roughly 1/4 the maximum array size
+ final char[] chars = new char[1 << 29];
+
+ // With infinite memory it should be possible to add this 3 times.
+ try {
+ for (int i = 0; i < 3; i++) {
+ sb.append(chars);
+ }
+ } catch (OutOfMemoryError ignored) {
+ Assumptions.abort("Not enough memory for the test");
+ }
+
+ // Now at 3/4 of the maximum array length.
+ // Adding is not possible so we expect an OOM error.
+ assertThrows(OutOfMemoryError.class, () -> sb.append(chars));
+ }
+
+ @Test
+ public void testOutOfMemoryError2() {
+ // This test is memory hungry requiring at least 4GiB of memory
+ // in a single allocation. If not possible then skip the test.
+
+ final TextStringBuilder sb = new TextStringBuilder();
+ sb.minimizeCapacity();
+ assertEquals(0, sb.capacity());
+
+ // Allocate a lot
+ final int small = 10;
+ final int big = Integer.MAX_VALUE - small;
+ final char[] extra = new char[small + 1];
+ try {
+ sb.ensureCapacity(big);
+ } catch (OutOfMemoryError ignored) {
+ Assumptions.abort("Not enough memory for the test");
+ }
+
+ fill(sb, big);
+
+ // Adding more than the maximum array size is not possible so we expect an OOM error.
+ assertThrows(OutOfMemoryError.class, () -> sb.append(extra));
+ }
+
+ @Test
+ public void testOutOfMemoryError3() {
+ // This test is memory hungry requiring at least 2GiB of memory
+ // in a single allocation. If not possible then skip the test.
+
+ final TextStringBuilder sb = new TextStringBuilder();
+ sb.minimizeCapacity();
+ assertEquals(0, sb.capacity());
+
+ final int length = 1 << 30;
+ try {
+ sb.ensureCapacity(length);
+ } catch (OutOfMemoryError ignored) {
+ Assumptions.abort("Not enough memory for the test");
+ }
+
+ fill(sb, length);
+
+ // Adding to itself requires a new buffer above the limits of an array
+ assertThrows(OutOfMemoryError.class, () -> sb.append(sb));
+ }
+
@Test
public void testReadFromCharBuffer() throws Exception {
String s = "";
diff --git a/src/test/java/org/apache/commons/text/numbers/DoubleFormatTest.java b/src/test/java/org/apache/commons/text/numbers/DoubleFormatTest.java
index e05cec3b..b624bed4 100644
--- a/src/test/java/org/apache/commons/text/numbers/DoubleFormatTest.java
+++ b/src/test/java/org/apache/commons/text/numbers/DoubleFormatTest.java
@@ -186,6 +186,16 @@ public class DoubleFormatTest {
return randomDouble(Double.MIN_EXPONENT, Double.MAX_EXPONENT, rnd);
}
+ static Stream<Arguments> testMaximumPrecision() {
+ return Stream.of(
+ // Example of different Double.toString representations across JDKs
+ // JDK 17: -9.3540047119774374E17
+ // JDK 21: -9.354004711977437E17
+ Arguments.of(DoubleFormat.PLAIN.builder().build(), -9.3540047119774374E17),
+ Arguments.of(DoubleFormat.SCIENTIFIC.builder().build(), -9.3540047119774374E17)
+ );
+ }
+
/**
* Remove Unicode {@link Character#FORMAT format} characters from the given string.
* @param str input string
@@ -341,6 +351,21 @@ public class DoubleFormatTest {
checkFormatAccuracyWithDefaults(DoubleFormat.ENGINEERING);
}
+ /**
+ * Test formatting at the maximum precision. The formatting is based on the output
+ * of {@link Double#toString()}. If cannot create an extended precision text
+ * representation and is limited to 17 significant digits. This test verifies that
+ * formatting does not lose information that would be required to recreate the
+ * same double value.
+ */
+ @ParameterizedTest
+ @MethodSource
+ void testMaximumPrecision(DoubleFunction<String> fmt, double value) {
+ final String s = fmt.apply(value);
+ final double d = Double.parseDouble(s);
+ Assertions.assertEquals(value, d, () -> value + " formatted as " + s);
+ }
+
@Test
void testMixed_custom() {
// arrange
@@ -629,29 +654,4 @@ public class DoubleFormatTest {
.formatSymbols(DecimalFormatSymbols.getInstance(loc))
.build());
}
-
- /**
- * Test formatting at the maximum precision. The formatting is based on the output
- * of {@link Double#toString()}. If cannot create an extended precision text
- * representation and is limited to 17 significant digits. This test verifies that
- * formatting does not lose information that would be required to recreate the
- * same double value.
- */
- @ParameterizedTest
- @MethodSource
- void testMaximumPrecision(DoubleFunction<String> fmt, double value) {
- final String s = fmt.apply(value);
- final double d = Double.parseDouble(s);
- Assertions.assertEquals(value, d, () -> value + " formatted as " + s);
- }
-
- static Stream<Arguments> testMaximumPrecision() {
- return Stream.of(
- // Example of different Double.toString representations across JDKs
- // JDK 17: -9.3540047119774374E17
- // JDK 21: -9.354004711977437E17
- Arguments.of(DoubleFormat.PLAIN.builder().build(), -9.3540047119774374E17),
- Arguments.of(DoubleFormat.SCIENTIFIC.builder().build(), -9.3540047119774374E17)
- );
- }
}