Summary Table

Categories Total Count
PII 0
URL 0
DNS 0
EKL 0
IP 0
PORT 0
VsID 0
CF 0
AI 0
VPD 0
PL 0
Other 0

File Content

package gov.va.med.pbm.ampl.utility;

import java.util.Collection;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* A common core of collection operations.
*
* @author Ian Meinert
* @since 1.0
*
*/
public class CollectionUtility {

/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(CollectionUtility.class);

/**
* Default constructor for the static methods.
*/
private CollectionUtility() {
// Not used.
}

/**
* This method determines if a given collection is null or empty.
*
* @param collection A collection of unknown objects
* @return whether or not the collection is null or empty
*/
public static boolean isNullOrEmpty(final Collection<?> collection) {
return collection == null || collection.isEmpty();
}

/**
* This method determines if a given map is null or empty.
*
* @param map A map of unknown objects
* @return whether or not the map is null or empty
*/
public static boolean isNullOrEmpty(final Map<?, ?> map) {
return map == null || map.isEmpty();
}

/**
* Retrieves a random element from an array of Objects.
*
* @param array the array to randomly pick from
* @return Object
*/
public static Object getRandom(Object[] array) {
int rnd = NumberUtility.randomBetween(0, array.length);
return array[rnd];
}
}