示例#1
0
 public int indexOf(Object o) {
   ISeq s = seq();
   for (int i = 0; s != null; s = s.next(), i++) {
     if (Util.equiv(s.first(), o)) return i;
   }
   return -1;
 }
示例#2
0
 public Object[] toArray(Object[] a) {
   if (a.length >= count()) {
     ISeq s = seq();
     for (int i = 0; s != null; ++i, s = s.next()) {
       a[i] = s.first();
     }
     if (a.length > count()) a[count()] = null;
     return a;
   } else return toArray();
 }
示例#3
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;
 }
示例#4
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;
  }
示例#5
0
  public boolean equiv(Object obj) {
    if (!(obj instanceof Map)) return false;
    if (obj instanceof IPersistentMap && !(obj instanceof MapEquivalence)) return false;

    Map m = (Map) obj;

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

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

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

    return true;
  }
示例#6
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;
  }
示例#7
0
 public ISeq next() {
   seq();
   if (s == null) return null;
   return s.next();
 }
示例#8
0
 public int count() {
   int c = 0;
   for (ISeq s = seq(); s != null; s = s.next()) ++c;
   return c;
 }
示例#9
0
 public boolean contains(Object o) {
   for (ISeq s = seq(); s != null; s = s.next()) {
     if (Util.equiv(s.first(), o)) return true;
   }
   return false;
 }
示例#10
0
 public ISeq next() {
   return create(seq.next());
 }