summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-08-06 14:20:35 +0000
committerRich Hickey <richhickey@gmail.com>2008-08-06 14:20:35 +0000
commitc4d627948776f6622ace56e931a1922911ff43c7 (patch)
tree379bc52b66828481f0b6b035ab00c8a3b32666b4 /src
parent060aa171217ee2cff9616c3134e4c20d35134ab2 (diff)
made empty lists implement java.util.Collection
Diffstat (limited to 'src')
-rw-r--r--src/jvm/clojure/lang/PersistentList.java78
1 files changed, 72 insertions, 6 deletions
diff --git a/src/jvm/clojure/lang/PersistentList.java b/src/jvm/clojure/lang/PersistentList.java
index 930cd887..55d5d2f2 100644
--- a/src/jvm/clojure/lang/PersistentList.java
+++ b/src/jvm/clojure/lang/PersistentList.java
@@ -10,9 +10,7 @@
package clojure.lang;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.LinkedList;
+import java.util.*;
public class PersistentList extends ASeq implements IPersistentList, IReduce{
@@ -33,7 +31,7 @@ public static IFn creator = new RestFn(0){
LinkedList list = new LinkedList();
for(ISeq s = RT.seq(args); s != null; s = s.rest())
list.add(s.first());
- return create(list);
+ return create(list);
}
};
@@ -91,7 +89,7 @@ public PersistentList cons(Object o){
}
public IPersistentCollection empty(){
- return EMPTY.withMeta(meta());
+ return EMPTY.withMeta(meta());
}
public PersistentList withMeta(IPersistentMap meta){
@@ -114,7 +112,7 @@ public Object reduce(IFn f, Object start) throws Exception{
return ret;
}
-static class EmptyList extends Obj implements IPersistentList{
+static class EmptyList extends Obj implements IPersistentList, Collection{
EmptyList(IPersistentMap meta){
super(meta);
@@ -149,6 +147,74 @@ static class EmptyList extends Obj implements IPersistentList{
public ISeq seq(){
return null;
}
+
+
+ public int size(){
+ return 0;
+ }
+
+ public boolean isEmpty(){
+ return true;
+ }
+
+ public boolean contains(Object o){
+ return false;
+ }
+
+ public Iterator iterator(){
+ return new Iterator(){
+
+ public boolean hasNext(){
+ return false;
+ }
+
+ public Object next(){
+ throw new NoSuchElementException();
+ }
+
+ public void remove(){
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public Object[] toArray(){
+ return RT.EMPTY_ARRAY;
+ }
+
+ public boolean add(Object o){
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean remove(Object o){
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean addAll(Collection collection){
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear(){
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean retainAll(Collection collection){
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean removeAll(Collection collection){
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean containsAll(Collection collection){
+ return collection.isEmpty();
+ }
+
+ public Object[] toArray(Object[] objects){
+ if(objects.length > 0)
+ objects[0] = null;
+ return objects;
+ }
}
}