![JAR search and dependency download from the Maven repository](/logo.png)
nl.siegmann.epublib.util.CollectionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of epublib-core Show documentation
Show all versions of epublib-core Show documentation
A java library for reading/writing/manipulating epub files
The newest version!
package nl.siegmann.epublib.util;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
public class CollectionUtil {
/**
* Wraps an Enumeration around an Iterator
* @author paul.siegmann
*
* @param
*/
private static class IteratorEnumerationAdapter implements Enumeration {
private Iterator iterator;
public IteratorEnumerationAdapter(Iterator iter) {
this.iterator = iter;
}
@Override
public boolean hasMoreElements() {
return iterator.hasNext();
}
@Override
public T nextElement() {
return iterator.next();
}
}
/**
* Creates an Enumeration out of the given Iterator.
* @param
* @param it
* @return an Enumeration created out of the given Iterator.
*/
public static Enumeration createEnumerationFromIterator(Iterator it) {
return new IteratorEnumerationAdapter(it);
}
/**
* Returns the first element of the list, null if the list is null or empty.
*
* @param
* @param list
* @return the first element of the list, null if the list is null or empty.
*/
public static T first(List list) {
if(list == null || list.isEmpty()) {
return null;
}
return list.get(0);
}
/**
* Whether the given collection is null or has no elements.
*
* @param collection
* @return Whether the given collection is null or has no elements.
*/
public static boolean isEmpty(Collection> collection) {
return collection == null || collection.isEmpty();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy