Example #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;
 }
Example #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();
 }
Example #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;
 }
Example #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;
  }
Example #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;
  }
Example #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;
  }
Example #7
0
 public ISeq more() {
   seq();
   if (s == null) return PersistentList.EMPTY;
   return s.more();
 }
Example #8
0
 public ISeq next() {
   seq();
   if (s == null) return null;
   return s.next();
 }
Example #9
0
 public Object first() {
   seq();
   if (s == null) return null;
   return s.first();
 }
Example #10
0
 public int count() {
   int c = 0;
   for (ISeq s = seq(); s != null; s = s.next()) ++c;
   return c;
 }
Example #11
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;
 }
Example #12
0
 public boolean equals(Object o) {
   ISeq s = seq();
   if (s != null) return s.equiv(o);
   else return (o instanceof Sequential || o instanceof List) && RT.seq(o) == null;
 }
Example #13
0
 public ISeq next() {
   return create(seq.next());
 }
Example #14
0
 public Object first() {
   return ((Map.Entry) seq.first()).getValue();
 }