下面列出了java.util.function.LongConsumer#accept ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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;
}
@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);
}
};
}
};
}
@Override
public boolean tryAdvance(LongConsumer action) {
Objects.requireNonNull(action);
action.accept(s.getAsLong());
return true;
}
@Override
public boolean tryAdvance(LongConsumer action) {
if (action == null) throw new NullPointerException();
if (it.hasNext()) {
action.accept(it.nextLong());
return true;
}
return false;
}
@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;
}
@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;
}
@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);
}
}
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;
}
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
public boolean tryAdvance(LongConsumer action) {
if (action == null) throw new NullPointerException();
if (it.hasNext()) {
action.accept(it.nextLong());
return true;
}
return false;
}
@Override
public boolean tryAdvance(LongConsumer action) {
if (action == null) throw new NullPointerException();
if (it.hasNext()) {
action.accept(it.nextLong());
return true;
}
return false;
}
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);
}
}
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]);
}
}
@Override
public void forEach(LongConsumer action, long fence) {
for (int i = 0; i < fence; i++) {
action.accept(array[i]);
}
}
@Override
public void append(ReqId reqId, int header, byte[] data, int checksum, LongConsumer onCompletion) {
onCompletion.accept(put(reqId, header, data, checksum));
}
/**
* 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());
}
/**
* 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);
}