package com.hwlcn.security.util;
import com.hwlcn.security.subject.PrincipalCollection;
import java.util.*;
public class CollectionUtils {
public static <E> Set<E> asSet(E... elements) {
if (elements == null || elements.length == 0) {
return Collections.emptySet();
}
LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1);
Collections.addAll(set, elements);
return set;
}
public static boolean isEmpty(Collection c) {
return c == null || c.isEmpty();
}
public static boolean isEmpty(Map m) {
return m == null || m.isEmpty();
}
public static int size(Collection c) {
return c != null ? c.size() : 0;
}
public static int size(Map m) {
return m != null ? m.size() : 0;
}
public static boolean isEmpty(PrincipalCollection principals) {
return principals == null || principals.isEmpty();
}
public static <E> List<E> asList(E... elements) {
if (elements == null || elements.length == 0) {
return Collections.emptyList();
}
int capacity = computeListCapacity(elements.length);
ArrayList<E> list = new ArrayList<E>(capacity);
Collections.addAll(list, elements);
return list;
}
static int computeListCapacity(int arraySize) {
return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE);
}
}