diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstItem.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstItem.java index 6c691a629..bc21cbd26 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstItem.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code FirstItem} is a {@link KorypheFunction} that returns the first item from a provided @@ -40,7 +40,7 @@ public T apply(final Iterable input) { throw new IllegalArgumentException("Input cannot be null"); } try { - return Iterables.getFirst(input, null); + return IterableUtil.getFirst(input); } finally { CloseableUtil.close(input); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstValid.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstValid.java index 6c4553b50..2d88b6a19 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstValid.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FirstValid.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package uk.gov.gchq.koryphe.impl.function; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Iterables; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -25,6 +24,7 @@ import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; import java.util.function.Predicate; @@ -53,7 +53,7 @@ public FirstValid(final Predicate predicate) { public I_ITEM apply(final Iterable iterable) { if (nonNull(iterable) && nonNull(predicate)) { try { - return Iterables.getFirst(filter(iterable, predicate), null); + return IterableUtil.getFirst(filter(iterable, predicate)); } finally { CloseableUtil.close(iterable); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FunctionChain.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FunctionChain.java index a91071ed6..50e8111dc 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FunctionChain.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/FunctionChain.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2022 Crown Copyright + * Copyright 2019-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package uk.gov.gchq.koryphe.impl.function; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Lists; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; @@ -25,6 +24,7 @@ import uk.gov.gchq.koryphe.tuple.function.TupleAdaptedFunction; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -43,7 +43,7 @@ public FunctionChain() { } public FunctionChain(final Function... functions) { - this(Lists.newArrayList(functions)); + this(Arrays.asList(functions)); } public FunctionChain(final List functions) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/IsEmpty.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/IsEmpty.java index e482a5edb..946bb7d15 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/IsEmpty.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/IsEmpty.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code IsEmpty} is a {@link KorypheFunction} which returns a boolean based @@ -38,7 +38,7 @@ public Boolean apply(final Iterable input) { throw new IllegalArgumentException("Input cannot be null"); } try { - return Iterables.isEmpty(input); + return IterableUtil.isEmpty(input); } finally { CloseableUtil.close(input); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/LastItem.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/LastItem.java index 5411b64a7..3bb8dea95 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/LastItem.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/LastItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code LastItem} is a {@link KorypheFunction} that returns the last item from a provided @@ -41,7 +41,7 @@ public T apply(final Iterable input) { throw new IllegalArgumentException("Input cannot be null"); } try { - return Iterables.getLast(input, null); + return IterableUtil.getLast(input); } finally { CloseableUtil.close(input); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Length.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Length.java index c442f238a..283fbdda2 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Length.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Length.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -58,9 +57,9 @@ public Integer apply(final Object value) { length = ((Object[]) value).length; } else if (value instanceof Iterable) { if (null != maxLength) { - length = Iterables.size(IterableUtil.limit((Iterable) value, 0, maxLength, true)); + length = IterableUtil.size(IterableUtil.limit((Iterable) value, 0, maxLength, true)); } else { - length = Iterables.size((Iterable) value); + length = IterableUtil.size((Iterable) value); } } else if (value instanceof Map) { length = ((Map) value).size(); diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/NthItem.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/NthItem.java index 3038a16a4..0bbdcb5cf 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/NthItem.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/NthItem.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -25,6 +24,7 @@ import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code NthItem} is a {@link KorypheFunction} that returns an item based on user selection, @@ -53,7 +53,7 @@ public T apply(final Iterable input) { throw new IllegalArgumentException("Input cannot be null"); } try { - return Iterables.get(input, selection); + return IterableUtil.toList(input).get(selection); } finally { CloseableUtil.close(input); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Size.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Size.java index 91a169753..7658e862b 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Size.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/Size.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.util.CloseableUtil; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code Size} is a {@link KorypheFunction} which returns the size of a provided @@ -38,7 +38,7 @@ public Integer apply(final Iterable input) { throw new IllegalArgumentException("Input cannot be null"); } try { - return Iterables.size(input); + return IterableUtil.size(input); } finally { CloseableUtil.close(input); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToArray.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToArray.java index a7fda7f7d..142d62182 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToArray.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToArray.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; - import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; +import uk.gov.gchq.koryphe.util.IterableUtil; /** * A {@code ToArray} is a {@link java.util.function.Function} that takes @@ -43,7 +42,7 @@ public Object[] apply(final Object value) { } if (value instanceof Iterable) { - return Iterables.toArray(((Iterable) value), Object.class); + return IterableUtil.toList(((Iterable) value)).toArray(); } return new Object[]{value}; diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToBytes.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToBytes.java index 2747f1fa1..6ade83c2a 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToBytes.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToBytes.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Crown Copyright + * Copyright 2019-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; -import com.google.common.base.Charsets; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -30,6 +29,7 @@ import java.nio.charset.Charset; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.isNull; import static java.util.Objects.nonNull; @@ -41,7 +41,7 @@ @Since("1.8.0") @Summary("Extracts the bytes from a string") public class ToBytes extends KorypheFunction { - public static final Charset DEFAULT_CHARSET = Charsets.UTF_8; + public static final Charset DEFAULT_CHARSET = UTF_8; @JsonInclude(JsonInclude.Include.NON_DEFAULT) private Charset charset; diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToList.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToList.java index b0be16262..aafee889a 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToList.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToList.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; - import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; +import uk.gov.gchq.koryphe.util.IterableUtil; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -37,20 +38,17 @@ public class ToList extends KorypheFunction> { @Override public List apply(final Object value) { if (null == value) { - return Lists.newArrayList((Object) null); + return Arrays.asList((Object) null); } if (value instanceof Object[]) { - return Lists.newArrayList((Object[]) value); + return new ArrayList<>(Arrays.asList((Object[]) value)); } if (value instanceof Iterable) { - if (value instanceof List) { - return (List) value; - } - return Lists.newArrayList((Iterable) value); + return IterableUtil.toList((Iterable) value); } - return Lists.newArrayList(value); + return new ArrayList<>(Arrays.asList(value)); } } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToSet.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToSet.java index 1ad1077ce..fb183fc9c 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToSet.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToSet.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,14 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; -import com.google.common.collect.Sets; import uk.gov.gchq.koryphe.Since; import uk.gov.gchq.koryphe.Summary; import uk.gov.gchq.koryphe.function.KorypheFunction; import uk.gov.gchq.koryphe.serialisation.json.SimpleClassNameIdResolver; +import uk.gov.gchq.koryphe.util.IterableUtil; +import java.util.Arrays; import java.util.HashSet; import java.util.Set; import java.util.TreeSet; @@ -76,9 +77,9 @@ public Set apply(final Object value) { } else if (implementation.isInstance(value)) { return (Set) value; } else if (value instanceof Object[]) { - setImpl.addAll(Sets.newHashSet((Object[]) value)); + setImpl.addAll(new HashSet<>(Arrays.asList((Object[]) value))); } else if (value instanceof Iterable) { - setImpl.addAll(Sets.newHashSet((Iterable) value)); + setImpl.addAll(new HashSet<>(IterableUtil.toList((Iterable) value))); } else { setImpl.add(value); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToString.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToString.java index 5f2e8ea94..e98307bb9 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToString.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/function/ToString.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSetter; -import com.google.common.base.Charsets; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -30,6 +29,7 @@ import java.nio.charset.Charset; import java.util.Arrays; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.nonNull; /** @@ -40,7 +40,7 @@ @Since("1.0.0") @Summary("Calls ToString on an object") public class ToString extends KorypheFunction { - public static final Charset DEFAULT_CHARSET = Charsets.UTF_8; + public static final Charset DEFAULT_CHARSET = UTF_8; private Charset charset; diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/And.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/And.java index 47d14eaec..7685b827b 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/And.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/And.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package uk.gov.gchq.koryphe.impl.predicate; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Lists; import org.apache.commons.lang3.builder.ToStringBuilder; import uk.gov.gchq.koryphe.Since; @@ -25,6 +24,7 @@ import uk.gov.gchq.koryphe.predicate.PredicateComposite; import uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate; +import java.util.Arrays; import java.util.List; import java.util.function.Predicate; @@ -42,7 +42,7 @@ public And() { } public And(final Predicate... predicates) { - this(Lists.newArrayList(predicates)); + this(Arrays.asList(predicates)); } public And(final List predicates) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/AreIn.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/AreIn.java index 2e4f1578a..1ab5a2afb 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/AreIn.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/AreIn.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Sets; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -62,7 +61,7 @@ public AreIn(final Collection allowedValues, final boolean nullOrEmptyAllowed } public AreIn(final Object... allowedValues) { - this.allowedValues = Sets.newHashSet(allowedValues); + this.allowedValues = new HashSet<>(Arrays.asList(allowedValues)); } @JsonIgnore diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/IsIn.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/IsIn.java index e5300b63e..a9805fd14 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/IsIn.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/IsIn.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Sets; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -51,7 +50,7 @@ public IsIn(final Collection controlData) { } public IsIn(final Object... controlData) { - this.allowedValues = Sets.newHashSet(controlData); + this.allowedValues = new HashSet<>(Arrays.asList(controlData)); } @JsonTypeInfo(use = JsonTypeInfo.Id.CLASS, include = JsonTypeInfo.As.WRAPPER_OBJECT) diff --git a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/Or.java b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/Or.java index 8cf5f1b39..14a71398a 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/Or.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/impl/predicate/Or.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,6 @@ package uk.gov.gchq.koryphe.impl.predicate; import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.google.common.collect.Lists; import org.apache.commons.lang3.builder.ToStringBuilder; import uk.gov.gchq.koryphe.Since; @@ -27,6 +26,7 @@ import uk.gov.gchq.koryphe.tuple.predicate.IntegerTupleAdaptedPredicate; import uk.gov.gchq.koryphe.tuple.predicate.TupleAdaptedPredicate; +import java.util.Arrays; import java.util.List; import java.util.function.Predicate; @@ -44,7 +44,7 @@ public Or() { } public Or(final Predicate... predicates) { - this(Lists.newArrayList(predicates)); + this(Arrays.asList(predicates)); } public Or(final List predicates) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/iterable/FilteredIterable.java b/core/src/main/java/uk/gov/gchq/koryphe/iterable/FilteredIterable.java index 14e3905d3..371f1fd17 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/iterable/FilteredIterable.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/iterable/FilteredIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package uk.gov.gchq.koryphe.iterable; -import com.google.common.collect.Lists; - import uk.gov.gchq.koryphe.util.CloseableUtil; import java.io.Closeable; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -38,7 +37,7 @@ public class FilteredIterable implements Closeable, Iterable { private final List predicates; public FilteredIterable(final Iterable iterable, final Predicate... predicates) { - this(iterable, Lists.newArrayList(predicates)); + this(iterable, Arrays.asList(predicates)); } public FilteredIterable(final Iterable iterable, final List predicates) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/iterable/MappedIterable.java b/core/src/main/java/uk/gov/gchq/koryphe/iterable/MappedIterable.java index c45a51ec5..cc3660b22 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/iterable/MappedIterable.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/iterable/MappedIterable.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package uk.gov.gchq.koryphe.iterable; -import com.google.common.collect.Lists; - import uk.gov.gchq.koryphe.util.CloseableUtil; import java.io.Closeable; +import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -39,7 +38,7 @@ public class MappedIterable implements Closeable, Iterable functions; public MappedIterable(final Iterable iterable, final Function... functions) { - this(iterable, Lists.newArrayList(functions)); + this(iterable, Arrays.asList(functions)); } public MappedIterable(final Iterable iterable, final List functions) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/serialisation/json/SimpleClassNameCache.java b/core/src/main/java/uk/gov/gchq/koryphe/serialisation/json/SimpleClassNameCache.java index 85afd8edf..fa52113d3 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/serialisation/json/SimpleClassNameCache.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/serialisation/json/SimpleClassNameCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,13 +17,14 @@ package uk.gov.gchq.koryphe.serialisation.json; import com.fasterxml.jackson.databind.JavaType; -import com.google.common.collect.Sets; import org.apache.commons.lang3.StringUtils; import uk.gov.gchq.koryphe.util.JavaUtils; import uk.gov.gchq.koryphe.util.ReflectionUtil; +import java.util.Arrays; import java.util.Comparator; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -189,7 +190,7 @@ public static String getSimpleClassNameOrNull(final Class clazz) { final Package classPackage = nonArrayClass.getPackage(); if (null != classPackage && corePackages.contains(classPackage.getName())) { // Found the class, so cache the result for next time. - addIdClasses(id, Sets.newHashSet(nonArrayClass)); + addIdClasses(id, new HashSet<>(Arrays.asList((nonArrayClass)))); } else { id = null; } @@ -244,7 +245,7 @@ public static String getClassName(final String id, final JavaType baseType) { final Class clazz = ReflectionUtil.getClassFromName(classNameTmp); if (null != clazz) { className = classNameTmp; - addIdClasses(nonArrayId, Sets.newHashSet(clazz)); + addIdClasses(nonArrayId, new HashSet<>(Arrays.asList(clazz))); break; } } @@ -354,7 +355,7 @@ private static void addSimpleClassName(final Map> map, final final String id = StringUtils.capitalize(clazz.getSimpleName()); final Set value = map.get(id); if (null == value) { - map.put(id, Sets.newHashSet(clazz)); + map.put(id, new HashSet<>(Arrays.asList(clazz))); } else { value.add(clazz); } @@ -366,7 +367,7 @@ private static void addSimpleClassNames(final Map> map, final final String id = StringUtils.capitalize(entry.getKey()); final Set value = map.get(id); if (null == value) { - map.put(id, Sets.newHashSet(entry.getValue())); + map.put(id, entry.getValue()); } else { value.addAll(entry.getValue()); } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/tuple/ArrayTuple.java b/core/src/main/java/uk/gov/gchq/koryphe/tuple/ArrayTuple.java index a1477c7d5..44e58c252 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/tuple/ArrayTuple.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/tuple/ArrayTuple.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,13 @@ package uk.gov.gchq.koryphe.tuple; -import com.google.common.collect.Iterables; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; +import uk.gov.gchq.koryphe.util.IterableUtil; + import java.util.Arrays; import java.util.Iterator; @@ -43,7 +44,7 @@ public ArrayTuple(final Object... values) { } public ArrayTuple(final Iterable values) { - this(Iterables.toArray(values, Object.class)); + this(IterableUtil.toList(values).toArray()); } /** diff --git a/core/src/main/java/uk/gov/gchq/koryphe/util/IterableUtil.java b/core/src/main/java/uk/gov/gchq/koryphe/util/IterableUtil.java index 3aadc445c..9b17de460 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/util/IterableUtil.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/util/IterableUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,14 @@ import uk.gov.gchq.koryphe.iterable.LimitedIterable; import uk.gov.gchq.koryphe.iterable.MappedIterable; +import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.StreamSupport; /** * An {@code IterableUtil} is a utility class providing capabilities for: @@ -87,4 +91,35 @@ public static Iterable limit(final Iterable iterable, final int start, return new LimitedIterable<>(iterable, start, end, truncate); } + public static int size(final Iterable iterable) { + if (iterable instanceof Collection) { + return ((Collection) iterable).size(); + } + return (int) StreamSupport.stream(iterable.spliterator(), false).count(); + } + + public static List toList(final Iterable iterable) { + if (iterable instanceof List) { + return (List) iterable; + } + if (iterable instanceof Set) { + return new ArrayList<>((Set) iterable); + } + List asList = new ArrayList<>(); + iterable.forEach(asList::add); + return asList; + } + + public static boolean isEmpty(final Iterable iterable) { + return size(iterable) == 0; + } + + public static T getFirst(final Iterable iterable) { + return iterable.iterator().next(); + } + + public static T getLast(final Iterable iterable) { + List list = toList(iterable); + return list.get(list.size() - 1); + } } diff --git a/core/src/main/java/uk/gov/gchq/koryphe/util/JavaUtils.java b/core/src/main/java/uk/gov/gchq/koryphe/util/JavaUtils.java index c115abbf2..9f9970c6a 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/util/JavaUtils.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/util/JavaUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package uk.gov.gchq.koryphe.util; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; @@ -41,7 +42,7 @@ public static class Set { @SafeVarargs public static java.util.Set of(final T... item) { - return Collections.unmodifiableSet(com.google.common.collect.Sets.newHashSet(item)); + return Collections.unmodifiableSet(new HashSet<>(Arrays.asList(item))); } public static java.util.Set copyOf(final java.util.Set set) { diff --git a/core/src/main/java/uk/gov/gchq/koryphe/util/ReflectionUtil.java b/core/src/main/java/uk/gov/gchq/koryphe/util/ReflectionUtil.java index 69b731527..e46a8a83f 100644 --- a/core/src/main/java/uk/gov/gchq/koryphe/util/ReflectionUtil.java +++ b/core/src/main/java/uk/gov/gchq/koryphe/util/ReflectionUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package uk.gov.gchq.koryphe.util; -import com.google.common.collect.Sets; import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner; import java.lang.annotation.Annotation; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -209,7 +209,7 @@ public static void addReflectionPackages(final String... newPackages) { if (1 == newPackages.length) { addReflectionPackages(Collections.singleton(newPackages[0])); } else { - addReflectionPackages(Sets.newHashSet(newPackages)); + addReflectionPackages(new HashSet<>(Arrays.asList(newPackages))); } } } diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DefaultIfEmptyTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DefaultIfEmptyTest.java index e968a8b4f..fdebc86d8 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DefaultIfEmptyTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DefaultIfEmptyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -101,7 +101,7 @@ public void shouldReturnDefaultValueIfEmpty() { @Test public void shouldReturnOriginalValueIfNotEmpty() { // Given - final List iterable = Lists.newArrayList("first", "second"); + final List iterable = Arrays.asList("first", "second"); final DefaultIfEmpty defaultIfEmpty = new DefaultIfEmpty(DEFAULT_VALUE); // When diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DictionaryLookupTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DictionaryLookupTest.java index c1c38162b..988a7acf8 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DictionaryLookupTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/DictionaryLookupTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Crown Copyright + * Copyright 2019-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Maps; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -82,7 +81,7 @@ protected DictionaryLookup getInstance() { protected Iterable> getDifferentInstancesOrNull() { return Arrays.asList( new DictionaryLookup<>(null), - new DictionaryLookup<>(Maps.newHashMap()) + new DictionaryLookup<>(new HashMap<>()) ); } diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ExtractValuesTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ExtractValuesTest.java index e9eee0571..9be1d2199 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ExtractValuesTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ExtractValuesTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Iterables; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/FunctionChainTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/FunctionChainTest.java index 56266d7ce..85c3073be 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/FunctionChainTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/FunctionChainTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Crown Copyright + * Copyright 2019-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; @@ -25,6 +24,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.HashSet; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.InstanceOfAssertFactories.ARRAY; @@ -98,7 +98,7 @@ public void shouldApplyAllTupleFunctions() { assertThat(result) .extracting("values") .asInstanceOf(ARRAY) - .containsExactly("someString", "SOMESTRING", Sets.newHashSet("SOMESTRING")); + .containsExactly("someString", "SOMESTRING", new HashSet<>(Arrays.asList("SOMESTRING"))); } @Test diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IsEmptyTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IsEmptyTest.java index 39ce996c6..7e3240c60 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IsEmptyTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IsEmptyTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; @@ -24,6 +23,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.HashSet; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -74,7 +74,7 @@ public void shouldJsonSerialiseAndDeserialise() throws IOException { public void shouldReturnTrueForEmptyIterable() { // Given final IsEmpty function = new IsEmpty(); - final Iterable input = Sets.newHashSet(); + final Iterable input = new HashSet<>(Arrays.asList()); // When final Boolean result = function.apply(input); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFilterTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFilterTest.java index 7c0cccf3b..cf1297594 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFilterTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFilterTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFlattenTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFlattenTest.java index c4a96a30a..f7aca9e75 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFlattenTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableFlattenTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; @@ -26,7 +24,9 @@ import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -51,7 +51,7 @@ public void shouldHandleNullInput() { public void shouldFlattenIterableNumbers() { // Given final IterableFlatten function = new IterableFlatten<>(new Sum()); - final List input = Lists.newArrayList(1, 2, 3, 4, 5); + final List input = Arrays.asList(1, 2, 3, 4, 5); // When final Number result = function.apply(input); @@ -64,7 +64,7 @@ public void shouldFlattenIterableNumbers() { public void shouldFlattenIterableNumbersWithNull() { // Given final IterableFlatten function = new IterableFlatten<>(new Sum()); - final List input = Lists.newArrayList(2, 4, 6, 8, null, 10); + final List input = Arrays.asList(2, 4, 6, 8, null, 10); // When final Number result = function.apply(input); @@ -76,7 +76,7 @@ public void shouldFlattenIterableNumbersWithNull() { public void shouldFlattenIterableNumbersAllNull() { // Given final IterableFlatten function = new IterableFlatten<>(new Sum()); - final List input = Lists.newArrayList(null, null, null, null); + final List input = Arrays.asList(null, null, null, null); // When final Number result = function.apply(input); @@ -89,7 +89,7 @@ public void shouldFlattenIterableNumbersAllNull() { public void shouldFlattenIterableStrings() { // Given final IterableFlatten function = new IterableFlatten<>((a, b) -> a + b); - final Set input = Sets.newHashSet("a", "b", "c"); + final Set input = new HashSet<>(Arrays.asList("a", "b", "c")); // When final String result = function.apply(input); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableLongestTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableLongestTest.java index 4d63896af..f97b26382 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableLongestTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/IterableLongestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,13 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -45,7 +45,7 @@ public void shouldHandleNullInput() { public void shouldGetLongestItemFromList() { // Given final IterableLongest function = getInstance(); - final List list = Lists.newArrayList("a", "ab", "abc"); + final List list = Arrays.asList("a", "ab", "abc"); // When final Object result = function.apply(list); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/LongestTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/LongestTest.java index d70a474f3..86a7bc165 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/LongestTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/LongestTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2022 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,16 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -92,8 +92,8 @@ public void shouldReturnLongestObjectArrayInput() { public void shouldReturnLongestListInput() { // Given final Longest> function = new Longest<>(); - final List input1 = Lists.newArrayList(1); - final List input2 = Lists.newArrayList(1, 2, 3); + final List input1 = Arrays.asList(1); + final List input2 = Arrays.asList(1, 2, 3); // When final List result = function.apply(input1, input2); @@ -106,8 +106,8 @@ public void shouldReturnLongestListInput() { public void shouldReturnLongestSetInput() { // Given final Longest> function = new Longest<>(); - final Set input1 = Sets.newHashSet(1); - final Set input2 = Sets.newHashSet(1, 2, 3); + final Set input1 = new HashSet<>(Arrays.asList(1)); + final Set input2 = new HashSet<>(Arrays.asList(1, 2, 3)); // When final Set result = function.apply(input1, input2); @@ -121,7 +121,7 @@ public void shouldReturnLongestMapInput() { // Given final Longest> function = new Longest<>(); final Map input1 = new HashMap<>(); - final Map input2 = Maps.asMap(Sets.newHashSet("1"), k -> k); + final Map input2 = Collections.singletonMap("1", "1"); // When final Map result = function.apply(input1, input2); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/StringJoinTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/StringJoinTest.java index 180abb94c..733846e45 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/StringJoinTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/StringJoinTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Crown Copyright + * Copyright 2020-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,15 +16,15 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Set; @@ -48,7 +48,7 @@ public void shouldHandleNullInput() { public void shouldHandleNullDelimiter() { // Given final StringJoin function = new StringJoin<>(null); - final Set input = Sets.newHashSet("a", "b", "c"); + final Set input = new HashSet<>(Arrays.asList("a", "b", "c")); // When final String result = function.apply(input); @@ -61,7 +61,7 @@ public void shouldHandleNullDelimiter() { public void shouldJoinIterableOfStrings() { // Given final StringJoin function = new StringJoin<>(); - final Set input = Sets.newHashSet("a", "b", "c"); + final Set input = new HashSet<>(Arrays.asList("a", "b", "c")); // When final String result = function.apply(input); @@ -74,7 +74,7 @@ public void shouldJoinIterableOfStrings() { public void shouldJoinIterableOfIntegers() { // Given final StringJoin function = new StringJoin<>(); - final List input = Lists.newArrayList(1, 2, 3, 4, 5); + final List input = Arrays.asList(1, 2, 3, 4, 5); // When final String result = function.apply(input); @@ -87,7 +87,7 @@ public void shouldJoinIterableOfIntegers() { public void shouldJoinIterableOfStringsWithDelimiter() { // Given final StringJoin function = new StringJoin<>(","); - final Set input = Sets.newHashSet("a", "b", "c"); + final Set input = new HashSet<>(Arrays.asList("a", "b", "c")); // When final String result = function.apply(input); @@ -100,7 +100,7 @@ public void shouldJoinIterableOfStringsWithDelimiter() { public void shouldJoinIterableOfIntegersWithDelimiter() { // Given final StringJoin function = new StringJoin<>(" "); - final List input = Lists.newArrayList(1, 2, 3, 4, 5); + final List input = Arrays.asList(1, 2, 3, 4, 5); // When final String result = function.apply(input); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToArrayTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToArrayTest.java index 4cb53db53..7ec616c8a 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToArrayTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToArrayTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; @@ -25,6 +23,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.LinkedHashSet; import static org.assertj.core.api.Assertions.assertThat; @@ -59,7 +58,7 @@ public void shouldConvertStringToArray() { public void shouldConvertListToArray() { // Given final ToArray function = new ToArray(); - final Object value = Lists.newArrayList("value1", "value2"); + final Object value = Arrays.asList("value1", "value2"); // When final Object[] result = function.apply(value); @@ -72,7 +71,7 @@ public void shouldConvertListToArray() { public void shouldConvertSetToArray() { // Given final ToArray function = new ToArray(); - final Object value = Sets.newLinkedHashSet(Arrays.asList("value1", "value2")); + final Object value = new LinkedHashSet<>(Arrays.asList("value1", "value2")); // When final Object[] result = function.apply(value); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToListTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToListTest.java index b68a6cc59..04d40d4bb 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToListTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToListTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; @@ -26,6 +24,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -43,7 +42,7 @@ public void shouldConvertNullToList() { // Then assertThat(result) - .isEqualTo(Lists.newArrayList((Object) null)) + .isEqualTo(Arrays.asList((Object) null)) .asList() .isNotNull() .isNotEmpty() @@ -61,7 +60,7 @@ public void shouldConvertStringToList() { // Then assertThat(result) - .isEqualTo(Lists.newArrayList(value)) + .isEqualTo(Arrays.asList(value)) .isExactlyInstanceOf(ArrayList.class) .asList() .containsExactly(value); @@ -78,24 +77,24 @@ public void shouldConvertArrayToList() { // Then assertThat(result) - .isEqualTo(Lists.newArrayList((Object []) value)) + .isEqualTo(Arrays.asList((Object[]) value)) .isExactlyInstanceOf(ArrayList.class) .asList() - .containsExactlyElementsOf(Lists.newArrayList((Object[]) value)); + .containsExactlyElementsOf(Arrays.asList((Object[]) value)); } @Test public void shouldConvertSetToList() { // Given final ToList function = new ToList(); - final Set value = Sets.newLinkedHashSet(Arrays.asList("value1", "value2")); + final Set value = new LinkedHashSet<>(Arrays.asList("value1", "value2")); // When final Object result = function.apply(value); // Then assertThat(result) - .isEqualTo(Lists.newArrayList(value)) + .isEqualTo(new ArrayList<>(value)) .isExactlyInstanceOf(ArrayList.class) .asList() .containsExactlyElementsOf(value); @@ -105,7 +104,7 @@ public void shouldConvertSetToList() { public void shouldReturnAGivenList() { // Given final ToList function = new ToList(); - final Object value = Lists.newArrayList("value1", "value2"); + final Object value = Arrays.asList("value1", "value2"); // When final Object result = function.apply(value); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToSetTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToSetTest.java index 6a0c7b4c0..34d260e72 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToSetTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToSetTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2022 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,14 +16,13 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.function.FunctionTest; import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; @@ -47,7 +46,7 @@ public void shouldConvertNullToHashSet() { // Then assertThat(result) - .isEqualTo(Sets.newHashSet((Object) null)) + .isEqualTo(new HashSet<>(Arrays.asList((Object) null))) .asInstanceOf(COLLECTION) .isNotNull() .isNotEmpty() @@ -65,7 +64,7 @@ public void shouldConvertNullToEmptyTreeSet() { // Then assertThat(result) .isExactlyInstanceOf(TreeSet.class) - .isEqualTo(Sets.newTreeSet()) + .isEqualTo(new TreeSet<>()) .asInstanceOf(COLLECTION) .isEmpty(); } @@ -81,7 +80,7 @@ public void shouldConvertStringToHashSet() { // Then assertThat(result) - .isEqualTo(Sets.newHashSet(value)) + .isEqualTo(new HashSet<>(Arrays.asList(value))) .isExactlyInstanceOf(HashSet.class) .asInstanceOf(COLLECTION) .containsExactly(value); @@ -98,7 +97,7 @@ public void shouldConvertStringToTreeSet() { // Then assertThat(result) - .isEqualTo(new TreeSet(Sets.newHashSet(value))) + .isEqualTo(new TreeSet(new HashSet<>(Arrays.asList(value)))) .isExactlyInstanceOf(TreeSet.class) .asInstanceOf(COLLECTION) .containsExactly(value); @@ -115,7 +114,7 @@ public void shouldConvertStringToTreeSetUsingfullyQualifiedClassString() throws // Then assertThat(result) - .isEqualTo(new TreeSet(Sets.newHashSet(value))) + .isEqualTo(new TreeSet(new HashSet<>(Arrays.asList(value)))) .isExactlyInstanceOf(TreeSet.class) .asInstanceOf(COLLECTION) .containsExactly(value); @@ -132,7 +131,7 @@ public void shouldConvertStringToTreeSetUsingSimpleClassString() throws ClassNot // Then assertThat(result) - .isEqualTo(new TreeSet(Sets.newHashSet(value))) + .isEqualTo(new TreeSet(new HashSet<>(Arrays.asList(value)))) .isExactlyInstanceOf(TreeSet.class) .asInstanceOf(COLLECTION) .containsExactly(value); @@ -149,10 +148,10 @@ public void shouldConvertArrayToHashSet() { // Then assertThat(result) - .isEqualTo(Sets.newHashSet((Object[]) value)) + .isEqualTo(new HashSet<>(Arrays.asList((Object[]) value))) .isExactlyInstanceOf(HashSet.class) .asInstanceOf(COLLECTION) - .containsExactlyInAnyOrderElementsOf(Lists.newArrayList((Object[]) value)); + .containsExactlyInAnyOrderElementsOf(Arrays.asList((Object[]) value)); } @Test @@ -166,24 +165,24 @@ public void shouldConvertArrayToTreeSet() { // Then assertThat(result) - .isEqualTo(new TreeSet(Sets.newHashSet((Object[]) value))) + .isEqualTo(new TreeSet(new HashSet<>(Arrays.asList((Object[]) value)))) .isExactlyInstanceOf(TreeSet.class) .asInstanceOf(COLLECTION) - .containsExactlyInAnyOrderElementsOf(Lists.newArrayList((Object[]) value)); + .containsExactlyInAnyOrderElementsOf(Arrays.asList((Object[]) value)); } @Test public void shouldConvertListToHashSet() { // Given final ToSet function = new ToSet(); - final List value = Lists.newArrayList("value1", "value2"); + final List value = Arrays.asList("value1", "value2"); // When final Object result = function.apply(value); // Then assertThat(result) - .isEqualTo(Sets.newHashSet(value)) + .isEqualTo(new HashSet<>(value)) .isExactlyInstanceOf(HashSet.class) .asInstanceOf(COLLECTION) .containsExactlyInAnyOrderElementsOf(value); @@ -193,14 +192,14 @@ public void shouldConvertListToHashSet() { public void shouldConvertListToTreeSet() { // Given final ToSet function = new ToSet(TreeSet.class); - final List value = Lists.newArrayList("value1", "value2"); + final List value = Arrays.asList("value1", "value2"); // When final Object result = function.apply(value); // Then assertThat(result) - .isEqualTo(new TreeSet(Sets.newHashSet(value))) + .isEqualTo(new TreeSet(new HashSet<>(value))) .isExactlyInstanceOf(TreeSet.class) .asInstanceOf(COLLECTION) .containsExactlyInAnyOrderElementsOf(value); @@ -210,7 +209,7 @@ public void shouldConvertListToTreeSet() { public void shouldReturnAGivenHashSet() { // Given final ToSet function = new ToSet(); - final Object value = Sets.newHashSet("value1", "value2"); + final Object value = new HashSet<>(Arrays.asList("value1", "value2")); // When final Object result = function.apply(value); @@ -223,7 +222,7 @@ public void shouldReturnAGivenHashSet() { public void shouldReturnAGivenTreeSet() { // Given final ToSet function = new ToSet(TreeSet.class); - final Object value = new TreeSet(Sets.newHashSet("value1", "value2")); + final Object value = new TreeSet(new HashSet<>(Arrays.asList("value1", "value2"))); // When final Object result = function.apply(value); @@ -236,14 +235,14 @@ public void shouldReturnAGivenTreeSet() { public void shouldConvertTreeSetToHashSet() { // Given final ToSet function = new ToSet(HashSet.class); - final Set value = new TreeSet(Sets.newHashSet("value1", "value2")); + final Set value = new TreeSet(new HashSet<>(Arrays.asList("value1", "value2"))); // When final Object result = function.apply(value); // Then assertThat(result) - .isEqualTo(Sets.newHashSet(value)) + .isEqualTo(new HashSet<>(value)) .isExactlyInstanceOf(HashSet.class) .asInstanceOf(COLLECTION) .containsExactlyInAnyOrderElementsOf(value); @@ -253,7 +252,7 @@ public void shouldConvertTreeSetToHashSet() { public void shouldConvertHashSetToTreeSet() { // Given final ToSet function = new ToSet(TreeSet.class); - final Set value = Sets.newHashSet("value1", "value2"); + final Set value = new HashSet<>(Arrays.asList("value1", "value2")); // When final Object result = function.apply(value); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToTupleTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToTupleTest.java index 1b2ce644b..54a6932ed 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToTupleTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/function/ToTupleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 Crown Copyright + * Copyright 2019-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.function; -import com.google.common.collect.Lists; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.junit.jupiter.api.Test; @@ -29,6 +28,7 @@ import uk.gov.gchq.koryphe.util.JsonSerialiser; import java.io.IOException; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -42,7 +42,7 @@ public void shouldConvertListIntoArrayTuple() { final ToTuple function = new ToTuple(); // When - Tuple output = function.apply(Lists.newArrayList(1, 2, 3, 4)); + Tuple output = function.apply(Arrays.asList(1, 2, 3, 4)); // Then assertThat(output).isEqualTo(new ArrayTuple(1, 2, 3, 4)); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/impl/predicate/IsInTest.java b/core/src/test/java/uk/gov/gchq/koryphe/impl/predicate/IsInTest.java index dce0da847..7a7e68dcd 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/impl/predicate/IsInTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/impl/predicate/IsInTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.impl.predicate; -import com.google.common.collect.Sets; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.predicate.PredicateTest; @@ -26,6 +25,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import static org.assertj.core.api.Assertions.assertThat; @@ -69,7 +69,7 @@ public void shouldJsonSerialiseAndDeserialise() throws IOException { // Then 2 assertThat(deserialisedFilter).isNotNull(); - assertThat(deserialisedFilter.getAllowedValues()).containsExactlyElementsOf(Sets.newHashSet(controlData)); + assertThat(deserialisedFilter.getAllowedValues()).containsExactlyElementsOf(new HashSet<>(Arrays.asList(controlData))); } @Override diff --git a/core/src/test/java/uk/gov/gchq/koryphe/iterable/ChainedIterableTest.java b/core/src/test/java/uk/gov/gchq/koryphe/iterable/ChainedIterableTest.java index de675851f..f21d29b05 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/iterable/ChainedIterableTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/iterable/ChainedIterableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package uk.gov.gchq.koryphe.iterable; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.util.CloseableUtil; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; @@ -62,8 +62,8 @@ public void shouldWrapAllIterableOfIterables() { // Given final List itr1 = Collections.singletonList(0); final List emptyItr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = Arrays.asList(1, 2, 3, 4); + final List itr4 = Arrays.asList(5, 6); // When final List> collect = Stream.of(itr1, emptyItr2, itr3, itr4).collect(Collectors.toList()); @@ -79,8 +79,8 @@ public void shouldWrapAllArrayOfIterables() { // Given final List itr1 = Collections.singletonList(0); final List emptyItr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = Arrays.asList(1, 2, 3, 4); + final List itr4 = Arrays.asList(5, 6); // When final ChainedIterable wrappedItr = new ChainedIterable<>(itr1, emptyItr2, itr3, itr4); @@ -94,9 +94,9 @@ public void shouldWrapAllArrayOfIterablesWithNulls() { // Given final List itr1 = Collections.singletonList(0); final List emptyItr2 = new ArrayList<>(0); - final List itrWithNull = Lists.newArrayList((Integer) null); - final List itr3 = Lists.newArrayList(1, null, 2, null, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itrWithNull = Arrays.asList((Integer) null); + final List itr3 = Arrays.asList(1, null, 2, null, 3, 4); + final List itr4 = Arrays.asList(5, 6); // When final ChainedIterable wrappedItr = new ChainedIterable<>(itr1, emptyItr2, itrWithNull, itr3, itr4); @@ -110,8 +110,8 @@ public void shouldHandleNullsOfIterables() { // Given final List itr1 = Collections.singletonList(0); final List emptyItr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = Arrays.asList(1, 2, 3, 4); + final List itr4 = Arrays.asList(5, 6); // When final ChainedIterable wrappedItr = new ChainedIterable<>(null, itr1, null, emptyItr2, null, itr3, itr4); @@ -124,10 +124,10 @@ public void shouldHandleNullsOfIterables() { @Test public void shouldRemoveElementFromFirstIterable() { // Given - final List itr1 = Lists.newArrayList("a"); + final List itr1 = new ArrayList<>(Arrays.asList("a")); final List emptyItr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList("b", "c", "d", "e"); - final List itr4 = Lists.newArrayList("f", "g"); + final List itr3 = Arrays.asList("b", "c", "d", "e"); + final List itr4 = Arrays.asList("f", "g"); ChainedIterable wrappedItr = null; Iterator itr = null; @@ -154,10 +154,10 @@ public void shouldRemoveElementFromFirstIterable() { @Test public void shouldRemoveElementFromThirdIterable() { // Given - final List itr1 = Lists.newArrayList("a"); + final List itr1 = Arrays.asList("a"); final List emptyItr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList("b", "c", "d", "e"); - final List itr4 = Lists.newArrayList("f", "g"); + final List itr3 = new ArrayList<>(Arrays.asList("b", "c", "d", "e")); + final List itr4 = Arrays.asList("f", "g"); // When ChainedIterable wrappedItr = null; diff --git a/core/src/test/java/uk/gov/gchq/koryphe/iterable/FilteredIterableTest.java b/core/src/test/java/uk/gov/gchq/koryphe/iterable/FilteredIterableTest.java index c7adf2f6a..cb6516e2c 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/iterable/FilteredIterableTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/iterable/FilteredIterableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package uk.gov.gchq.koryphe.iterable; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.impl.predicate.IsLessThan; import uk.gov.gchq.koryphe.impl.predicate.IsMoreThan; +import java.util.Arrays; import java.util.List; import java.util.function.Predicate; @@ -32,23 +32,23 @@ public class FilteredIterableTest { @Test public void shouldThrowIAXWhenArrayOfIterablesIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(null, Lists.newArrayList(new IsLessThan(4)))); + assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(null, Arrays.asList(new IsLessThan(4)))); } @Test public void shouldThrowIAXWhenListOfPredicatesIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(Lists.newArrayList(1, 2, 3, 4, 5), (List) null)); + assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(Arrays.asList(1, 2, 3, 4, 5), (List) null)); } @Test public void shouldThrowIAXWhenOnePredicateIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(Lists.newArrayList(1, 2, 3, 4, 5), Lists.newArrayList(new IsLessThan(4), (Predicate) null))); + assertThatIllegalArgumentException().isThrownBy(() -> new FilteredIterable(Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(new IsLessThan(4), (Predicate) null))); } @Test public void shouldCorrectlyFilterSinglePredicate() { // Given - final List itr = Lists.newArrayList(1, 2, 3, 4, 5); + final List itr = Arrays.asList(1, 2, 3, 4, 5); // When FilteredIterable filteredIterable = new FilteredIterable(itr, new IsLessThan(4)); @@ -60,8 +60,8 @@ public void shouldCorrectlyFilterSinglePredicate() { @Test public void shouldCorrectlyFilterMultiplePredicates() { // Given - final List itr = Lists.newArrayList(1, 2, 3, 4, 5); - final List predicates = Lists.newArrayList(new IsLessThan(4), new IsMoreThan(1)); + final List itr = Arrays.asList(1, 2, 3, 4, 5); + final List predicates = Arrays.asList(new IsLessThan(4), new IsMoreThan(1)); // When FilteredIterable filteredIterable = new FilteredIterable(itr, predicates); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/iterable/MappedIterableTest.java b/core/src/test/java/uk/gov/gchq/koryphe/iterable/MappedIterableTest.java index e541993ff..7e6f1e478 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/iterable/MappedIterableTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/iterable/MappedIterableTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,12 +16,12 @@ package uk.gov.gchq.koryphe.iterable; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import uk.gov.gchq.koryphe.impl.function.Increment; import uk.gov.gchq.koryphe.impl.function.MultiplyBy; +import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -32,23 +32,23 @@ public class MappedIterableTest { @Test public void shouldThrowIAXWhenArrayOfIterablesIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(null, Lists.newArrayList(new Increment(4)))); + assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(null, Arrays.asList(new Increment(4)))); } @Test public void shouldThrowIAXWhenListOfFunctionsIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(Lists.newArrayList(1, 2, 3, 4, 5), (List) null)); + assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(Arrays.asList(1, 2, 3, 4, 5), (List) null)); } @Test public void shouldThrowIAXWhenOneFunctionIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(Lists.newArrayList(1, 2, 3, 4, 5), Lists.newArrayList(new Increment(4), (Function) null))); + assertThatIllegalArgumentException().isThrownBy(() -> new MappedIterable(Arrays.asList(1, 2, 3, 4, 5), Arrays.asList(new Increment(4), (Function) null))); } @Test public void shouldCorrectlyApplySingleFunction() { // Given - final List itr = Lists.newArrayList(1, 2, 3, 4, 5); + final List itr = Arrays.asList(1, 2, 3, 4, 5); // When MappedIterable mappedIterable = new MappedIterable(itr, new Increment(4)); @@ -60,8 +60,8 @@ public void shouldCorrectlyApplySingleFunction() { @Test public void shouldCorrectlyApplyMultipleFunctions() { // Given - final List itr = Lists.newArrayList(1, 2, 3, 4, 5); - final List functions = Lists.newArrayList(new Increment(4), new MultiplyBy(2)); + final List itr = Arrays.asList(1, 2, 3, 4, 5); + final List functions = Arrays.asList(new Increment(4), new MultiplyBy(2)); // When MappedIterable mappedIterable = new MappedIterable(itr, functions); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/signature/InputValidatorAssert.java b/core/src/test/java/uk/gov/gchq/koryphe/signature/InputValidatorAssert.java index 4d40ad98b..cb317ade1 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/signature/InputValidatorAssert.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/signature/InputValidatorAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,11 @@ package uk.gov.gchq.koryphe.signature; -import com.google.common.collect.Sets; - import org.assertj.core.api.AbstractAssert; +import java.util.Arrays; +import java.util.HashSet; + public class InputValidatorAssert extends AbstractAssert { public InputValidatorAssert(InputValidator actual) { @@ -33,7 +34,7 @@ public static InputValidatorAssert assertThat(InputValidator actual) { public InputValidatorAssert acceptsInput(Class... arguments) { isNotNull(); if (!actual.isInputValid(arguments).isValid()) { - failWithMessage("Expected Class %s to accept inputs %s", actual, Sets.newHashSet(arguments)); + failWithMessage("Expected Class %s to accept inputs %s", actual, new HashSet<>(Arrays.asList(arguments))); } return this; } @@ -41,7 +42,7 @@ public InputValidatorAssert acceptsInput(Class... arguments) { public InputValidatorAssert rejectsInput(Class... arguments) { isNotNull(); if (actual.isInputValid(arguments).isValid()) { - failWithMessage("Expected Class %s to reject inputs %s", actual, Sets.newHashSet(arguments)); + failWithMessage("Expected Class %s to reject inputs %s", actual, new HashSet<>(Arrays.asList(arguments))); } return this; } diff --git a/core/src/test/java/uk/gov/gchq/koryphe/signature/SignatureAssert.java b/core/src/test/java/uk/gov/gchq/koryphe/signature/SignatureAssert.java index f0e00f70a..0f8088433 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/signature/SignatureAssert.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/signature/SignatureAssert.java @@ -1,5 +1,5 @@ /* - * Copyright 2022 Crown Copyright + * Copyright 2022-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,11 @@ package uk.gov.gchq.koryphe.signature; -import com.google.common.collect.Sets; - import org.assertj.core.api.AbstractObjectAssert; +import java.util.Arrays; +import java.util.HashSet; + public class SignatureAssert extends AbstractObjectAssert { public SignatureAssert(Signature actual) { @@ -33,7 +34,7 @@ public static SignatureAssert assertThat(Signature actual) { public SignatureAssert isAssignableFrom(Class... arguments) { isNotNull(); if (!actual.assignable(arguments).isValid()) { - failWithMessage("Expected Signature %s to be assignable from %s", actual, Sets.newHashSet(arguments)); + failWithMessage("Expected Signature %s to be assignable from %s", actual, new HashSet<>(Arrays.asList(arguments))); } return this; } @@ -41,7 +42,7 @@ public SignatureAssert isAssignableFrom(Class... arguments) { public SignatureAssert isNotAssignableFrom(Class... arguments) { isNotNull(); if (actual.assignable(arguments).isValid()) { - failWithMessage("Expected Signature %s not to be assignable from %s", actual, Sets.newHashSet(arguments)); + failWithMessage("Expected Signature %s not to be assignable from %s", actual, new HashSet<>(Arrays.asList(arguments))); } return this; } diff --git a/core/src/test/java/uk/gov/gchq/koryphe/tuple/ArrayTupleTest.java b/core/src/test/java/uk/gov/gchq/koryphe/tuple/ArrayTupleTest.java index e834d18a3..82c617930 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/tuple/ArrayTupleTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/tuple/ArrayTupleTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,10 @@ package uk.gov.gchq.koryphe.tuple; -import com.google.common.collect.Lists; - import org.junit.jupiter.api.Test; +import java.util.Arrays; + import static org.assertj.core.api.Assertions.assertThat; public class ArrayTupleTest { @@ -44,6 +44,6 @@ public void testInitialArrayConstructors() { final ArrayTuple tuple = new ArrayTuple(initialValues); // Then - assertThat(tuple).containsExactlyElementsOf(Lists.newArrayList(initialValues)); + assertThat(tuple).containsExactlyElementsOf(Arrays.asList(initialValues)); } } diff --git a/core/src/test/java/uk/gov/gchq/koryphe/util/IterableUtilTest.java b/core/src/test/java/uk/gov/gchq/koryphe/util/IterableUtilTest.java index 50081012c..8f4420fcb 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/util/IterableUtilTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/util/IterableUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.util; -import com.google.common.collect.Lists; import org.junit.jupiter.api.Test; import java.util.ArrayList; @@ -35,8 +34,8 @@ public void shouldWrapAllIterables() { // Given final List itr1 = Collections.singletonList(0); final List itr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = Arrays.asList(1, 2, 3, 4); + final List itr4 = Arrays.asList(5, 6); // When final Iterable itrConcat = IterableUtil.concat(Arrays.asList(itr1, itr2, itr3, itr4)); @@ -48,10 +47,10 @@ public void shouldWrapAllIterables() { @Test public void shouldRemoveElementFromFirstIterable() { // Given - final List itr1 = Lists.newArrayList(0); + final List itr1 = new ArrayList<>(Arrays.asList(0)); final List itr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = Arrays.asList(1, 2, 3, 4); + final List itr4 = Arrays.asList(5, 6); final int itr1Size = itr1.size(); final int itr2Size = itr2.size(); @@ -75,10 +74,10 @@ public void shouldRemoveElementFromFirstIterable() { @Test public void shouldRemoveElementFromThirdIterable() { // Given - final List itr1 = Lists.newArrayList(0); + final List itr1 = Arrays.asList(0); final List itr2 = new ArrayList<>(0); - final List itr3 = Lists.newArrayList(1, 2, 3, 4); - final List itr4 = Lists.newArrayList(5, 6); + final List itr3 = new ArrayList<>(Arrays.asList(1, 2, 3, 4)); + final List itr4 = Arrays.asList(5, 6); final int itr1Size = itr1.size(); final int itr2Size = itr2.size(); diff --git a/core/src/test/java/uk/gov/gchq/koryphe/util/ReflectionUtilTest.java b/core/src/test/java/uk/gov/gchq/koryphe/util/ReflectionUtilTest.java index cb72fbecf..684bbd3c2 100644 --- a/core/src/test/java/uk/gov/gchq/koryphe/util/ReflectionUtilTest.java +++ b/core/src/test/java/uk/gov/gchq/koryphe/util/ReflectionUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2020 Crown Copyright + * Copyright 2018-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package uk.gov.gchq.koryphe.util; -import com.google.common.collect.Sets; import com.google.common.primitives.UnsignedLong; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -24,6 +23,7 @@ import uk.gov.gchq.koryphe.serialisation.json.obj.first.TestCustomNumber; +import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.Map; @@ -105,11 +105,11 @@ public void shouldReturnSimpleClassNames() { assertThat(simpleClassNames) .containsEntry( TestCustomNumber.class.getSimpleName(), - Sets.newHashSet( + new HashSet<>(Arrays.asList( TestCustomNumber.class, uk.gov.gchq.koryphe.serialisation.json.obj.second.TestCustomNumber.class ) - ) + )) .doesNotContainKey(UnsignedLong.class.getSimpleName()); } @@ -137,11 +137,11 @@ public void shouldReturnSimpleClassNamesWithExtraClassesInPath() { assertThat(simpleClassNames) .containsEntry( TestCustomNumber.class.getSimpleName(), - Sets.newHashSet( + new HashSet<>(Arrays.asList( TestCustomNumber.class, uk.gov.gchq.koryphe.serialisation.json.obj.second.TestCustomNumber.class ) - ) + )) .containsEntry( UnsignedLong.class.getSimpleName(), Collections.singleton(UnsignedLong.class) @@ -162,11 +162,11 @@ public void shouldReturnSimpleClassNamesWithExtraClassesInPathWithTrailingDot() assertThat(simpleClassNames) .containsEntry( TestCustomNumber.class.getSimpleName(), - Sets.newHashSet( + new HashSet<>(Arrays.asList( TestCustomNumber.class, uk.gov.gchq.koryphe.serialisation.json.obj.second.TestCustomNumber.class ) - ) + )) .containsEntry( UnsignedLong.class.getSimpleName(), Collections.singleton(UnsignedLong.class) diff --git a/doc/src/main/java/uk/gov/gchq/koryphe/example/KorypheExample.java b/doc/src/main/java/uk/gov/gchq/koryphe/example/KorypheExample.java index e7dddbf19..c10711a01 100644 --- a/doc/src/main/java/uk/gov/gchq/koryphe/example/KorypheExample.java +++ b/doc/src/main/java/uk/gov/gchq/koryphe/example/KorypheExample.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020 Crown Copyright + * Copyright 2017-2023 Crown Copyright * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,10 @@ package uk.gov.gchq.koryphe.example; -import com.google.common.collect.Lists; - import uk.gov.gchq.koryphe.example.annotation.Example; import uk.gov.gchq.koryphe.tuple.MapTuple; import uk.gov.gchq.koryphe.tuple.Tuple; +import uk.gov.gchq.koryphe.util.IterableUtil; import java.util.stream.Stream; @@ -78,7 +77,7 @@ protected void printTuple(final Tuple tuple) { } protected void printIterable(final Iterable iterable) { - System.out.println(Lists.newArrayList(iterable)); + System.out.println(IterableUtil.toList(iterable)); } protected Tuple createMapTuple(final Object valueA, final Object valueB, final Object valueC) { diff --git a/pom.xml b/pom.xml index 6790d2c43..3f4217f06 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ 4.7.3 - 29.0-jre + 31.1-jre 3.22.0 2.13.4 5.8.2 @@ -143,11 +143,6 @@ commons-io ${commons-io.version} - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-csv @@ -190,6 +185,12 @@ ${mockito.version} test + + com.google.guava + guava + ${guava.version} + test +