java.util.function.ToLongFunction Java Examples
The following examples show how to use
java.util.function.ToLongFunction.
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: ReferencePipeline.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public final LongStream mapToLong(ToLongFunction<? super P_OUT> mapper) { Objects.requireNonNull(mapper); return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { @Override Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) { return new Sink.ChainedReference<P_OUT, Long>(sink) { @Override public void accept(P_OUT u) { downstream.accept(mapper.applyAsLong(u)); } }; } }; }
Example #2
Source File: ChunkUtils.java From hadoop-ozone with Apache License 2.0 | 6 votes |
private static void writeData(ChunkBuffer data, String filename, long offset, long len, VolumeIOStats volumeIOStats, ToLongFunction<ChunkBuffer> writer) throws StorageContainerException { validateBufferSize(len, data.remaining()); final long startTime = Time.monotonicNow(); final long bytesWritten; try { bytesWritten = writer.applyAsLong(data); } catch (UncheckedIOException e) { throw wrapInStorageContainerException(e.getCause()); } final long endTime = Time.monotonicNow(); long elapsed = endTime - startTime; volumeIOStats.incWriteTime(elapsed); volumeIOStats.incWriteOpCount(); volumeIOStats.incWriteBytes(bytesWritten); LOG.debug("Written {} bytes at offset {} to {} in {} ms", bytesWritten, offset, filename, elapsed); validateWriteSize(len, bytesWritten); }
Example #3
Source File: ReferencePipeline.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public final LongStream mapToLong(ToLongFunction<? super P_OUT> mapper) { Objects.requireNonNull(mapper); return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { @Override Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) { return new Sink.ChainedReference<P_OUT, Long>(sink) { @Override public void accept(P_OUT u) { downstream.accept(mapper.applyAsLong(u)); } }; } }; }
Example #4
Source File: ReferencePipeline.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
@Override public final LongStream mapToLong(ToLongFunction<? super P_OUT> mapper) { Objects.requireNonNull(mapper); return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { @Override Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) { return new Sink.ChainedReference<P_OUT, Long>(sink) { @Override public void accept(P_OUT u) { downstream.accept(mapper.applyAsLong(u)); } }; } }; }
Example #5
Source File: XDataFrameContent.java From morpheus-core with Apache License 2.0 | 6 votes |
/** * Maps the specified column to longs using the mapper function provided * @param frame the frame reference * @param colKey the column key to apply mapper function to * @param mapper the mapper function to apply * @return the newly created content, with update column */ @SuppressWarnings("unchecked") final XDataFrameContent<R,C> mapToLongs(XDataFrame<R,C> frame, C colKey, ToLongFunction<DataFrameValue<R,C>> mapper) { if (!isColumnStore()) { throw new DataFrameException("Cannot apply columns of a transposed DataFrame"); } else { final int rowCount = rowKeys.size(); final boolean parallel = frame.isParallel(); final int colIndex = colKeys.getIndexForKey(colKey); return new XDataFrameContent<>(rowKeys, colKeys, true, Mapper.apply(data, parallel, (index, array) -> { if (index != colIndex) { return array; } else { final int colOrdinal = colKeys.getOrdinalForKey(colKey); final Array<?> targetValues = Array.of(Long.class, array.length()); final Cursor cursor = new Cursor(frame, rowKeys.isEmpty() ? -1 : 0, colOrdinal); for (int i = 0; i < rowCount; ++i) { cursor.atRowOrdinal(i); final long value = mapper.applyAsLong(cursor); targetValues.setLong(cursor.rowIndex, value); } return targetValues; } })); } }
Example #6
Source File: ReferencePipeline.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public final LongStream mapToLong(ToLongFunction<? super P_OUT> mapper) { Objects.requireNonNull(mapper); return new LongPipeline.StatelessOp<P_OUT>(this, StreamShape.REFERENCE, StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) { @Override Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) { return new Sink.ChainedReference<P_OUT, Long>(sink) { @Override public void accept(P_OUT u) { downstream.accept(mapper.applyAsLong(u)); } }; } }; }
Example #7
Source File: LeaderState.java From incubator-ratis with Apache License 2.0 | 6 votes |
private long[] getSorted(List<RaftPeerId> followerIDs, boolean includeSelf, ToLongFunction<FollowerInfo> getFollowerIndex, LongSupplier getLogIndex) { final int length = includeSelf ? followerIDs.size() + 1 : followerIDs.size(); if (length == 0) { throw new IllegalArgumentException("followers.size() == " + followerIDs.size() + " and includeSelf == " + includeSelf); } final long[] indices = new long[length]; List<FollowerInfo> followerInfos = getFollowerInfos(followerIDs); for (int i = 0; i < followerInfos.size(); i++) { indices[i] = getFollowerIndex.applyAsLong(followerInfos.get(i)); } if (includeSelf) { // note that we also need to wait for the local disk I/O indices[length - 1] = getLogIndex.getAsLong(); } Arrays.sort(indices); return indices; }
Example #8
Source File: ArrayBase.java From morpheus-core with Apache License 2.0 | 5 votes |
@Override public final Array<T> applyLongs(ToLongFunction<ArrayValue<T>> function) { final int length = length(); if (length > 0) { final ApplyValues action = new ApplyValues(0, length - 1, function); if (isParallel()) { ForkJoinPool.commonPool().invoke(action); } else { action.compute(); } } return this; }
Example #9
Source File: StepFunctionTimer.java From micrometer with Apache License 2.0 | 5 votes |
public StepFunctionTimer(Id id, Clock clock, long stepMillis, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit, TimeUnit baseTimeUnit) { this.id = id; this.clock = clock; this.ref = new WeakReference<>(obj); this.countFunction = countFunction; this.totalTimeFunction = totalTimeFunction; this.totalTimeFunctionUnit = totalTimeFunctionUnit; this.baseTimeUnit = baseTimeUnit; this.countTotal = new StepTuple2<>(clock, stepMillis, 0L, 0.0, count::sumThenReset, total::sumThenReset); }
Example #10
Source File: JmxReporterService.java From galeb with Apache License 2.0 | 5 votes |
private long extractDelta(final AtomicLong last, final ToLongFunction<Undertow.ListenerInfo> longFunction) { long start = System.nanoTime(); double localLast = last.get() * 1.0; double current = undertow.getListenerInfo().stream().mapToLong(longFunction).sum() * 1.0; long end = System.nanoTime(); last.set((long) current); return Math.round((current * ((double) end / (double) start)) - localLast); }
Example #11
Source File: FunctionTimer.java From micrometer with Apache License 2.0 | 5 votes |
private Builder(String name, @Nullable T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { this.name = name; this.obj = obj; this.countFunction = countFunction; this.totalTimeFunction = totalTimeFunction; this.totalTimeFunctionUnit = totalTimeFunctionUnit; }
Example #12
Source File: DefaultCardinalityEstimator.java From rheem with Apache License 2.0 | 5 votes |
public DefaultCardinalityEstimator(double certaintyProb, int numInputs, boolean isAllowMoreInputs, ToLongFunction<long[]> singlePointEstimator) { this(certaintyProb, numInputs, isAllowMoreInputs, (inputCards, rheemContext) -> singlePointEstimator.applyAsLong(inputCards)); }
Example #13
Source File: XDataFrame.java From morpheus-core with Apache License 2.0 | 5 votes |
@Override public DataFrame<R, C> mapToLongs(ToLongFunction<DataFrameValue<R, C>> mapper) { final Array<R> rowKeys = rows().keyArray(); final Array<C> colKeys = cols().keyArray(); final XDataFrame<R,C> result = (XDataFrame<R,C>)DataFrame.ofLongs(rowKeys, colKeys); this.forEachValue(v -> { final long value = mapper.applyAsLong(v); final int rowOrdinal = v.rowOrdinal(); final int colOrdinal = v.colOrdinal(); result.content().setLong(rowOrdinal, colOrdinal, value); }); return result; }
Example #14
Source File: XDataFrameVector.java From morpheus-core with Apache License 2.0 | 5 votes |
@Override() public final Z applyLongs(ToLongFunction<DataFrameValue<R,C>> mapper) { return forEachValue(value -> { final long result = mapper.applyAsLong(value); value.setLong(result); }); }
Example #15
Source File: SimpleMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { switch (config.mode()) { case CUMULATIVE: return new CumulativeFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnit, getBaseTimeUnit()); case STEP: default: return new StepFunctionTimer<>(id, clock, config.step().toMillis(), obj, countFunction, totalTimeFunction, totalTimeFunctionUnit, getBaseTimeUnit()); } }
Example #16
Source File: BasicTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public void testLongComparator() { Thing[] things = new Thing[longValues.length]; for (int i=0; i<longValues.length; i++) things[i] = new Thing(0, longValues[i], 0.0, null); Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() { @Override public long applyAsLong(Thing thing) { return thing.getLongField(); } }); assertComparisons(things, comp, comparisons); }
Example #17
Source File: CumulativeFunctionTimer.java From micrometer with Apache License 2.0 | 5 votes |
public CumulativeFunctionTimer(Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit, TimeUnit baseTimeUnit) { this.id = id; this.ref = new WeakReference<>(obj); this.countFunction = countFunction; this.totalTimeFunction = totalTimeFunction; this.totalTimeFunctionUnit = totalTimeFunctionUnit; this.baseTimeUnit = baseTimeUnit; }
Example #18
Source File: DropwizardMeterRegistry.java From micrometer with Apache License 2.0 | 5 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { DropwizardFunctionTimer<T> ft = new DropwizardFunctionTimer<>(id, clock, obj, countFunction, totalTimeFunction, totalTimeFunctionUnit, getBaseTimeUnit()); registry.register(hierarchicalName(id), ft.getDropwizardMeter()); return ft; }
Example #19
Source File: BasicTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void testLongComparator() { Thing[] things = new Thing[longValues.length]; for (int i=0; i<longValues.length; i++) things[i] = new Thing(0, longValues[i], 0.0, null); Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() { @Override public long applyAsLong(Thing thing) { return thing.getLongField(); } }); assertComparisons(things, comp, comparisons); }
Example #20
Source File: BasicTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void testLongComparator() { Thing[] things = new Thing[longValues.length]; for (int i=0; i<longValues.length; i++) things[i] = new Thing(0, longValues[i], 0.0, null); Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() { @Override public long applyAsLong(Thing thing) { return thing.getLongField(); } }); assertComparisons(things, comp, comparisons); }
Example #21
Source File: BasicTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public void testLongComparator() { Thing[] things = new Thing[longValues.length]; for (int i=0; i<longValues.length; i++) things[i] = new Thing(0, longValues[i], 0.0, null); Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() { @Override public long applyAsLong(Thing thing) { return thing.getLongField(); } }); assertComparisons(things, comp, comparisons); }
Example #22
Source File: ArrayBase.java From morpheus-core with Apache License 2.0 | 5 votes |
@Override public final Array<Long> mapToLongs(ToLongFunction<ArrayValue<T>> mapper) { final Array<Long> result = Array.of(Long.class, length()); final MapValues<Long> action = new MapValues<>(0, length() - 1, mapper, result); if (isParallel()) { ForkJoinPool.commonPool().invoke(action); return result; } else { action.compute(); return result; } }
Example #23
Source File: AbstractQueryEngine.java From NNAnalytics with Apache License 2.0 | 5 votes |
private Map<String, Long> genericAvgingHistogram( Stream<INode> inodes, Function<INode, String> namingFunction, ToLongFunction<INode> dataFunction) { Map<String, Double> collect = inodes.collect( Collectors.groupingBy( namingFunction, Collectors.averagingDouble(n -> (double) dataFunction.applyAsLong(n)))); HashMap<String, Long> histogram = new HashMap<>(collect.size()); for (Entry<String, Double> entry : collect.entrySet()) { histogram.put(entry.getKey(), entry.getValue().longValue()); } return histogram; }
Example #24
Source File: BasicTest.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void testLongComparator() { Thing[] things = new Thing[longValues.length]; for (int i=0; i<longValues.length; i++) things[i] = new Thing(0, longValues[i], 0.0, null); Comparator<Thing> comp = Comparator.comparingLong(new ToLongFunction<Thing>() { @Override public long applyAsLong(Thing thing) { return thing.getLongField(); } }); assertComparisons(things, comp, comparisons); }
Example #25
Source File: Helper.java From NNAnalytics with Apache License 2.0 | 4 votes |
public static <T> ToLongFunction<T> convertToLongFunction(Function<T, Long> function) { return function::apply; }
Example #26
Source File: StreamDataOutput.java From presto with Apache License 2.0 | 4 votes |
public StreamDataOutput(ToLongFunction<SliceOutput> writer, Stream stream) { this.writer = requireNonNull(writer, "writer is null"); this.stream = requireNonNull(stream, "stream is null"); }
Example #27
Source File: WavefrontMeterRegistry.java From micrometer with Apache License 2.0 | 4 votes |
@Override protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { return new CumulativeFunctionTimer<>(id, obj, countFunction, totalTimeFunction, totalTimeFunctionUnit, getBaseTimeUnit()); }
Example #28
Source File: BrokerAttributeInjector.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private static long getLongValue(Broker broker, ToLongFunction<Broker> supplier) { return supplier.applyAsLong(broker); }
Example #29
Source File: Simulation.java From chvote-protocol-poc with GNU Affero General Public License v3.0 | 4 votes |
private LongSummaryStatistics computeStats(List<DefaultVotingClient> votingClients, ToLongFunction<DefaultVotingClient.Stats> getVoteEncodingTime) { return votingClients.stream().map(DefaultVotingClient::getStats).mapToLong(getVoteEncodingTime).summaryStatistics(); }
Example #30
Source File: FunctionTimer.java From micrometer with Apache License 2.0 | 4 votes |
static <T> Builder<T> builder(String name, T obj, ToLongFunction<T> countFunction, ToDoubleFunction<T> totalTimeFunction, TimeUnit totalTimeFunctionUnit) { return new Builder<>(name, obj, countFunction, totalTimeFunction, totalTimeFunctionUnit); }