| 14 | import java.util.*; |
| 15 | |
| 16 | public abstract class APersistentMap extends AFn implements IPersistentMap, Map, Iterable, Serializable, MapEquivalence, IHashEq { |
| 17 | |
| 18 | private static final long serialVersionUID = 6736310834519110267L; |
| 19 | |
| 20 | int _hash; |
| 21 | int _hasheq; |
| 22 | |
| 23 | public String toString(){ |
| 24 | return RT.printString(this); |
| 25 | } |
| 26 | |
| 27 | public 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 | |
| 51 | public boolean equals(Object obj){ |
| 52 | return mapEquals(this, obj); |
| 53 | } |
| 54 | |
| 55 | static 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; |
nothing calls this directly
no outgoing calls
no test coverage detected