generator.server.javatool.base.main.collection.ProjectCollections.mustache Maven / Gradle / Ivy
package {{packageName}}.shared.collection.domain;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Null safe utility class to manage collections
*/
public final class {{ baseName }}Collections {
private {{ baseName }}Collections() {}
/**
* Get an immutable collection from the given collection
*
* @param
* Type of this collection
* @param collection
* input collection
* @return An immutable collection
*/
public static Collection immutable(Collection extends T> collection) {
if (collection == null) {
return Set.of();
}
return Collections.unmodifiableCollection(collection);
}
/**
* Get an immutable set from the given set
*
* @param
* Type of this set
* @param set
* input set
* @return An immutable set
*/
public static Set immutable(Set extends T> set) {
if (set == null) {
return Set.of();
}
return Collections.unmodifiableSet(set);
}
/**
* Get an immutable set from the given list
*
* @param
* Type of this list
* @param list
* input list
* @return An immutable list
*/
public static List immutable(List extends T> list) {
if (list == null) {
return List.of();
}
return Collections.unmodifiableList(list);
}
/**
* Get an immutable map from the given map
*
* @param Key type of this map
* @param value type of this map
* @return An immutable map
*/
public static Map immutable(Map extends K, ? extends V> map) {
if (map == null) {
return Map.of();
}
return Collections.unmodifiableMap(map);
}
}