MCPcopy Index your code
hub / github.com/clojure/clojure / APersistentMap

Class APersistentMap

src/jvm/clojure/lang/APersistentMap.java:16–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14import java.util.*;
15
16public abstract class APersistentMap extends AFn implements IPersistentMap, Map, Iterable, Serializable, MapEquivalence, IHashEq {
17
18private static final long serialVersionUID = 6736310834519110267L;
19
20int _hash;
21int _hasheq;
22
23public String toString(){
24 return RT.printString(this);
25}
26
27public IPersistentCollection cons(Object o){
28 if(o instanceof Map.Entry)
29 {
30 Map.Entry e = (Map.Entry) o;
31
32 return assoc(e.getKey(), e.getValue());
33 }
34 else if(o instanceof IPersistentVector)
35 {
36 IPersistentVector v = (IPersistentVector) o;
37 if(v.count() != 2)
38 throw new IllegalArgumentException("Vector arg to map conj must be a pair");
39 return assoc(v.nth(0), v.nth(1));
40 }
41
42 IPersistentMap ret = this;
43 for(ISeq es = RT.seq(o); es != null; es = es.next())
44 {
45 Map.Entry e = (Map.Entry) es.first();
46 ret = ret.assoc(e.getKey(), e.getValue());
47 }
48 return ret;
49}
50
51public boolean equals(Object obj){
52 return mapEquals(this, obj);
53}
54
55static public boolean mapEquals(IPersistentMap m1, Object obj){
56 if(m1 == obj) return true;
57 if(!(obj instanceof Map))
58 return false;
59 Map m = (Map) obj;
60
61 if(m.size() != m1.count())
62 return false;
63
64 for(ISeq s = m1.seq(); s != null; s = s.next())
65 {
66 Map.Entry e = (Map.Entry) s.first();
67 boolean found = m.containsKey(e.getKey());
68
69 if(!found || !Util.equals(e.getValue(), m.get(e.getKey())))
70 return false;
71 }
72
73 return true;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected