
org.unique.commons.utils.CollectionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unique-web Show documentation
Show all versions of unique-web Show documentation
unique-web is a lightweight Java Web Framework
The newest version!
/**
* Copyright (c) 2014-2015, biezhi 王爵 ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.unique.commons.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
/**
* collection util
* @author biezhi
* @since 1.0
*/
public class CollectionUtil {
/**
* new HashMap
*/
public static HashMap newHashMap() {
return new HashMap();
}
/**
* new HashMap and initialCapacity
*/
public static HashMap newHashMap(int size) {
return new HashMap();
}
/**
* new concurrentHashMap
*/
public static ConcurrentHashMap newConcurrentHashMap() {
return new ConcurrentHashMap();
}
/**
* new concurrentHashMap and initialCapacity
*/
public static ConcurrentHashMap newConcurrentHashMap(int size) {
return new ConcurrentHashMap(size);
}
/**
* new ArrayList
*/
public static ArrayList newArrayList() {
return new ArrayList();
}
/**
* new ArrayList and initialCapacity
*/
public static ArrayList newArrayList(int size) {
return new ArrayList(size);
}
/**
* new HashSet
*/
public static HashSet newHashSet() {
return new HashSet();
}
/**
* new HashSet and initialCapacity
*/
public static HashSet newHashSet(int size) {
return new HashSet(size);
}
/**
* new TreeSet
*/
public static TreeSet newTreeSet() {
return new TreeSet();
}
/**
* map sort
*/
public static Map sortMap(Map map, Comparator> compator) {
Map result = new LinkedHashMap();
List> entries = new ArrayList>(map.entrySet());
Collections.sort(entries, compator);
for (Entry entry : entries) {
result.put(entry.getKey(), entry.getValue());
}
return result;
}
/**
* return collection is empty
*/
public static boolean isEmpty(Collection c){
return (null == c || c.isEmpty());
}
/**
* return map is empty
*/
public static boolean isEmpty(Map map){
return (null == map || map.isEmpty());
}
/**
* return array is empty
*/
public static boolean isEmpty(T[] arr){
return null == arr || arr.length == 0;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy