Example #1
0
  public boolean equals(Object obj) {

    if (!(obj instanceof Sequential)) return false;
    ISeq ms = RT.seq(obj);
    for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) {
      if (ms == null || !Util.equals(s.first(), ms.first())) return false;
    }
    return ms == null;
  }
Example #2
0
 public PersistentQueue pop() {
   if (f == null) // hmmm... pop of empty queue -> empty queue?
   return this;
   // throw new IllegalStateException("popping empty queue");
   ISeq f1 = f.next();
   PersistentVector r1 = r;
   if (f1 == null) {
     f1 = RT.seq(r);
     r1 = null;
   }
   return new PersistentQueue(meta(), cnt - 1, f1, r1);
 }
Example #3
0
 public final synchronized ISeq seq() {
   sval();
   if (sv != null) {
     Object ls = sv;
     sv = null;
     while (ls instanceof LazySeq) {
       ls = ((LazySeq) ls).sval();
     }
     s = RT.seq(ls);
   }
   return s;
 }
Example #4
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 #5
0
 public ISeq seq() {
   if (f == null) return null;
   return new Seq(f, RT.seq(r));
 }
Example #6
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;
 }