Ejemplo n.º 1
0
  public static boolean mapEquals(IPersistentMap m1, Object obj) {
    if (m1 == obj) return true;
    if (!(obj instanceof Map)) return false;
    Map m = (Map) obj;

    if (m.size() != m1.count()) return false;

    for (ISeq s = m1.seq(); s != null; s = s.next()) {
      Map.Entry e = (Map.Entry) s.first();
      boolean found = m.containsKey(e.getKey());

      if (!found || !Util.equals(e.getValue(), m.get(e.getKey()))) return false;
    }

    return true;
  }
Ejemplo n.º 2
0
 public static int mapHash(IPersistentMap m) {
   int hash = 0;
   for (ISeq s = m.seq(); s != null; s = s.next()) {
     Map.Entry e = (Map.Entry) s.first();
     hash +=
         (e.getKey() == null ? 0 : e.getKey().hashCode())
             ^ (e.getValue() == null ? 0 : e.getValue().hashCode());
   }
   return hash;
 }
Ejemplo n.º 3
0
  public IPersistentCollection cons(Object o) {
    if (o instanceof Map.Entry) {
      Map.Entry e = (Map.Entry) o;

      return assoc(e.getKey(), e.getValue());
    } else if (o instanceof IPersistentVector) {
      IPersistentVector v = (IPersistentVector) o;
      if (v.count() != 2)
        throw new IllegalArgumentException("Vector arg to map conj must be a pair");
      return assoc(v.nth(0), v.nth(1));
    }

    IPersistentMap ret = this;
    for (ISeq es = RT.seq(o); es != null; es = es.next()) {
      Map.Entry e = (Map.Entry) es.first();
      ret = ret.assoc(e.getKey(), e.getValue());
    }
    return ret;
  }