checkpoint
authoradam <adam@megacz.com>
Sun, 16 Jul 2006 07:19:39 +0000 (03:19 -0400)
committeradam <adam@megacz.com>
Sun, 16 Jul 2006 07:19:39 +0000 (03:19 -0400)
darcs-hash:20060716071939-5007d-1943bc593f4c5f6b1f5fa38a3412812ee9f200de.gz

src/edu/berkeley/sbp/Tree.java
src/edu/berkeley/sbp/util/ArrayUtil.java

index 7dbda47..1b9ddfa 100644 (file)
@@ -48,10 +48,7 @@ public class Tree<T>
         this.location = loc;
         this.head = head;
         this.lift = lift && children != null && children.length > 0;
         this.location = loc;
         this.head = head;
         this.lift = lift && children != null && children.length > 0;
-
-        Tree<T>[] children2 = children==null ? new Tree[0] : new Tree[children.length];
-        if (children != null) System.arraycopy(children, 0, children2, 0, children.length);
-        this.children = children2;
+        this.children = ArrayUtil.clone(children, Tree.class);
     }
 
 
     }
 
 
@@ -86,6 +83,9 @@ public class Tree<T>
     public boolean isTransparent() { return false; }
     public boolean isHidden() { return false; }
 
     public boolean isTransparent() { return false; }
     public boolean isHidden() { return false; }
 
+
+    // TreeFunctor /////////////////////////////////////////////////////////////////////////////
+
     public static interface TreeFunctor<T,R> extends Functor<Iterable<Tree<T>>, R> { }
     
 }
     public static interface TreeFunctor<T,R> extends Functor<Iterable<Tree<T>>, R> { }
     
 }
index f4f7278..d52de30 100644 (file)
@@ -11,4 +11,10 @@ public class ArrayUtil {
       return ret;
   }
 
       return ret;
   }
 
+    public static <T> T[] clone(T[] source, Class<T> c) {
+        T[] dest = (T[])Array.newInstance(c, source==null ? 0 : source.length);
+        if (source != null) System.arraycopy(source, 0, dest, 0, source.length);
+        return dest;
+    }
+
 }
 }