private boolean step() {
    if (next != NONE) return true;

    while (next == NONE) {
      if (buffer.isEmpty()) {
        if (completed) {
          return false;
        } else if (sourceIter.hasNext()) {
          Object iter = null;
          if (multi) iter = xf.applyTo(RT.cons(null, sourceIter.next()));
          else iter = xf.invoke(null, sourceIter.next());

          if (RT.isReduced(iter)) {
            xf.invoke(null);
            completed = true;
          }
        } else {
          xf.invoke(null);
          completed = true;
        }
      } else {
        next = buffer.remove();
      }
    }
    return true;
  }
Exemple #2
0
 final synchronized Object sval() {
   if (fn != null) {
     sv = fn.invoke();
     fn = null;
   }
   if (sv != null) return sv;
   return s;
 }
Exemple #3
0
 final synchronized Object sval() {
   if (fn != null) {
     try {
       sv = fn.invoke();
       fn = null;
     } catch (RuntimeException e) {
       throw e;
     } catch (Exception e) {
       throw Util.runtimeException(e);
     }
   }
   if (sv != null) return sv;
   return s;
 }
 Object doCommute(Ref ref, IFn fn, ISeq args) {
   if (!info.running()) throw retryex;
   if (!vals.containsKey(ref)) {
     Object val = null;
     try {
       ref.lock.readLock().lock();
       val = ref.tvals == null ? null : ref.tvals.val;
     } finally {
       ref.lock.readLock().unlock();
     }
     vals.put(ref, val);
   }
   ArrayList<CFn> fns = commutes.get(ref);
   if (fns == null) commutes.put(ref, fns = new ArrayList<CFn>());
   fns.add(new CFn(fn, args));
   Object ret = fn.applyTo(RT.cons(vals.get(ref), args));
   vals.put(ref, ret);
   return ret;
 }
  private TransformerIterator(IFn xform, Iterator sourceIter, boolean multi) {
    this.sourceIter = sourceIter;
    this.xf =
        (IFn)
            xform.invoke(
                new AFn() {
                  public Object invoke() {
                    return null;
                  }

                  public Object invoke(Object acc) {
                    return acc;
                  }

                  public Object invoke(Object acc, Object o) {
                    buffer = buffer.add(o);
                    return acc;
                  }
                });
    this.multi = multi;
  }