/*** 初始化ArrayList
*
*@paramelements
*@return
*/@SafeVarargspublic static ListcreateArrayList(T... elements) {
List list = new ArrayList();for(T element : elements) {
list.add(element);
}returnlist;
}public static boolean isEmpty(Collection>collection) {return (collection == null ||collection.isEmpty());
}public static boolean isNotEmpty(Collection>collection) {return (collection != null && !collection.isEmpty());
}/*** 获取两个集合的差集
*
*@parambig
* 大集合
*@paramsmall
* 小集合
*@return两个集合的差集*/
public static Collection getDiffSection(Collection big, Collectionsmall) {
Set differenceSet =Sets.difference(Sets.newHashSet(big), Sets.newHashSet(small));returnLists.newArrayList(differenceSet);
}public static List getDiffSection(Collectionbig, T obj) {
Set small = new HashSet();
small.add(obj);
Set differenceSet =Sets.difference(Sets.newHashSet(big), small);returnLists.newArrayList(differenceSet);
}/*** 获取两个集合的交集
*
*@paramc1
*@paramc2
*@return
*/
public static List getInterSection(Collection c1, Collectionc2) {
Set intersections =Sets.intersection(Sets.newHashSet(c1), Sets.newHashSet(c2));returnLists.newArrayList(intersections);
}/*** 获取两个集合的合集
*
*@paramc1
*@paramc2
*@return
*/
public static List getUnionSection(Collection c1, Collectionc2) {
c1.addAll(c2);
Set newHashSet =Sets.newHashSet(c1);returnLists.newArrayList(newHashSet);
}public static List> splitList(List list, intpageSize) {int listSize = list.size(); //list的大小
int page = (listSize + (pageSize - 1)) / pageSize; //页数
List> listArray = new ArrayList>(); //创建list数组 ,用来保存分割后的list
for (int i = 0; i < page; i++) { //按照数组大小遍历
List subList = new ArrayList(); //数组每一位放入一个分割后的list
for (int j = 0; j < listSize; j++) { //遍历待分割的list
int pageIndex = ((j + 1) + (pageSize - 1)) / pageSize; //当前记录的页码(第几页)
if (pageIndex == (i + 1)) { //当前记录的页码等于要放入的页码时
subList.add(list.get(j)); //放入list中的元素到分割后的list(subList)
}if ((j + 1) == ((j + 1) * pageSize)) { //当放满一页时退出当前循环
break;
}
}
listArray.add(subList);//将分割后的list放入对应的数组的位中
}returnlistArray;
}public static boolean isListEqual(Collection l0, Collectionl1) {if (l0 ==l1) {return true;
}if (l0 == null && l1 == null) {return true;
}if (l0 == null || l1 == null) {return false;
}if (l0.size() !=l1.size()) {return false;
}for(Object o : l0) {if (!l1.contains(o)) {return false;
}
}for(Object o : l1) {if (!l0.contains(o)) {return false;
}
}return true;
}