Internal refactoring

This commit is contained in:
Gary Gregory 2024-05-12 15:42:37 -04:00
parent b9f15bc007
commit b7b52fc506
3 changed files with 3 additions and 1 deletions

View File

@ -128,6 +128,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate SystemUtils.getUserName(String) in favor of SystemProperties.getUserName(Supplier).</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LockVisitor.acceptReadLocked(FailableConsumer) null-safe.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make LockVisitor.applyWriteLocked(FailableConsumer) null-safe.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Make ObjectUtils.getFirstNonNull(Supplier...) null-safe.</action>
<!-- UPDATE -->
<action type="update" dev="sebb" due-to="Dependabot">Bump commons-parent from 64 to 69 #1194.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump org.codehaus.mojo:exec-maven-plugin from 3.1.1 to 3.2.0 #1175.</action>

View File

@ -689,7 +689,7 @@ public class ObjectUtils {
*/
@SafeVarargs
public static <T> T getFirstNonNull(final Supplier<T>... suppliers) {
return Streams.of(suppliers).map(s -> s != null ? s.get() : null).filter(Objects::nonNull).findFirst().orElse(null);
return Streams.of(suppliers).filter(Objects::nonNull).map(Supplier::get).filter(Objects::nonNull).findFirst().orElse(null);
}
/**

View File

@ -480,6 +480,7 @@ public class ObjectUtilsTest extends AbstractLangTest {
@Test
public void testGetFirstNonNull() {
// first non-null
assertEquals("", ObjectUtils.getFirstNonNull(null, () -> ""));
assertEquals("", ObjectUtils.getFirstNonNull(Suppliers.nul(), () -> ""));
// first encountered value is used
assertEquals("1", ObjectUtils.getFirstNonNull(Suppliers.nul(), () -> "1", () -> "2", Suppliers.nul()));