From 71e52d355e2ab3c33669a7df06a1c5f1f5d391c3 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 22 Jan 2014 13:38:14 -0800 Subject: [PATCH] Added toArrayList(). If we're going to tell you to use an ArrayList instead of toArray(), let's make that easy. This would be unnecessary if there was an ArrayList constructor that took Iterable, but there isn't. And DSet is not a Collection. --- .../com/threerings/presents/dobj/DSet.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/com/threerings/presents/dobj/DSet.java b/core/src/main/java/com/threerings/presents/dobj/DSet.java index 3b8921768..7cea3f879 100644 --- a/core/src/main/java/com/threerings/presents/dobj/DSet.java +++ b/core/src/main/java/com/threerings/presents/dobj/DSet.java @@ -22,6 +22,7 @@ package com.threerings.presents.dobj; import java.util.AbstractSet; +import java.util.ArrayList; import java.util.Comparator; import java.util.ConcurrentModificationException; import java.util.Iterator; @@ -280,14 +281,15 @@ public class DSet } /** - * Copies the elements of this distributed set into the supplied array. If the array is not - * large enough to hold all of the elements, as many as fit into the array will be copied. If - * the array argument is null, an object array of sufficient size to contain all - * of the elements of this set will be created and returned. - * - * @deprecated use {@link #clone} or add this to an ArrayList. Arrays are an untypesafe - * quagmire. + * Copies the elements of this distributed set into a newly created {@link ArrayList}. */ + public ArrayList toArrayList () { + ArrayList list = new ArrayList(size()); + for (E elem : this) list.add(elem); + return list; + } + + /** @deprecated use {@link #clone} or {@link #toArrayList}. */ @Deprecated public E[] toArray (E[] array) { @@ -299,10 +301,7 @@ public class DSet return array; } - /** - * @deprecated use {@link #clone} or add this to an ArrayList. Arrays are an untypesafe - * quagmire. - */ + /** @deprecated use {@link #clone} or {@link #toArrayList}. */ @Deprecated public Object[] toArray (Object[] array) {