summaryrefslogtreecommitdiff
path: root/src/jvm/clojure/lang/APersistentMap.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jvm/clojure/lang/APersistentMap.java')
-rw-r--r--src/jvm/clojure/lang/APersistentMap.java78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/jvm/clojure/lang/APersistentMap.java b/src/jvm/clojure/lang/APersistentMap.java
index eff4e294..b595a53b 100644
--- a/src/jvm/clojure/lang/APersistentMap.java
+++ b/src/jvm/clojure/lang/APersistentMap.java
@@ -10,7 +10,9 @@
package clojure.lang;
-public abstract class APersistentMap extends AFn implements IPersistentMap{
+import java.util.Collection;
+
+public abstract class APersistentMap extends AFn implements IPersistentMap, Collection{
int _hash = -1;
@@ -138,4 +140,78 @@ static public class ValSeq extends ASeq{
public Object invoke(Object arg1) throws Exception{
return valAt(arg1);
}
+
+// java.util.Collection implementation
+
+public Object[] toArray(){
+ return RT.seqToArray(seq());
+}
+
+public boolean add(Object o){
+ throw new UnsupportedOperationException();
+}
+
+public boolean remove(Object o){
+ throw new UnsupportedOperationException();
+}
+
+public boolean addAll(Collection c){
+ throw new UnsupportedOperationException();
+}
+
+public void clear(){
+ throw new UnsupportedOperationException();
+}
+
+public boolean retainAll(Collection c){
+ throw new UnsupportedOperationException();
+}
+
+public boolean removeAll(Collection c){
+ throw new UnsupportedOperationException();
+}
+
+public boolean containsAll(Collection c){
+ for(Object o : c)
+ {
+ if(contains(o))
+ return true;
+ }
+ return false;
+}
+
+public Object[] toArray(Object[] a){
+ if(a.length >= count())
+ {
+ ISeq s = seq();
+ for(int i = 0; s != null; ++i, s = s.rest())
+ {
+ a[i] = s.first();
+ }
+ if(a.length >= count())
+ a[count()] = null;
+ return a;
+ }
+ else
+ return toArray();
+}
+
+public int size(){
+ return count();
+}
+
+public boolean isEmpty(){
+ return count() == 0;
+}
+
+public boolean contains(Object o){
+ if(o instanceof IMapEntry)
+ {
+ IMapEntry e = (IMapEntry) o;
+ IMapEntry v = entryAt(e.key());
+ return (v != null && RT.equal(v.val(), e.val()));
+ }
+ return false;
+}
+
}