java.util.function.LongConsumer#accept ( )源码实例Demo

下面列出了java.util.function.LongConsumer#accept ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk1.8-source-analysis   文件: Streams.java
@Override
public boolean tryAdvance(LongConsumer consumer) {
    Objects.requireNonNull(consumer);

    final long i = from;
    if (i < upTo) {
        from++;
        consumer.accept(i);
        return true;
    }
    else if (last > 0) {
        last = 0;
        consumer.accept(i);
        return true;
    }
    return false;
}
 
源代码2 项目: jdk1.8-source-analysis   文件: LongPipeline.java
@Override
public final LongStream peek(LongConsumer action) {
    Objects.requireNonNull(action);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 0) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    action.accept(t);
                    downstream.accept(t);
                }
            };
        }
    };
}
 
源代码3 项目: TencentKona-8   文件: StreamSpliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    Objects.requireNonNull(action);

    action.accept(s.getAsLong());
    return true;
}
 
源代码4 项目: dragonwell8_jdk   文件: Spliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
源代码5 项目: jdk1.8-source-analysis   文件: Spliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null)
        throw new NullPointerException();
    if (index >= 0 && index < fence) {
        action.accept(array[index++]);
        return true;
    }
    return false;
}
 
源代码6 项目: TencentKona-8   文件: Spliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null)
        throw new NullPointerException();
    if (index >= 0 && index < fence) {
        action.accept(array[index++]);
        return true;
    }
    return false;
}
 
源代码7 项目: jdk1.8-source-analysis   文件: Spliterators.java
@Override
public void forEachRemaining(LongConsumer action) {
    long[] a; int i, hi; // hoist accesses and checks from loop
    if (action == null)
        throw new NullPointerException();
    if ((a = array).length >= (hi = fence) &&
        (i = index) >= 0 && i < (index = hi)) {
        do { action.accept(a[i]); } while (++i < hi);
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: Random.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码9 项目: TencentKona-8   文件: SplittableRandom.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
源代码10 项目: jdk1.8-source-analysis   文件: Spliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
源代码11 项目: TencentKona-8   文件: Spliterators.java
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
源代码12 项目: jdk1.8-source-analysis   文件: ThreadLocalRandom.java
public void forEachRemaining(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        index = f;
        long o = origin, b = bound;
        ThreadLocalRandom rng = ThreadLocalRandom.current();
        do {
            consumer.accept(rng.internalNextLong(o, b));
        } while (++i < f);
    }
}
 
源代码13 项目: jdk1.8-source-analysis   文件: SplittableRandom.java
public boolean tryAdvance(LongConsumer consumer) {
    if (consumer == null) throw new NullPointerException();
    long i = index, f = fence;
    if (i < f) {
        consumer.accept(rng.internalNextLong(origin, bound));
        index = i + 1;
        return true;
    }
    return false;
}
 
@Override
protected void acceptConsumed(LongConsumer action) {
    action.accept(tmpValue);
}
 
@Nullable
@Override
protected Iterable<VideoRecordingSize> getRecordingsToDelete(Place place, long used, long allowed, LongConsumer quotaUpdater) throws Exception {
   long newUsed = used;

   List<VideoRecordingSize> delete = new ArrayList<>();
   Iterator<VideoRecordingSize> it = videoDao.streamRecordingIdsForPlace(place.getId(), false).iterator();

   // We keep deleting non-favorited recordings until:
   //  1) we run out of videos
   //  2) we are below the quota
   //  3) we are at the maximum number of deletes allowed per new recording
   while(
         it.hasNext() && 
         delete.size() < maxDeletesAllowed && 
         newUsed > allowed
   ) {
      VideoRecordingSize recording = it.next();

      if (delete.size() == maxDeletesAllowed || newUsed < allowed) {
         break;
      }

      // Add this recording to the set of recordings to delete and adjust the
      // currently used space to reflect its deletion.
      delete.add(recording);
      newUsed -= recording.getSize();
   }

   // If we reach the maximum deletes then we will allow the new recording regardless
   // of whether there is quota space available or not.
   if (delete.size() == maxDeletesAllowed || newUsed < allowed) {
      QUOTA_ENFORCEMENT_DELETES.update(delete.size());
      quotaUpdater.accept(used-newUsed);
      return delete;
   }

   // If we went through all of the recordings and could not find enough to delete
   // then we deny the new recording without deleting anything.
   log.info("video quota enforcer denying new recording because not enough space could be freed: deletable={}, used={}, allowed={}, updated used={}", delete, used, allowed, newUsed);
   return null;
}
 
@Override
public void forEach(LongConsumer action, long fence) {
    for (int i = 0; i < fence; i++) {
        action.accept(array[i]);
    }
}
 
源代码17 项目: dragonwell8_jdk   文件: StreamSpliterators.java
@Override
public void forEach(LongConsumer action, long fence) {
    for (int i = 0; i < fence; i++) {
        action.accept(array[i]);
    }
}
 
源代码18 项目: waltz   文件: MockStorePartition.java
@Override
public void append(ReqId reqId, int header, byte[] data, int checksum, LongConsumer onCompletion) {
    onCompletion.accept(put(reqId, header, data, checksum));
}
 
源代码19 项目: dragonwell8_jdk   文件: PrimitiveIterator.java
/**
 * Performs the given action for each remaining element until all elements
 * have been processed or the action throws an exception.  Actions are
 * performed in the order of iteration, if that order is specified.
 * Exceptions thrown by the action are relayed to the caller.
 *
 * @implSpec
 * <p>The default implementation behaves as if:
 * <pre>{@code
 *     while (hasNext())
 *         action.accept(nextLong());
 * }</pre>
 *
 * @param action The action to be performed for each element
 * @throws NullPointerException if the specified action is null
 */
default void forEachRemaining(LongConsumer action) {
    Objects.requireNonNull(action);
    while (hasNext())
        action.accept(nextLong());
}
 
源代码20 项目: dragonwell8_jdk   文件: OptionalLong.java
/**
 * Have the specified consumer accept the value if a value is present,
 * otherwise do nothing.
 *
 * @param consumer block to be executed if a value is present
 * @throws NullPointerException if value is present and {@code consumer} is
 * null
 */
public void ifPresent(LongConsumer consumer) {
    if (isPresent)
        consumer.accept(value);
}
 
 同类方法