Skip to content

Commit

Permalink
gh-194: Fix imports and change usages of requireNonNullOrElseGet to r…
Browse files Browse the repository at this point in the history
…equireNonNullElse.
  • Loading branch information
t511203 committed Feb 7, 2022
1 parent 5463b94 commit 38b3957
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/uk/gov/gchq/koryphe/impl/function/If.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate;
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;

import static java.util.Objects.requireNonNullElse;
import static uk.gov.gchq.koryphe.util.Util.arr;

/**
Expand Down Expand Up @@ -82,7 +82,7 @@ public class If<I, O> extends KorypheFunction<I, O> {
*/
@Override
public O apply(final I input) {
if (Objects.requireNonNullElseGet(condition, () -> null != predicate && predicate.test(input))) {
if (requireNonNullElse(condition, null != predicate && predicate.test(input))) {
if (null != then) {
return then.apply(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.function.KorypheFunction;

import java.util.Objects;
import static java.util.Objects.requireNonNullElse;

/**
* A {@code StringAppend} is a {@link java.util.function.Function} which takes a input {@link String} and returns the
Expand Down Expand Up @@ -61,7 +61,7 @@ public String getSuffix() {
}

public void setSuffix(final String suffix) {
this.suffix = Objects.requireNonNullElse(suffix, StringUtils.EMPTY);
this.suffix = requireNonNullElse(suffix, StringUtils.EMPTY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.function.KorypheFunction;

import java.util.Objects;
import static java.util.Objects.requireNonNullElse;

/**
* A {@code StringPrepend} is a {@link java.util.function.Function} which takes a input {@link String} and returns the
Expand Down Expand Up @@ -59,7 +59,7 @@ public String getPrefix() {
}

public void setPrefix(final String prefix) {
this.prefix = Objects.requireNonNullElse(prefix, StringUtils.EMPTY);
this.prefix = requireNonNullElse(prefix, StringUtils.EMPTY);
}

@Override
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/If.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate;
import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate;

import java.util.Objects;
import java.util.function.Predicate;

import static java.util.Objects.requireNonNullElse;

/**
* An {@code If} is a {@link Predicate} that conditionally applies one of two predicates to a provided input.
* <p> Note that the <code>If</code> has both a number of constructors as well as a <code>Builder</code>.
Expand Down Expand Up @@ -137,7 +138,7 @@ public If(final Predicate<? super I> predicate, final Predicate<? super I> then,
*/
@Override
public boolean test(final I input) {
if (Objects.requireNonNullElseGet(condition, () -> null != predicate && predicate.test(input))) {
if (requireNonNullElse(condition, null != predicate && predicate.test(input))) {
return null != then && then.test(input);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import uk.gov.gchq.koryphe.function.KorypheFunction;

import java.util.Arrays;
import java.util.Objects;

import static java.util.Objects.requireNonNullElse;

/**
* @param <R> The type of reference used by tuples.
Expand Down Expand Up @@ -81,7 +82,7 @@ public R[] getSelection() {
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Cloning the array would be expensive - we will have to reply on users not modifying the array")
public void setSelection(final R[] selection) {
this.selection = Objects.requireNonNullElseGet(selection, () -> (R[]) new Object[0]);
this.selection = requireNonNullElse(selection, (R[]) new Object[0]);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
import uk.gov.gchq.koryphe.Summary;

import java.util.Arrays;
import java.util.Objects;
import java.util.function.BiFunction;

import static java.util.Objects.requireNonNullElse;

/**
* @param <R> The type of reference used by tuples.
* @param <FO> The adapted output type.
Expand Down Expand Up @@ -81,7 +82,7 @@ public Tuple<R> apply(final Tuple<R> state, final FO output) {
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "Cloning the array would be expensive - we will have to reply on users not modifying the array")
public void setProjection(final R[] projection) {
this.projection = Objects.requireNonNullElseGet(projection, () -> (R[]) new Object[0]);
this.projection = requireNonNullElse(projection, (R[]) new Object[0]);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/java/uk/gov/gchq/koryphe/util/IterableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Predicate;

import static java.util.Objects.requireNonNullElse;

/**
* An {@code IterableUtil} is a utility class providing capabilities for:
* <ul>
Expand Down Expand Up @@ -348,7 +349,7 @@ private LimitedIterable(final Iterable<T> iterable, final int start, final Integ
throw new IllegalArgumentException("The start pointer must be less than the end pointer.");
}

this.iterable = Objects.requireNonNullElse(iterable, Collections.emptyList());
this.iterable = requireNonNullElse(iterable, Collections.emptyList());

this.start = start;
this.end = end;
Expand Down Expand Up @@ -390,7 +391,7 @@ private LimitedIterator(final Iterator<T> iterator, final int start, final Integ
throw new IllegalArgumentException("start should be less than end");
}

this.iterator = Objects.requireNonNullElse(iterator, Collections.emptyIterator());
this.iterator = requireNonNullElse(iterator, Collections.emptyIterator());
this.end = end;
this.truncate = truncate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.koryphe.util.EqualityTest;
import uk.gov.gchq.koryphe.Since;
import uk.gov.gchq.koryphe.Summary;
import uk.gov.gchq.koryphe.signature.Signature;
import uk.gov.gchq.koryphe.util.EqualityTest;
import uk.gov.gchq.koryphe.util.SummaryUtil;
import uk.gov.gchq.koryphe.util.VersionUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void shouldCast() {
final Cast function = new Cast(Integer.class);

// When
Object output = function.apply(Long.valueOf(5L));
Object output = function.apply(5L);

// Then
assertEquals(Integer.class, output.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.io.IOException;
import java.util.Collections;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.koryphe.function.FunctionTest;
import uk.gov.gchq.koryphe.util.JsonSerialiser;

Expand All @@ -13,7 +14,8 @@
import java.util.TimeZone;
import java.util.function.Function;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class ToDateStringTest extends FunctionTest<ToDateString> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package uk.gov.gchq.koryphe.impl.function;

import org.junit.jupiter.api.Test;

import uk.gov.gchq.koryphe.function.FunctionTest;
import uk.gov.gchq.koryphe.util.JsonSerialiser;

Expand All @@ -36,9 +37,7 @@ public void shouldThrowException() {
final ToDouble function = new ToDouble();

// When
Exception exception = assertThrows(IllegalArgumentException.class, () -> {
function.apply(true);
});
Exception exception = assertThrows(IllegalArgumentException.class, () -> function.apply(true));

String expectedMessage = "Could not convert value to Double: ";
String actualMessage = exception.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void shouldConvertToInteger() {
final ToInteger function = new ToInteger();

// When
Object output = function.apply(Long.valueOf(5L));
Object output = function.apply(5L);

// Then
assertEquals(5, output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package uk.gov.gchq.koryphe.impl.function;

import org.apache.commons.io.Charsets;
import org.junit.jupiter.api.Test;

import uk.gov.gchq.koryphe.function.FunctionTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.function.Predicate;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public void shouldCheckApplyBiFunctionTypes() {
@Test
public void shouldCheckApplyBiFunctionTypesForInlineBiFunction() {
// Given
final BiFunction<Long, Double, String> inlineBiFunction = new BiFunction<Long, Double, String>() {
final BiFunction<Long, Double, String> inlineBiFunction = new BiFunction<>() {
@Override
public String apply(final Long l, final Double d) {
return Long.toString(l).concat(Double.toString(d));
Expand Down

0 comments on commit 38b3957

Please sign in to comment.