Java Code Examples for java.util.function.LongConsumer#accept()

The following examples show how to use java.util.function.LongConsumer#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Streams.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: LongPipeline.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@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);
                }
            };
        }
    };
}
 
Example 3
Source File: Spliterators.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
Example 4
Source File: Spliterators.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: StreamSpliterators.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean tryAdvance(LongConsumer action) {
    Objects.requireNonNull(action);

    action.accept(s.getAsLong());
    return true;
}
 
Example 6
Source File: Spliterators.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example 7
Source File: Spliterators.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: SplittableRandom.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: Random.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 10
Source File: ThreadLocalRandom.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
Source File: Spliterators.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
Example 12
Source File: Spliterators.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
@Override
public boolean tryAdvance(LongConsumer action) {
    if (action == null) throw new NullPointerException();
    if (it.hasNext()) {
        action.accept(it.nextLong());
        return true;
    }
    return false;
}
 
Example 13
Source File: SplittableRandom.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 14
Source File: MockStorePartition.java    From waltz with Apache License 2.0 4 votes vote down vote up
@Override
public void append(ReqId reqId, int header, byte[] data, int checksum, LongConsumer onCompletion) {
    onCompletion.accept(put(reqId, header, data, checksum));
}
 
Example 15
Source File: StreamSpliterators.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void forEach(LongConsumer action, long fence) {
    for (int i = 0; i < fence; i++) {
        action.accept(array[i]);
    }
}
 
Example 16
Source File: StreamSpliterators.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
@Override
public void forEach(LongConsumer action, long fence) {
    for (int i = 0; i < fence; i++) {
        action.accept(array[i]);
    }
}
 
Example 17
Source File: VideoQuotaEnforcerDeleteOldest.java    From arcusplatform with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 18
Source File: StreamSpliterators.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
@Override
protected void acceptConsumed(LongConsumer action) {
    action.accept(tmpValue);
}
 
Example 19
Source File: OptionalLong.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: PrimitiveIterator.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * 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());
}