diff --git a/src/main/java/org/apache/commons/lang3/JavaVersion.java b/src/main/java/org/apache/commons/lang3/JavaVersion.java index 355b6ab6e..feb53bd16 100644 --- a/src/main/java/org/apache/commons/lang3/JavaVersion.java +++ b/src/main/java/org/apache/commons/lang3/JavaVersion.java @@ -183,6 +183,11 @@ public enum JavaVersion { */ JAVA_RECENT(maxVersion(), Float.toString(maxVersion())); + /** + * The regex to split version strings. + */ + private static final String VERSION_SPLIT_REGEX = "\\."; + /** * Transforms the given string with a Java version number to the * corresponding constant of this enumeration class. This method is used @@ -313,11 +318,6 @@ private static float toFloatVersion(final String value) { */ private final String name; - /** - * The regex to split version strings. - */ - private static final String VERSION_SPLIT_REGEX = "\\."; - /** * Constructs a new instance. * diff --git a/src/main/java/org/apache/commons/lang3/SystemProperties.java b/src/main/java/org/apache/commons/lang3/SystemProperties.java index 54137332d..1c2d03653 100644 --- a/src/main/java/org/apache/commons/lang3/SystemProperties.java +++ b/src/main/java/org/apache/commons/lang3/SystemProperties.java @@ -3708,6 +3708,20 @@ public static String getProperty(final String property) { return getProperty(property, Suppliers.nul()); } + /** + * Gets a System property, defaulting to {@code null} if the property cannot be read. + *

+ * If a {@link SecurityException} is caught, the return value is {@code null}. + *

+ * + * @param property the system property name. + * @param defaultIfAbsent use this value when the property is empty or throws SecurityException. + * @return the system property value or {@code null} if a security problem occurs + */ + static String getProperty(final String property, final String defaultIfAbsent) { + return getProperty(property, () -> defaultIfAbsent); + } + /** * Gets a System property, defaulting to {@code null} if the property cannot be read. *

@@ -3734,20 +3748,6 @@ static String getProperty(final String property, final Supplier defaultI } } - /** - * Gets a System property, defaulting to {@code null} if the property cannot be read. - *

- * If a {@link SecurityException} is caught, the return value is {@code null}. - *

- * - * @param property the system property name. - * @param defaultIfAbsent use this value when the property is empty or throws SecurityException. - * @return the system property value or {@code null} if a security problem occurs - */ - static String getProperty(final String property, final String defaultIfAbsent) { - return getProperty(property, () -> defaultIfAbsent); - } - /** * Gets the current value from the system properties map. *

diff --git a/src/main/java/org/apache/commons/lang3/function/Consumers.java b/src/main/java/org/apache/commons/lang3/function/Consumers.java index 43f161d07..49b514ec1 100644 --- a/src/main/java/org/apache/commons/lang3/function/Consumers.java +++ b/src/main/java/org/apache/commons/lang3/function/Consumers.java @@ -31,21 +31,6 @@ public class Consumers { @SuppressWarnings("rawtypes") private static final Consumer NOP = Function.identity()::apply; - /** - * Gets the NOP Consumer singleton. - * - * @param type type to consume. - * @return the NOP Consumer singleton. - */ - @SuppressWarnings("unchecked") - public static Consumer nop() { - return NOP; - } - - private Consumers() { - // No instances. - } - /** * Applies the given {@link Consumer} action to the object if the consumer is not {@code null}. Otherwise, does * nothing. @@ -60,4 +45,19 @@ public static void accept(final T object, final Consumer consumer) { consumer.accept(object); } } + + /** + * Gets the NOP Consumer singleton. + * + * @param type type to consume. + * @return the NOP Consumer singleton. + */ + @SuppressWarnings("unchecked") + public static Consumer nop() { + return NOP; + } + + private Consumers() { + // No instances. + } } diff --git a/src/main/java/org/apache/commons/lang3/function/Functions.java b/src/main/java/org/apache/commons/lang3/function/Functions.java index cf8309f8f..8d9313ca5 100644 --- a/src/main/java/org/apache/commons/lang3/function/Functions.java +++ b/src/main/java/org/apache/commons/lang3/function/Functions.java @@ -26,6 +26,21 @@ */ public final class Functions { + /** + * Applies the {@link Function} on the object if the function is not {@code null}. Otherwise, does nothing and + * returns {@code null}. + * + * @param object the object to apply the function. + * @param function the function to apply. + * @param the type of the argument the function applies. + * @param the type of the result the function returns. + * @return the value the function returns if the function is not {@code null}; {@code null} otherwise. + * @since 3.15.0 + */ + public static R apply(final T object, final Function function) { + return function != null ? function.apply(object) : null; + } + /** * Starts a fluent chain like {@code function(foo::bar).andThen(...).andThen(...).apply(...);} * @@ -41,19 +56,4 @@ public static Function function(final Function function) { private Functions() { // no instances needed. } - - /** - * Applies the {@link Function} on the object if the function is not {@code null}. Otherwise, does nothing and - * returns {@code null}. - * - * @param object the object to apply the function. - * @param function the function to apply. - * @param the type of the argument the function applies. - * @param the type of the result the function returns. - * @return the value the function returns if the function is not {@code null}; {@code null} otherwise. - * @since 3.15.0 - */ - public static R apply(final T object, final Function function) { - return function != null ? function.apply(object) : null; - } } diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTrimStripTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTrimStripTest.java index aa827ddf5..96aef4d64 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTrimStripTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTrimStripTest.java @@ -111,13 +111,13 @@ public void testStripAccentsIWithBar() { } @Test - public void testStripAccentsUWithBar() { - assertEquals("U u U u", StringUtils.stripAccents("\u0244 \u0289 \u1D7E \u1DB6")); + public void testStripAccentsTWithStroke() { + assertEquals("T t", StringUtils.stripAccents("\u0166 \u0167")); } @Test - public void testStripAccentsTWithStroke() { - assertEquals("T t", StringUtils.stripAccents("\u0166 \u0167")); + public void testStripAccentsUWithBar() { + assertEquals("U u U u", StringUtils.stripAccents("\u0244 \u0289 \u1D7E \u1DB6")); } @Test diff --git a/src/test/java/org/apache/commons/lang3/function/ConsumersTest.java b/src/test/java/org/apache/commons/lang3/function/ConsumersTest.java index 47828debf..e649c25db 100644 --- a/src/test/java/org/apache/commons/lang3/function/ConsumersTest.java +++ b/src/test/java/org/apache/commons/lang3/function/ConsumersTest.java @@ -31,22 +31,13 @@ */ public class ConsumersTest extends AbstractLangTest { - /** - * Tests {@link Consumers#nop()}. - */ - @Test - public void testNop() { - Stream.of("").forEach(Consumers.nop()); - // - final Consumer c1 = Consumers.nop(); - c1.accept(null); - final Consumer c2 = Consumers.nop(); - c2.accept(null); - final Consumer c3 = Consumers.nop(); - c3.accept(null); - // - Consumers.nop().accept(null); - Consumers.nop().accept(""); + private static final class TestConsumer implements Consumer { + private boolean isCalled; + + @Override + public void accept(T t) { + isCalled = true; + } } /** @@ -67,12 +58,21 @@ public void testAccept() { assertEquals("foo", builder2.toString()); } - private static final class TestConsumer implements Consumer { - private boolean isCalled; - - @Override - public void accept(T t) { - isCalled = true; - } + /** + * Tests {@link Consumers#nop()}. + */ + @Test + public void testNop() { + Stream.of("").forEach(Consumers.nop()); + // + final Consumer c1 = Consumers.nop(); + c1.accept(null); + final Consumer c2 = Consumers.nop(); + c2.accept(null); + final Consumer c3 = Consumers.nop(); + c3.accept(null); + // + Consumers.nop().accept(null); + Consumers.nop().accept(""); } } diff --git a/src/test/java/org/apache/commons/lang3/function/FunctionsTest.java b/src/test/java/org/apache/commons/lang3/function/FunctionsTest.java index 4693eb00a..8f5825134 100644 --- a/src/test/java/org/apache/commons/lang3/function/FunctionsTest.java +++ b/src/test/java/org/apache/commons/lang3/function/FunctionsTest.java @@ -29,14 +29,6 @@ */ public class FunctionsTest { - /** - * Tests {@link Functions#function(Function)}. - */ - @Test - public void testFunction() { - assertEquals("foo", Functions.function(String::valueOf).andThen(String::toString).apply("foo")); - } - /** * Tests {@link Functions#apply(Object, Function)}. */ @@ -46,4 +38,12 @@ public void testApply() { assertEquals("foo-bar", Functions.apply(null, object -> "foo-bar")); assertNull(Functions.apply("foo", null)); } + + /** + * Tests {@link Functions#function(Function)}. + */ + @Test + public void testFunction() { + assertEquals("foo", Functions.function(String::valueOf).andThen(String::toString).apply("foo")); + } } diff --git a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java index 29404044d..46f46630c 100644 --- a/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/math/NumberUtilsTest.java @@ -141,14 +141,6 @@ private boolean isParsableByte(final String s) { return parsable; } - private boolean isParsableFloat(final String s) { - final boolean parsable = NumberUtils.isParsable(s); - assertTrue(isNumberFormatParsable(s), s); - assertTrue(isNumberIntegerOnlyFormatParsable(s), s); - assertEquals(parsable, isApplyNonNull(s, Float::parseFloat), s); - return parsable; - } - private boolean isParsableDouble(final String s) { final boolean parsable = NumberUtils.isParsable(s); assertTrue(isNumberFormatParsable(s), s); @@ -157,6 +149,14 @@ private boolean isParsableDouble(final String s) { return parsable; } + private boolean isParsableFloat(final String s) { + final boolean parsable = NumberUtils.isParsable(s); + assertTrue(isNumberFormatParsable(s), s); + assertTrue(isNumberIntegerOnlyFormatParsable(s), s); + assertEquals(parsable, isApplyNonNull(s, Float::parseFloat), s); + return parsable; + } + private boolean isParsableInteger(final String s) { final boolean parsable = NumberUtils.isParsable(s); assertTrue(isNumberFormatParsable(s), s);