@InterfaceAudience.Private public class CollectionUtils extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
CollectionUtils.IOExceptionSupplier<V>
A supplier that throws IOException when get.
|
Modifier and Type | Field and Description |
---|---|
private static List<Object> |
EMPTY_LIST |
Constructor and Description |
---|
CollectionUtils() |
Modifier and Type | Method and Description |
---|---|
static <K,V> V |
computeIfAbsent(ConcurrentMap<K,V> map,
K key,
Supplier<V> supplier)
In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the
value already exists.
|
static <K,V> V |
computeIfAbsent(ConcurrentMap<K,V> map,
K key,
Supplier<V> supplier,
Runnable actionIfAbsent) |
static <K,V> V |
computeIfAbsentEx(ConcurrentMap<K,V> map,
K key,
CollectionUtils.IOExceptionSupplier<V> supplier)
In HBASE-16648 we found that ConcurrentHashMap.get is much faster than computeIfAbsent if the
value already exists.
|
static <T> T |
getFirst(Collection<T> collection)
first/last
|
static <T> T |
getLast(List<T> list) |
static int |
getLastIndex(List<?> list) |
static <T> boolean |
isEmpty(Collection<T> collection)
empty
|
static boolean |
isLastIndex(List<?> list,
int index) |
static <T> boolean |
notEmpty(Collection<T> collection) |
static <T> Collection<T> |
nullSafe(Collection<T> in) |
static <A,B> boolean |
nullSafeSameSize(Collection<A> a,
Collection<B> b) |
static <T> int |
nullSafeSize(Collection<T> collection)
size
|
private static final List<Object> EMPTY_LIST
public CollectionUtils()
public static <T> Collection<T> nullSafe(Collection<T> in)
public static <T> int nullSafeSize(Collection<T> collection)
public static <A,B> boolean nullSafeSameSize(Collection<A> a, Collection<B> b)
public static <T> boolean isEmpty(Collection<T> collection)
public static <T> boolean notEmpty(Collection<T> collection)
public static <T> T getFirst(Collection<T> collection)
public static int getLastIndex(List<?> list)
list
- any listpublic static boolean isLastIndex(List<?> list, int index)
list
- index
- the index in questionpublic static <K,V> V computeIfAbsent(ConcurrentMap<K,V> map, K key, Supplier<V> supplier)
public static <K,V> V computeIfAbsentEx(ConcurrentMap<K,V> map, K key, CollectionUtils.IOExceptionSupplier<V> supplier) throws IOException
ConcurrentMap.computeIfAbsent(Object, java.util.function.Function)
. It uses get and
putIfAbsent to implement computeIfAbsent. And notice that the implementation does not guarantee
that the supplier will only be executed once.IOException
public static <K,V> V computeIfAbsent(ConcurrentMap<K,V> map, K key, Supplier<V> supplier, Runnable actionIfAbsent)
Copyright © 2007–2019 The Apache Software Foundation. All rights reserved.