Created a repository for collection related utility functions. Created
addAll() a function that adds all elements from an enumeration to a collection. Created another version that works with an Iterator rather than an Enumeration. git-svn-id: https://samskivert.googlecode.com/svn/trunk@202 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// $Id: CollectionUtil.java,v 1.1 2001/07/21 22:05:04 mdb Exp $
|
||||
|
||||
package com.samskivert.util;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A collection of collection-related utility functions.
|
||||
*/
|
||||
public class CollectionUtil
|
||||
{
|
||||
/**
|
||||
* Adds all items returned by the enumeration to the supplied
|
||||
* collection.
|
||||
*/
|
||||
public static void addAll (Collection col, Enumeration enum)
|
||||
{
|
||||
while (enum.hasMoreElements()) {
|
||||
col.add(enum.nextElement());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all items returned by the iterator to the supplied collection.
|
||||
*/
|
||||
public static void addAll (Collection col, Iterator iter)
|
||||
{
|
||||
while (iter.hasNext()) {
|
||||
col.add(iter.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user