From 469e2d169fdba9cc995fae5e73cfbce62eba1b43 Mon Sep 17 00:00:00 2001 From: mdb Date: Sat, 21 Jul 2001 22:05:04 +0000 Subject: [PATCH] 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 --- .../com/samskivert/util/CollectionUtil.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 projects/samskivert/src/java/com/samskivert/util/CollectionUtil.java diff --git a/projects/samskivert/src/java/com/samskivert/util/CollectionUtil.java b/projects/samskivert/src/java/com/samskivert/util/CollectionUtil.java new file mode 100644 index 00000000..632f7f7b --- /dev/null +++ b/projects/samskivert/src/java/com/samskivert/util/CollectionUtil.java @@ -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()); + } + } +}