diff options
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/collections')
23 files changed, 76 insertions, 22 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java b/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java index 03d503ac501..9575e18e218 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/AbstractFilteringList.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.ArrayList; diff --git a/vespajlib/src/main/java/com/yahoo/collections/ArraySet.java b/vespajlib/src/main/java/com/yahoo/collections/ArraySet.java index c8f685e75c2..90f055a3801 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ArraySet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ArraySet.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Arrays; diff --git a/vespajlib/src/main/java/com/yahoo/collections/BobHash.java b/vespajlib/src/main/java/com/yahoo/collections/BobHash.java index 3d1e82743cc..2203c57fa67 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/BobHash.java +++ b/vespajlib/src/main/java/com/yahoo/collections/BobHash.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import com.yahoo.text.Utf8; diff --git a/vespajlib/src/main/java/com/yahoo/collections/ByteArrayComparator.java b/vespajlib/src/main/java/com/yahoo/collections/ByteArrayComparator.java index d184ad50da2..a9be4fb8dbe 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ByteArrayComparator.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ByteArrayComparator.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; /** diff --git a/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java b/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java index d936bbe41d4..a1123239293 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CollectionComparator.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Collection; diff --git a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java index 58d39e097d8..7f70256233e 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CollectionUtil.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.ArrayList; diff --git a/vespajlib/src/main/java/com/yahoo/collections/Comparables.java b/vespajlib/src/main/java/com/yahoo/collections/Comparables.java index 1f97cdd1ee3..2e6c8fc82b3 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Comparables.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Comparables.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; diff --git a/vespajlib/src/main/java/com/yahoo/collections/CopyOnWriteHashMap.java b/vespajlib/src/main/java/com/yahoo/collections/CopyOnWriteHashMap.java index 218d0c407ec..ec4f7eec5d0 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/CopyOnWriteHashMap.java +++ b/vespajlib/src/main/java/com/yahoo/collections/CopyOnWriteHashMap.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.AbstractMap; diff --git a/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java index 43ba88cf10c..fba973e3380 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/FreezableArrayList.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Collection; diff --git a/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java b/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java index bfd62a4c9fd..1fe986a3270 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Hashlet.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; diff --git a/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java b/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java index 59c0ac5758c..bc14c9c3fee 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java +++ b/vespajlib/src/main/java/com/yahoo/collections/IntArrayComparator.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; /** diff --git a/vespajlib/src/main/java/com/yahoo/collections/Iterables.java b/vespajlib/src/main/java/com/yahoo/collections/Iterables.java index 904db7a3db7..dfbf4024ce4 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Iterables.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Iterables.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Iterator; diff --git a/vespajlib/src/main/java/com/yahoo/collections/LazyMap.java b/vespajlib/src/main/java/com/yahoo/collections/LazyMap.java index d8fc77cf6a0..9d0df495f9a 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/LazyMap.java +++ b/vespajlib/src/main/java/com/yahoo/collections/LazyMap.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.AbstractMap; diff --git a/vespajlib/src/main/java/com/yahoo/collections/LazySet.java b/vespajlib/src/main/java/com/yahoo/collections/LazySet.java index 4daa671cea3..4d284fd278d 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/LazySet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/LazySet.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.AbstractSet; diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java index d802012e71a..32b1ced15d7 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListMap.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListMap.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.lang.reflect.InvocationTargetException; diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java index 9a807d0fcc7..8ace7598e27 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.ArrayList; diff --git a/vespajlib/src/main/java/com/yahoo/collections/MD5.java b/vespajlib/src/main/java/com/yahoo/collections/MD5.java index bc1a8b29c64..6bd32b62b74 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MD5.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MD5.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import com.yahoo.text.Utf8; diff --git a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java index 700f16ee519..f829f6c2289 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java +++ b/vespajlib/src/main/java/com/yahoo/collections/MethodCache.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import com.yahoo.concurrent.CopyOnWriteHashMap; diff --git a/vespajlib/src/main/java/com/yahoo/collections/Optionals.java b/vespajlib/src/main/java/com/yahoo/collections/Optionals.java new file mode 100644 index 00000000000..27a1e837900 --- /dev/null +++ b/vespajlib/src/main/java/com/yahoo/collections/Optionals.java @@ -0,0 +1,54 @@ +package com.yahoo.collections; + +import com.google.common.collect.Comparators; + +import java.util.Optional; +import java.util.function.BinaryOperator; + +/** + * @author jonmv + */ +public class Optionals { + + private Optionals() { } + + /** Returns the first non-empty optional, or empty if all are empty. */ + @SafeVarargs + public static <T> Optional<T> firstNonEmpty(Optional<T>... optionals) { + for (Optional<T> optional : optionals) + if (optional.isPresent()) + return optional; + return Optional.empty(); + } + + /** Returns the non-empty optional with the lowest value, or empty if all are empty. */ + @SafeVarargs + public static <T extends Comparable<T>> Optional<T> min(Optional<T>... optionals) { + Optional<T> best = Optional.empty(); + for (Optional<T> optional : optionals) + if (best.isEmpty() || optional.isPresent() && optional.get().compareTo(best.get()) < 0) + best = optional; + return best; + } + + /** Returns the non-empty optional with the highest value, or empty if all are empty. */ + @SafeVarargs + public static <T extends Comparable<T>> Optional<T> max(Optional<T>... optionals) { + Optional<T> best = Optional.empty(); + for (Optional<T> optional : optionals) + if (best.isEmpty() || optional.isPresent() && optional.get().compareTo(best.get()) > 0) + best = optional; + return best; + } + + /** Returns whether either optional is empty, or both are present and equal. */ + public static <T> boolean equalIfBothPresent(Optional<T> first, Optional<T> second) { + return first.isEmpty() || second.isEmpty() || first.equals(second); + } + + /** Returns whether the optional is empty, or present and equal to the given value. */ + public static <T> boolean emptyOrEqual(Optional<T> optional, T value) { + return optional.isEmpty() || optional.equals(Optional.of(value)); + } + +} diff --git a/vespajlib/src/main/java/com/yahoo/collections/Pair.java b/vespajlib/src/main/java/com/yahoo/collections/Pair.java index baddcedd38c..dee35f2bbb7 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Pair.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Pair.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Objects; diff --git a/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java b/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java index f9fe365c4c7..1cc68777c88 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java +++ b/vespajlib/src/main/java/com/yahoo/collections/TinyIdentitySet.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; import java.util.Arrays; diff --git a/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java b/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java index 4ee02c45efa..adb953697e3 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java +++ b/vespajlib/src/main/java/com/yahoo/collections/Tuple2.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.collections; /** diff --git a/vespajlib/src/main/java/com/yahoo/collections/package-info.java b/vespajlib/src/main/java/com/yahoo/collections/package-info.java index 03b5b9e0f8d..c7f9eb1cf73 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/package-info.java +++ b/vespajlib/src/main/java/com/yahoo/collections/package-info.java @@ -1,4 +1,4 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. @ExportPackage package com.yahoo.collections; |