add FastSet.first() for quick access to the first element of a FastSet
authoradam <adam@megacz.com>
Tue, 4 Mar 2008 04:06:40 +0000 (23:06 -0500)
committeradam <adam@megacz.com>
Tue, 4 Mar 2008 04:06:40 +0000 (23:06 -0500)
darcs-hash:20080304040640-5007d-bb4ef3dcf9eba44ce411de64a2f5fb565787e660.gz

src/edu/berkeley/sbp/util/FastSet.java

index 4e289cd..581886e 100644 (file)
@@ -22,6 +22,12 @@ public /*final*/ class FastSet<T> implements Iterator<T>, Iterable<T>, Visitable
         return (T)array[i];
     }
 
         return (T)array[i];
     }
 
+    public T first() {
+        if (only != null) return only;
+        if (array != null) return (T)(array[0]);
+        return null;
+    }
+
     public FastSet() { }
     public FastSet(T t) { only = t; }
     public FastSet(Set<T> s) {
     public FastSet() { }
     public FastSet(T t) { only = t; }
     public FastSet(Set<T> s) {