All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.blade.kit.CollectionKit Maven / Gradle / Ivy

There is a newer version: 2.0.15.RELEASE
Show newest version
/**
 * Copyright (c) 2017, 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 com.blade.kit; import lombok.experimental.UtilityClass; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; /** * Collection kit * * @author biezhi * @date 2017/12/15 */ @UtilityClass public class CollectionKit { /** * Determines whether an array is empty * * @param array array object * @param array type * @return return array is empty */ public static boolean isEmpty(T[] array) { return null == array || array.length == 0; } /** * Determines whether an array is not empty * * @param array array object * @param array type * @return return array is not empty */ public static boolean isNotEmpty(T[] array) { return null != array && array.length > 0; } /** * Determines whether an collection is empty * * @param collection collection object * @param collection type * @return return collection is empty */ public static boolean isEmpty(Collection collection) { return null == collection || collection.size() == 0; } /** * Determines whether an collection is not empty * * @param collection collection object * @param collection type * @return return collection is not empty */ public static boolean isNotEmpty(Collection collection) { return null != collection && collection.size() > 0; } /** * New HashMap * * @param HashMap Key type * @param HashMap Value type * @return return HashMap */ public static HashMap newMap() { return new HashMap<>(); } /** * New HashMap and initialCapacity * * @param initialCapacity initialCapacity * @param HashMap Key type * @param HashMap Value type * @return return HashMap */ public static HashMap newMap(int initialCapacity) { return new HashMap<>(initialCapacity); } /** * New ConcurrentMap * * @param ConcurrentMap Key type * @param ConcurrentMap Value type * @return return ConcurrentMap */ public static ConcurrentMap newConcurrentMap() { return new ConcurrentHashMap<>(); } /** * New ConcurrentMap and initialCapacity * * @param initialCapacity initialCapacity * @param ConcurrentMap Key type * @param ConcurrentMap Value type * @return return ConcurrentMap */ public static ConcurrentMap newConcurrentMap(int initialCapacity) { return new ConcurrentHashMap<>(initialCapacity); } /** * New List and add values * * @param values list values * @param list type * @return return array list */ @SafeVarargs public static List newLists(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return Arrays.asList(values); } /** * New Set and add values * * @param values set values * @param set type * @return return HashSet */ @SafeVarargs public static Set newSets(T... values) { if(null == values || values.length == 0){ Assert.notNull(values, "values not is null."); } return new HashSet<>(Arrays.asList(values)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy