diff options
Diffstat (limited to 'vespajlib')
34 files changed, 82 insertions, 172 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java index 7f70256233e..1f215f9d90e 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java @@ -51,8 +51,7 @@ public class CollectionUtil { * Returns true if the contents of the two given collections are equal, ignoring order. */ public static boolean equalContentsIgnoreOrder(Collection<?> c1, Collection<?> c2) { - return c1.size() == c2.size() && - c1.containsAll(c2); + return c1.size() == c2.size() && c1.containsAll(c2); } /** diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java index 8ace7598e27..26c0bec34b1 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java @@ -56,7 +56,7 @@ public class ListenableArrayList<ITEM> extends ArrayList<ITEM> { } public List<Runnable> listeners() { - if (listeners == null) return Collections.emptyList(); + if (listeners == null) return List.of(); return Collections.unmodifiableList(listeners); } diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/InThreadExecutorService.java b/vespajlib/src/main/java/com/yahoo/concurrent/InThreadExecutorService.java index 96541e555b2..63653b051c0 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/InThreadExecutorService.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/InThreadExecutorService.java @@ -1,7 +1,6 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.concurrent; -import java.util.Collections; import java.util.List; import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.ExecutorService; @@ -24,7 +23,7 @@ public class InThreadExecutorService extends AbstractExecutorService { @Override public List<Runnable> shutdownNow() { shutdown(); - return Collections.emptyList(); + return List.of(); } @Override diff --git a/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java b/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java index 3a02d752aa5..e67c1ebb3b6 100644 --- a/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java +++ b/vespajlib/src/main/java/com/yahoo/data/access/simple/Value.java @@ -41,8 +41,8 @@ public class Value implements Inspector { public void traverse(ObjectTraverser ot) {} public Inspector entry(int idx) { return invalid; } public Inspector field(java.lang.String name) { return invalid; } - public Iterable<Inspector> entries() { return Collections.emptyList(); } - public Iterable<Map.Entry<java.lang.String,Inspector>> fields() { return Collections.emptyList(); } + public Iterable<Inspector> entries() { return List.of(); } + public Iterable<Map.Entry<java.lang.String,Inspector>> fields() { return List.of(); } public StringBuilder writeJson(StringBuilder target) { return JsonRender.render(this, target, true); } diff --git a/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java b/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java deleted file mode 100644 index 939d2276efc..00000000000 --- a/vespajlib/src/main/java/com/yahoo/errorhandling/Results.java +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.errorhandling; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * @author Tony Vaagenes - */ -public class Results<DATA, ERROR> { - - private final List<DATA> data; - private final List<ERROR> errors; - - public Results(List<DATA> data, List<ERROR> errors) { - this.data = List.copyOf(data); - this.errors = List.copyOf(errors); - } - - public boolean hasErrors() { - return !errors.isEmpty(); - } - - public List<DATA> data() { - return data; - } - - public List<ERROR> errors() { - return errors; - } - - public static class Builder<DATA, ERROR> { - private final List<DATA> data = new ArrayList<>(); - private final List<ERROR> errors = new ArrayList<>(); - - public void addData(DATA d) { - data.add(d); - } - - public void addAllData(Collection<? extends DATA> d) { - data.addAll(d); - } - - public void addError(ERROR e) { - errors.add(e); - } - - public void addAllErrors(Collection<? extends ERROR> e) { - errors.addAll(e); - } - - public Results<DATA, ERROR> build() { - return new Results<>(data, errors); - } - } - -} diff --git a/vespajlib/src/main/java/com/yahoo/errorhandling/package-info.java b/vespajlib/src/main/java/com/yahoo/errorhandling/package-info.java deleted file mode 100644 index ac6c913381c..00000000000 --- a/vespajlib/src/main/java/com/yahoo/errorhandling/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -@ExportPackage -package com.yahoo.errorhandling; - -import com.yahoo.osgi.annotation.ExportPackage; diff --git a/vespajlib/src/main/java/com/yahoo/net/URI.java b/vespajlib/src/main/java/com/yahoo/net/URI.java index d008c589824..5111ad39e88 100644 --- a/vespajlib/src/main/java/com/yahoo/net/URI.java +++ b/vespajlib/src/main/java/com/yahoo/net/URI.java @@ -80,7 +80,7 @@ public class URI implements Cloneable, Comparable<URI> { } /** - * Creates an URI, optionaly keeping the fragment (the part starting by #). + * Creates a URI, optionally keeping the fragment (the part starting by #). * If the uri is hierarchical, it is normalized and incorrect hierarchical uris * which looks like urls are attempted repaired. * @@ -95,7 +95,7 @@ public class URI implements Cloneable, Comparable<URI> { } /** - * Creates an URI, optionaly keeping the fragment (the part starting by #). + * Creates a URI, optionally keeping the fragment (the part starting by #). * If the uri is hierarchical, it is normalized and incorrect hierarchical uris * which looks like urls are attempted repaired. * diff --git a/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java b/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java index 704fe9d56c3..12b435111e3 100644 --- a/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java +++ b/vespajlib/src/main/java/com/yahoo/system/CommandLineParser.java @@ -39,12 +39,12 @@ public class CommandLineParser { } public CommandLineParser(String[] cmds) { - inputStrings = Arrays.asList(cmds); + inputStrings = List.of(cmds); } public CommandLineParser(String progname, String[] cmds) { this.progname=progname; - inputStrings = Arrays.asList(cmds); + inputStrings = List.of(cmds); } /** diff --git a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java index d27c7cf0168..d225d6f4641 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/Tensor.java @@ -23,8 +23,6 @@ import com.yahoo.tensor.functions.Expand; import com.yahoo.tensor.impl.Label; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -170,7 +168,7 @@ public interface Tensor { /** Aggregates cells over a set of dimensions, or over all dimensions if no dimensions are specified */ default Tensor reduce(Reduce.Aggregator aggregator, String ... dimensions) { - return new Reduce<>(new ConstantTensor<>(this), aggregator, Arrays.asList(dimensions)).evaluate(); + return new Reduce<>(new ConstantTensor<>(this), aggregator, List.of(dimensions)).evaluate(); } /** Aggregates cells over a set of dimensions, or over all dimensions if no dimensions are specified */ default Tensor reduce(Reduce.Aggregator aggregator, List<String> dimensions) { @@ -186,8 +184,8 @@ public interface Tensor { } default Tensor rename(String fromDimension, String toDimension) { - return new Rename<>(new ConstantTensor<>(this), Collections.singletonList(fromDimension), - Collections.singletonList(toDimension)).evaluate(); + return new Rename<>(new ConstantTensor<>(this), List.of(fromDimension), + List.of(toDimension)).evaluate(); } default Tensor concat(double argument, String dimension) { @@ -270,26 +268,26 @@ public interface Tensor { default Tensor bit(Tensor argument) { return join(argument, (a,b) -> ((int)b < 8 && (int)b >= 0 && ((int)a & (1 << (int)b)) != 0) ? 1.0 : 0.0); } default Tensor hamming(Tensor argument) { return join(argument, Hamming::hamming); } - default Tensor avg() { return avg(Collections.emptyList()); } - default Tensor avg(String dimension) { return avg(Collections.singletonList(dimension)); } + default Tensor avg() { return avg(List.of()); } + default Tensor avg(String dimension) { return avg(List.of(dimension)); } default Tensor avg(List<String> dimensions) { return reduce(Reduce.Aggregator.avg, dimensions); } - default Tensor count() { return count(Collections.emptyList()); } - default Tensor count(String dimension) { return count(Collections.singletonList(dimension)); } + default Tensor count() { return count(List.of()); } + default Tensor count(String dimension) { return count(List.of(dimension)); } default Tensor count(List<String> dimensions) { return reduce(Reduce.Aggregator.count, dimensions); } - default Tensor max() { return max(Collections.emptyList()); } - default Tensor max(String dimension) { return max(Collections.singletonList(dimension)); } + default Tensor max() { return max(List.of()); } + default Tensor max(String dimension) { return max(List.of(dimension)); } default Tensor max(List<String> dimensions) { return reduce(Reduce.Aggregator.max, dimensions); } - default Tensor median() { return median(Collections.emptyList()); } - default Tensor median(String dimension) { return median(Collections.singletonList(dimension)); } + default Tensor median() { return median(List.of()); } + default Tensor median(String dimension) { return median(List.of(dimension)); } default Tensor median(List<String> dimensions) { return reduce(Reduce.Aggregator.median, dimensions); } - default Tensor min() { return min(Collections.emptyList()); } - default Tensor min(String dimension) { return min(Collections.singletonList(dimension)); } + default Tensor min() { return min(List.of()); } + default Tensor min(String dimension) { return min(List.of(dimension)); } default Tensor min(List<String> dimensions) { return reduce(Reduce.Aggregator.min, dimensions); } - default Tensor prod() { return prod(Collections.emptyList()); } - default Tensor prod(String dimension) { return prod(Collections.singletonList(dimension)); } + default Tensor prod() { return prod(List.of()); } + default Tensor prod(String dimension) { return prod(List.of(dimension)); } default Tensor prod(List<String> dimensions) { return reduce(Reduce.Aggregator.prod, dimensions); } - default Tensor sum() { return sum(Collections.emptyList()); } - default Tensor sum(String dimension) { return sum(Collections.singletonList(dimension)); } + default Tensor sum() { return sum(List.of()); } + default Tensor sum(String dimension) { return sum(List.of(dimension)); } default Tensor sum(List<String> dimensions) { return reduce(Reduce.Aggregator.sum, dimensions); } // ----------------- non-math query methods (that is, computations not returning a tensor) diff --git a/vespajlib/src/main/java/com/yahoo/tensor/TensorTypeParser.java b/vespajlib/src/main/java/com/yahoo/tensor/TensorTypeParser.java index b6bd252f135..fc82be4b33c 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/TensorTypeParser.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/TensorTypeParser.java @@ -3,7 +3,6 @@ package com.yahoo.tensor; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.regex.Matcher; @@ -50,7 +49,7 @@ public class TensorTypeParser { dimensionsSpec = specBody.substring(parenthesisIndex + 1); } - if (dimensionsSpec.isEmpty()) return new TensorType.Builder(valueType, Collections.emptyList()).build(); + if (dimensionsSpec.isEmpty()) return new TensorType.Builder(valueType, List.of()).build(); List<TensorType.Dimension> dimensions = new ArrayList<>(); for (String element : dimensionsSpec.split(",")) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java index 0cef1482292..58b17758cfe 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/evaluation/VariableTensor.java @@ -7,7 +7,6 @@ import com.yahoo.tensor.functions.PrimitiveTensorFunction; import com.yahoo.tensor.functions.TensorFunction; import com.yahoo.tensor.functions.ToStringContext; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -34,7 +33,7 @@ public class VariableTensor<NAMETYPE extends Name> extends PrimitiveTensorFuncti } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { return this; } diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/CellCast.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/CellCast.java index 61207840ded..5655bb020a4 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/CellCast.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/CellCast.java @@ -8,7 +8,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -32,7 +31,7 @@ public class CellCast<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAM } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java index c81cde70c75..0ecd4b5f947 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/ConstantTensor.java @@ -7,7 +7,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -29,7 +28,7 @@ public class ConstantTensor<NAMETYPE extends Name> extends PrimitiveTensorFuncti } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java index 382ac94be7d..354e03e6699 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Diag.java @@ -4,7 +4,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; @@ -27,7 +26,7 @@ public class Diag<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETYP } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Expand.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Expand.java index 3042991e2c0..f5a33dde064 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Expand.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Expand.java @@ -4,7 +4,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -25,7 +24,7 @@ public class Expand<NAMETYPE extends Name> extends CompositeTensorFunction<NAMET } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java index 51bd4152479..a5afeb6d2a4 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/L1Normalize.java @@ -3,7 +3,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -21,7 +20,7 @@ public class L1Normalize<NAMETYPE extends Name> extends CompositeTensorFunction< } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java index 4b6ffbca63c..47e341732ca 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/L2Normalize.java @@ -3,7 +3,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -21,7 +20,7 @@ public class L2Normalize<NAMETYPE extends Name> extends CompositeTensorFunction< } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java index 404be1d6fac..94e75588ba3 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Map.java @@ -9,7 +9,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Objects; @@ -40,7 +39,7 @@ public class Map<NAMETYPE extends Name> extends PrimitiveTensorFunction<NAMETYPE public DoubleUnaryOperator mapper() { return mapper; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/MapSubspaces.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/MapSubspaces.java index aa9602339e9..93a101909a2 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/MapSubspaces.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/MapSubspaces.java @@ -9,7 +9,6 @@ import com.yahoo.tensor.evaluation.EvaluationContext; import com.yahoo.tensor.evaluation.Name; import com.yahoo.tensor.evaluation.TypeContext; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -64,7 +63,7 @@ public class MapSubspaces<NAMETYPE extends Name> extends PrimitiveTensorFunction public TensorFunction<NAMETYPE> argument() { return argument; } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java index 5d51d8cd5c6..811e861de9c 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Random.java @@ -4,7 +4,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -24,7 +23,7 @@ public class Random<NAMETYPE extends Name> extends CompositeTensorFunction<NAMET } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java index 8520aef537d..9960fbd58ea 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Range.java @@ -4,7 +4,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.function.Function; @@ -28,7 +27,7 @@ public class Range<NAMETYPE extends Name> extends CompositeTensorFunction<NAMETY } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.emptyList(); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java index c2eff01c801..150bf82f0e8 100644 --- a/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java +++ b/vespajlib/src/main/java/com/yahoo/tensor/functions/Softmax.java @@ -4,7 +4,6 @@ package com.yahoo.tensor.functions; import com.yahoo.tensor.TensorType; import com.yahoo.tensor.evaluation.Name; -import java.util.Collections; import java.util.List; import java.util.Objects; @@ -26,7 +25,7 @@ public class Softmax<NAMETYPE extends Name> extends CompositeTensorFunction<NAME } @Override - public List<TensorFunction<NAMETYPE>> arguments() { return Collections.singletonList(argument); } + public List<TensorFunction<NAMETYPE>> arguments() { return List.of(argument); } @Override public TensorFunction<NAMETYPE> withArguments(List<TensorFunction<NAMETYPE>> arguments) { diff --git a/vespajlib/src/main/java/com/yahoo/yolean/trace/TraceNode.java b/vespajlib/src/main/java/com/yahoo/yolean/trace/TraceNode.java index 39a78897bfb..90b9383eb0c 100644 --- a/vespajlib/src/main/java/com/yahoo/yolean/trace/TraceNode.java +++ b/vespajlib/src/main/java/com/yahoo/yolean/trace/TraceNode.java @@ -3,7 +3,6 @@ package com.yahoo.yolean.trace; import com.yahoo.yolean.concurrent.ThreadRobustList; -import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; @@ -73,7 +72,7 @@ public class TraceNode { */ public <PAYLOADTYPE> Iterable<PAYLOADTYPE> descendants(final Class<PAYLOADTYPE> payloadType) { if (children == null) { - return Collections.emptyList(); + return List.of(); } return new Iterable<PAYLOADTYPE>() { @@ -118,7 +117,7 @@ public class TraceNode { */ public Iterable<TraceNode> children() { if (children == null) { - return Collections.emptyList(); + return List.of(); } return children; } diff --git a/vespajlib/src/test/java/com/yahoo/collections/CollectionComparatorTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/CollectionComparatorTestCase.java index 54101c7f251..a2420ed3fe5 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/CollectionComparatorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/collections/CollectionComparatorTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.collections; import org.junit.Test; -import java.util.Arrays; import java.util.List; import static org.junit.Assert.assertEquals; @@ -14,16 +13,16 @@ import static org.junit.Assert.assertEquals; public class CollectionComparatorTestCase { @Test public void arrayLength() { - List<String> shortArr = Arrays.asList("x", "y"); - List<String> longArr = Arrays.asList("a", "b", "c", "d", "e"); + List<String> shortArr = List.of("x", "y"); + List<String> longArr = List.of("a", "b", "c", "d", "e"); assertEquals(-1, CollectionComparator.compare(shortArr, longArr)); } @Test public void compareArrays() { - List<String> one = Arrays.asList("b", "c", "d", "d", "e"); - List<String> two = Arrays.asList("a", "b", "c", "d", "e"); + List<String> one = List.of("b", "c", "d", "d", "e"); + List<String> two = List.of("a", "b", "c", "d", "e"); assertEquals(1, CollectionComparator.compare(one, two)); assertEquals(-1, CollectionComparator.compare(two, one)); @@ -31,8 +30,8 @@ public class CollectionComparatorTestCase { @Test public void compareEqualArrays() { - List<String> one = Arrays.asList("a", "b", "c", "d", "e"); - List<String> two = Arrays.asList("a", "b", "c", "d", "e"); + List<String> one = List.of("a", "b", "c", "d", "e"); + List<String> two = List.of("a", "b", "c", "d", "e"); assertEquals(0, CollectionComparator.compare(one, two)); assertEquals(0, CollectionComparator.compare(two, one)); diff --git a/vespajlib/src/test/java/com/yahoo/collections/CollectionUtilTest.java b/vespajlib/src/test/java/com/yahoo/collections/CollectionUtilTest.java index 7cef3423aeb..fd24bfb4f40 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/CollectionUtilTest.java +++ b/vespajlib/src/test/java/com/yahoo/collections/CollectionUtilTest.java @@ -27,7 +27,7 @@ public class CollectionUtilTest { @Test public void testMkString() { assertEquals("1, 2, 3, 4", - CollectionUtil.mkString(Arrays.asList(1, 2, 3, 4), ", ")); + CollectionUtil.mkString(List.of(1, 2, 3, 4), ", ")); } @Test @@ -35,16 +35,14 @@ public class CollectionUtilTest { List<Integer> l2Copy = new ArrayList<>(); l2Copy.addAll(l2); shuffle(); - assertTrue(CollectionUtil.equalContentsIgnoreOrder( - l2, l2Copy)); - assertFalse(CollectionUtil.equalContentsIgnoreOrder( - l1, l2)); + assertTrue(CollectionUtil.equalContentsIgnoreOrder(l2, l2Copy)); + assertFalse(CollectionUtil.equalContentsIgnoreOrder(l1, l2)); } @Test public void testSymmetricDifference() { assertTrue(CollectionUtil.equalContentsIgnoreOrder( - Arrays.asList(1, 2, 3), + List.of(1, 2, 3), CollectionUtil.symmetricDifference(l1, l2))); } } diff --git a/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java b/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java index 940dc159a17..930b274ef3e 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java +++ b/vespajlib/src/test/java/com/yahoo/collections/LazyMapTest.java @@ -4,7 +4,6 @@ package com.yahoo.collections; import org.junit.Test; import org.mockito.Mockito; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -22,7 +21,6 @@ import static org.junit.Assert.fail; * @author Simon Thoresen Hult */ public class LazyMapTest { - @Test public void requireThatInitialDelegateIsEmpty() { LazyMap<String, String> map = newLazyMap(new HashMap<String, String>()); @@ -36,14 +34,14 @@ public class LazyMapTest { assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass()); map = newLazyMap(new HashMap<String, String>()); - map.putAll(Collections.singletonMap("foo", "bar")); + map.put("foo", "bar"); assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass()); } @Test public void requireThatEmptyMapPutAllEmptyMapDoesNotUpgradeToSingletonMap() { LazyMap<String, String> map = newLazyMap(new HashMap<String, String>()); - map.putAll(Collections.<String, String>emptyMap()); + map.putAll(Map.of()); assertEquals(LazyMap.EmptyMap.class, map.getDelegate().getClass()); } @@ -81,7 +79,7 @@ public class LazyMapTest { assertEquals("bar", map.put("foo", "baz")); assertEquals("baz", map.get("foo")); assertSame(delegate, map.getDelegate()); - map.putAll(Collections.singletonMap("foo", "cox")); + map.put("foo", "cox"); assertSame(delegate, map.getDelegate()); assertEquals("cox", map.get("foo")); } @@ -89,7 +87,7 @@ public class LazyMapTest { @Test public void requireThatSingletonMapPutAllEmptyMapDoesNotUpgradeToFinalMap() { LazyMap<String, String> map = newSingletonMap("foo", "bar"); - map.putAll(Collections.<String, String>emptyMap()); + map.putAll(Map.of()); assertEquals(LazyMap.SingletonMap.class, map.getDelegate().getClass()); } @@ -188,7 +186,7 @@ public class LazyMapTest { Mockito.verify(delegate).put("foo", "bar"); Mockito.verify(delegate).put("baz", "cox"); - Map<String, String> arg = Collections.singletonMap("baz", "cox"); + Map<String, String> arg = Map.of("baz", "cox"); map.putAll(arg); Mockito.verify(delegate).putAll(arg); diff --git a/vespajlib/src/test/java/com/yahoo/collections/LazySetTest.java b/vespajlib/src/test/java/com/yahoo/collections/LazySetTest.java index ecefd891ca9..4acd9ef3214 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/LazySetTest.java +++ b/vespajlib/src/test/java/com/yahoo/collections/LazySetTest.java @@ -4,11 +4,11 @@ package com.yahoo.collections; import org.junit.Test; import org.mockito.Mockito; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.NoSuchElementException; import java.util.Set; @@ -26,25 +26,25 @@ public class LazySetTest { @Test public void requireThatInitialDelegateIsEmpty() { - LazySet<String> set = newLazySet(new HashSet<String>()); + LazySet<String> set = newLazySet(new HashSet<>()); assertEquals(LazySet.EmptySet.class, set.getDelegate().getClass()); } @Test public void requireThatEmptySetAddUpgradesToSingletonSet() { - LazySet<String> set = newLazySet(new HashSet<String>()); + LazySet<String> set = newLazySet(new HashSet<>()); assertTrue(set.add("foo")); assertEquals(LazySet.SingletonSet.class, set.getDelegate().getClass()); - set = newLazySet(new HashSet<String>()); - assertTrue(set.addAll(Arrays.asList("foo"))); + set = newLazySet(new HashSet<>()); + assertTrue(set.addAll(List.of("foo"))); assertEquals(LazySet.SingletonSet.class, set.getDelegate().getClass()); } @Test public void requireThatEmptySetAddAllEmptySetDoesNotUpgradeToSingletonSet() { - LazySet<String> set = newLazySet(new HashSet<String>()); - assertFalse(set.addAll(Collections.<String>emptySet())); + LazySet<String> set = newLazySet(new HashSet<>()); + assertFalse(set.addAll(Set.of())); assertEquals(LazySet.EmptySet.class, set.getDelegate().getClass()); } @@ -52,7 +52,7 @@ public class LazySetTest { public void requireThatEmptySetAddAllUpgradesToFinalSet() { Set<String> delegate = new HashSet<>(); LazySet<String> set = newLazySet(delegate); - assertTrue(set.addAll(Arrays.asList("foo", "bar"))); + assertTrue(set.addAll(List.of("foo", "bar"))); assertSame(delegate, set.getDelegate()); assertEquals(2, delegate.size()); assertTrue(delegate.contains("foo")); @@ -76,7 +76,7 @@ public class LazySetTest { @Test public void requireThatSingletonSetAddAllEmptySetDoesNotUpgradeToFinalSet() { LazySet<String> set = newSingletonSet("foo"); - assertFalse(set.addAll(Collections.<String>emptySet())); + assertFalse(set.addAll(Set.of())); assertEquals(LazySet.SingletonSet.class, set.getDelegate().getClass()); } @@ -102,7 +102,7 @@ public class LazySetTest { public void requireThatSingletonSetAddAllUpgradesToFinalSet() { Set<String> delegate = new HashSet<>(); LazySet<String> set = newSingletonSet(delegate, "foo"); - assertTrue(set.addAll(Arrays.asList("bar"))); + assertTrue(set.addAll(List.of("bar"))); assertSame(delegate, set.getDelegate()); assertEquals(2, delegate.size()); assertTrue(delegate.contains("foo")); @@ -110,7 +110,7 @@ public class LazySetTest { delegate = new HashSet<>(); set = newSingletonSet(delegate, "foo"); - assertTrue(set.addAll(Arrays.asList("bar", "baz"))); + assertTrue(set.addAll(List.of("bar", "baz"))); assertSame(delegate, set.getDelegate()); assertEquals(3, delegate.size()); assertTrue(delegate.contains("foo")); @@ -198,15 +198,15 @@ public class LazySetTest { assertFalse(set.remove("foo")); Mockito.verify(delegate).remove("foo"); - Collection<String> containsAllArg = Collections.singletonList("foo"); + Collection<String> containsAllArg = Set.of("foo"); assertFalse(set.containsAll(containsAllArg)); Mockito.verify(delegate).containsAll(containsAllArg); - Collection<String> retainAllArg = Collections.singletonList("foo"); + Collection<String> retainAllArg = Set.of("foo"); assertFalse(set.retainAll(retainAllArg)); Mockito.verify(delegate).retainAll(retainAllArg); - Collection<String> removeAllArg = Collections.singletonList("foo"); + Collection<String> removeAllArg = Set.of("foo"); assertFalse(set.removeAll(removeAllArg)); Mockito.verify(delegate).removeAll(removeAllArg); diff --git a/vespajlib/src/test/java/com/yahoo/collections/ListenableArrayListTestCase.java b/vespajlib/src/test/java/com/yahoo/collections/ListenableArrayListTestCase.java index 536e4d62502..adee795bb48 100644 --- a/vespajlib/src/test/java/com/yahoo/collections/ListenableArrayListTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/collections/ListenableArrayListTestCase.java @@ -4,7 +4,7 @@ package com.yahoo.collections; import org.junit.Test; import static org.junit.Assert.*; -import java.util.Arrays; +import java.util.List; import java.util.ListIterator; /** @@ -22,9 +22,9 @@ public class ListenableArrayListTestCase { assertEquals(1,listener.invoked); list.add(0,"b"); assertEquals(2,listener.invoked); - list.addAll(Arrays.asList(new String[]{"c", "d"})); + list.addAll(List.of(new String[]{"c", "d"})); assertEquals(3,listener.invoked); - list.addAll(1,Arrays.asList(new String[]{"e", "f"})); + list.addAll(1,List.of(new String[]{"e", "f"})); assertEquals(4,listener.invoked); list.set(0,"g"); assertEquals(5,listener.invoked); diff --git a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java index b1061fbc9ef..968746319d3 100644 --- a/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/io/reader/NamedReaderTestCase.java @@ -6,7 +6,6 @@ import java.io.Reader; import java.io.StringReader; import java.lang.reflect.Method; import java.nio.CharBuffer; -import java.util.Collections; import java.util.List; import com.yahoo.protect.ClassValidator; @@ -30,7 +29,7 @@ public class NamedReaderTestCase { assertEquals("test1",r.getName()); assertEquals("test1",r.toString()); assertEquals(stringReader,r.getReader()); - NamedReader.closeAll(Collections.singletonList(r)); + NamedReader.closeAll(List.of(r)); NamedReader.closeAll(null); // noop, nor exception } diff --git a/vespajlib/src/test/java/com/yahoo/net/UrlTokenizerTestCase.java b/vespajlib/src/test/java/com/yahoo/net/UrlTokenizerTestCase.java index 385d58db86f..100507c6cc1 100644 --- a/vespajlib/src/test/java/com/yahoo/net/UrlTokenizerTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/net/UrlTokenizerTestCase.java @@ -359,7 +359,7 @@ public class UrlTokenizerTestCase { } private static void assertTokenize(Url url, UrlToken... expected) { - Iterator<UrlToken> expectedIt = Arrays.asList(expected).iterator(); + Iterator<UrlToken> expectedIt = List.of(expected).iterator(); Iterator<UrlToken> actualIt = new UrlTokenizer(url).tokenize().iterator(); while (expectedIt.hasNext()) { assertTrue(actualIt.hasNext()); @@ -373,7 +373,7 @@ public class UrlTokenizerTestCase { List<UrlToken> actual = new LinkedList<>(); UrlTokenizer.addTokens(actual, UrlToken.Type.PATH, 0, img, true); - Iterator<String> expectedIt = Arrays.asList(expected).iterator(); + Iterator<String> expectedIt = List.of(expected).iterator(); Iterator<UrlToken> actualIt = actual.iterator(); while (expectedIt.hasNext()) { assertTrue(actualIt.hasNext()); diff --git a/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java index 528ca57d256..b5d36326774 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/IndexedTensorTestCase.java @@ -3,9 +3,9 @@ package com.yahoo.tensor; import org.junit.Test; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import static org.junit.Assert.assertEquals; @@ -139,7 +139,7 @@ public class IndexedTensorTestCase { Tensor.Builder builder = Tensor.Builder.of(type); builder.cell(47.0, 98); Tensor tensor = builder.build(); - assertEquals(47.0, tensor.sum(Collections.singletonList("x")).asDouble(), 0.000001); + assertEquals(47.0, tensor.sum(List.of("x")).asDouble(), 0.000001); } private void assertBuildingVWXYZ(TensorType type) { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java b/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java index 378e2397a89..6b0dbac8f2a 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/MatrixDotProductBenchmark.java @@ -9,7 +9,6 @@ import com.yahoo.tensor.functions.Join; import com.yahoo.tensor.functions.Reduce; import com.yahoo.tensor.functions.TensorFunction; -import java.util.Collections; import java.util.List; import java.util.Random; @@ -69,7 +68,7 @@ public class MatrixDotProductBenchmark { .value(random.nextDouble()); } } - return Collections.singletonList(builder.build()); + return List.of(builder.build()); } private static void addDimension(TensorType.Builder builder, String name, TensorType.Dimension.Type type, int size) { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java index 69fb71b9b0e..7a51ea300f4 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TensorTestCase.java @@ -11,7 +11,6 @@ import com.yahoo.tensor.functions.TensorFunction; import org.junit.Test; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.Set; import java.util.function.DoubleBinaryOperator; @@ -214,7 +213,7 @@ public class TensorTestCase { Tensor unitK = Tensor.Builder.of(new TensorType.Builder().mapped("k").build()).cell().label("k", 0).value(1).build(); Tensor vectorInJSpace = vector(Type.mapped).multiply(unitJ); Tensor matrixInKSpace = matrix(Type.mapped, 2).get(0).multiply(unitK); - assertEquals("Generic computation implementation", 42, (int)dotProduct(vectorInJSpace, Collections.singletonList(matrixInKSpace))); + assertEquals("Generic computation implementation", 42, (int)dotProduct(vectorInJSpace, List.of(matrixInKSpace))); } @Test @@ -458,7 +457,7 @@ public class TensorTestCase { .value((i+1)*(j+1)); } } - return Collections.singletonList(builder.build()); + return List.of(builder.build()); } private TensorType vectorType(TensorType.Builder builder, String name, TensorType.Dimension.Type type, int size) { diff --git a/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java b/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java index 5d267d4d2f1..ce17a5d846d 100644 --- a/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/tensor/TypeResolverTestCase.java @@ -3,7 +3,6 @@ package com.yahoo.tensor; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import org.junit.Test; @@ -17,7 +16,7 @@ import static org.junit.Assert.assertTrue; public class TypeResolverTestCase { private static List<String> mkl(String ...values) { - return Arrays.asList(values); + return List.of(values); } @Test |