示例#1
0
  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;
  }
示例#2
0
 final synchronized Object sval() {
   if (fn != null) {
     sv = fn.invoke();
     fn = null;
   }
   if (sv != null) return sv;
   return s;
 }
示例#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;
 }
示例#4
0
 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;
 }
示例#5
0
  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;
  }