dev.robocode.tankroyale.botapi.util.CollectionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of robocode-tankroyale-bot-api Show documentation
Show all versions of robocode-tankroyale-bot-api Show documentation
Robocode Tank Royale Bot API for Java
The newest version!
package dev.robocode.tankroyale.botapi.util;
import java.util.*;
/**
* Collection utility class.
*/
public final class CollectionUtil {
// Hides constructor
private CollectionUtil() {
}
/**
* Creates a mutable list that is a copy of another list.
*
* @param list is the list to copy, where {@code null} results in returning an empty mutable list.
* @return a mutable list that is a copy of the input list.
*/
public static List toMutableList(List list) {
return list == null ? new ArrayList<>() : new ArrayList<>(list);
}
/**
* Creates a mutable set that copies all items from a collection, but is removing duplicates.
*
* @param collection is the collection to copy, where {@code null} results in returning an empty mutable set.
* @return a mutable set that is a copy of the input collection.
*/
public static Set toMutableSet(Collection collection) {
return collection == null ? new HashSet<>() : new HashSet<>(collection);
}
}