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

jodd.util.CollectionUtil Maven / Gradle / Ivy

There is a newer version: 3.4.1
Show newest version
// Copyright (c) 2003-2010, Jodd Team (jodd.org). All Rights Reserved.

package jodd.util;

import jodd.util.collection.EnumerationIterator;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * Collection utilities.
 */
public class CollectionUtil {

	/**
	 * Adapts an enumeration to an iterator.
	 */
	public static  Iterator toIterator(Enumeration enumeration) {
		return new EnumerationIterator(enumeration);
	}

	/**
	 * Iterate elements to a list.
	 * Returns an empty list if there are no elements to iterate.
	 */
	public static  List iterateToList(Iterator iterator) {
		List list = new ArrayList();
		while (iterator.hasNext()) {
			list.add(iterator.next());
		}
		return list;
	}

	/**
	 * Iterate elements to a set.
	 * Returns an empty set if there are no elements to iterate.
	 */
	public static  Set iterateToSet(Iterator iterator) {
		Set set = new HashSet();
		while (iterator.hasNext()) {
			set.add(iterator.next());
		}
		return set;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy