Sort members

This commit is contained in:
Gary Gregory 2024-05-29 16:16:10 -04:00
parent 4b99af5ebf
commit a37e8de046
8 changed files with 92 additions and 92 deletions

View File

@ -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.
*

View File

@ -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.
* <p>
* If a {@link SecurityException} is caught, the return value is {@code null}.
* </p>
*
* @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.
* <p>
@ -3734,20 +3748,6 @@ static String getProperty(final String property, final Supplier<String> defaultI
}
}
/**
* Gets a System property, defaulting to {@code null} if the property cannot be read.
* <p>
* If a {@link SecurityException} is caught, the return value is {@code null}.
* </p>
*
* @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.
* <p>

View File

@ -31,21 +31,6 @@ public class Consumers {
@SuppressWarnings("rawtypes")
private static final Consumer NOP = Function.identity()::apply;
/**
* Gets the NOP Consumer singleton.
*
* @param <T> type type to consume.
* @return the NOP Consumer singleton.
*/
@SuppressWarnings("unchecked")
public static <T> Consumer<T> 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 <T> void accept(final T object, final Consumer<T> consumer) {
consumer.accept(object);
}
}
/**
* Gets the NOP Consumer singleton.
*
* @param <T> type type to consume.
* @return the NOP Consumer singleton.
*/
@SuppressWarnings("unchecked")
public static <T> Consumer<T> nop() {
return NOP;
}
private Consumers() {
// No instances.
}
}

View File

@ -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 <T> the type of the argument the function applies.
* @param <R> 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 <T, R> R apply(final T object, final Function<T, R> 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 <T, R> Function<T, R> function(final Function<T, R> 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 <T> the type of the argument the function applies.
* @param <R> 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 <T, R> R apply(final T object, final Function<T, R> function) {
return function != null ? function.apply(object) : null;
}
}

View File

@ -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

View File

@ -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<Object> c2 = Consumers.nop();
c2.accept(null);
final Consumer<String> c3 = Consumers.nop();
c3.accept(null);
//
Consumers.nop().accept(null);
Consumers.nop().accept("");
private static final class TestConsumer<T> implements Consumer<T> {
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<T> implements Consumer<T> {
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<Object> c2 = Consumers.nop();
c2.accept(null);
final Consumer<String> c3 = Consumers.nop();
c3.accept(null);
//
Consumers.nop().accept(null);
Consumers.nop().accept("");
}
}

View File

@ -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"));
}
}

View File

@ -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);