本文整理汇总了Java中java.util.function.LongSupplier类的典型用法代码示例。如果您正苦于以下问题:Java LongSupplier类的具体用法?Java LongSupplier怎么用?Java LongSupplier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LongSupplier类属于java.util.function包,在下文中一共展示了LongSupplier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseLong
import java.util.function.LongSupplier; //导入依赖的package包/类
@Override
public long parseLong(String value, boolean roundUp, LongSupplier now) {
Number n;
try {
n = format.parse(value);
} catch (ParseException e) {
throw new RuntimeException(e);
}
if (format.isParseIntegerOnly()) {
return n.longValue();
} else {
double d = n.doubleValue();
if (roundUp) {
d = Math.ceil(d);
} else {
d = Math.floor(d);
}
return Math.round(d);
}
}
示例2: TranslogWriter
import java.util.function.LongSupplier; //导入依赖的package包/类
private TranslogWriter(
final ChannelFactory channelFactory,
final ShardId shardId,
final Checkpoint initialCheckpoint,
final FileChannel channel,
final Path path,
final ByteSizeValue bufferSize,
final LongSupplier globalCheckpointSupplier) throws IOException {
super(initialCheckpoint.generation, channel, path, channel.position());
this.shardId = shardId;
this.channelFactory = channelFactory;
this.outputStream = new BufferedChannelOutputStream(java.nio.channels.Channels.newOutputStream(channel), bufferSize.bytesAsInt());
this.lastSyncedCheckpoint = initialCheckpoint;
this.totalOffset = initialCheckpoint.offset;
assert initialCheckpoint.minSeqNo == SequenceNumbersService.NO_OPS_PERFORMED : initialCheckpoint.minSeqNo;
this.minSeqNo = initialCheckpoint.minSeqNo;
assert initialCheckpoint.maxSeqNo == SequenceNumbersService.NO_OPS_PERFORMED : initialCheckpoint.maxSeqNo;
this.maxSeqNo = initialCheckpoint.maxSeqNo;
this.globalCheckpointSupplier = globalCheckpointSupplier;
}
示例3: parse
import java.util.function.LongSupplier; //导入依赖的package包/类
public long parse(String text, LongSupplier now, boolean roundUp, DateTimeZone timeZone) {
long time;
String mathString;
if (text.startsWith("now")) {
try {
time = now.getAsLong();
} catch (Exception e) {
throw new ElasticsearchParseException("could not read the current timestamp", e);
}
mathString = text.substring("now".length());
} else {
int index = text.indexOf("||");
if (index == -1) {
return parseDateTime(text, timeZone, roundUp);
}
time = parseDateTime(text.substring(0, index), timeZone, false);
mathString = text.substring(index + 2);
}
return parseMath(mathString, time, roundUp, timeZone);
}
示例4: TransportBulkAction
import java.util.function.LongSupplier; //导入依赖的package包/类
public TransportBulkAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ClusterService clusterService, IngestService ingestService,
TransportShardBulkAction shardBulkAction, TransportCreateIndexAction createIndexAction,
ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver,
AutoCreateIndex autoCreateIndex, LongSupplier relativeTimeProvider) {
super(settings, BulkAction.NAME, threadPool, transportService, actionFilters, indexNameExpressionResolver, BulkRequest::new);
Objects.requireNonNull(relativeTimeProvider);
this.clusterService = clusterService;
this.ingestService = ingestService;
this.shardBulkAction = shardBulkAction;
this.createIndexAction = createIndexAction;
this.autoCreateIndex = autoCreateIndex;
this.relativeTimeProvider = relativeTimeProvider;
this.ingestForwarder = new IngestActionForwarder(transportService);
clusterService.addStateApplier(this.ingestForwarder);
}
示例5: TestTransportBulkAction
import java.util.function.LongSupplier; //导入依赖的package包/类
TestTransportBulkAction(
Settings settings,
ThreadPool threadPool,
TransportService transportService,
ClusterService clusterService,
TransportShardBulkAction shardBulkAction,
TransportCreateIndexAction createIndexAction,
ActionFilters actionFilters,
IndexNameExpressionResolver indexNameExpressionResolver,
AutoCreateIndex autoCreateIndex,
LongSupplier relativeTimeProvider) {
super(
settings,
threadPool,
transportService,
clusterService,
null,
shardBulkAction,
createIndexAction,
actionFilters,
indexNameExpressionResolver,
autoCreateIndex,
relativeTimeProvider);
}
示例6: of
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
* Create a new {@code Random64} instance, where the random numbers are
* generated by the given long {@code supplier}.
*
* @param supplier the random number supplier
* @return a new {@code Random64} instance
* @throws java.lang.NullPointerException if the given {@code supplier} is
* {@code null}.
*/
public static Random64 of(final LongSupplier supplier) {
Objects.requireNonNull(supplier);
return new Random64() {
private static final long serialVersionUID = 1L;
private final Boolean _sentry = Boolean.TRUE;
@Override
public long nextLong() {
return supplier.getAsLong();
}
@Override
public void setSeed(final long seed) {
if (_sentry != null) {
throw new UnsupportedOperationException(
"The 'setSeed(long)' method is not supported."
);
}
}
};
}
示例7: shouldRequireNonNullCache
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<String, Long> cache = null;
final Supplier<String> keySupplier = () -> "key";
final LongSupplier supplier = () -> 123L;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedLongSupplierMemoizer<>(cache, keySupplier, supplier);
}
示例8: shouldRequireNonNullKeySupplier
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullKeySupplier() {
// given
final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
final Supplier<String> keySupplier = null;
final LongSupplier supplier = () -> 123L;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide a key function, might just be 'MemoizationDefaults.defaultKeySupplier()'.");
// then
new ConcurrentMapBasedLongSupplierMemoizer<>(cache, keySupplier, supplier);
}
示例9: shouldRequireNonNullValueSupplier
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullValueSupplier() {
// given
final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
final Supplier<String> keySupplier = () -> "key";
final LongSupplier supplier = null;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Cannot memoize a NULL Supplier - provide an actual Supplier to fix this.");
// then
new ConcurrentMapBasedLongSupplierMemoizer<>(cache, keySupplier, supplier);
}
示例10: shouldUseSuppliedKey
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldUseSuppliedKey() {
// given
final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
final Supplier<String> keySupplier = () -> "key";
final LongSupplier supplier = () -> 123L;
// when
final ConcurrentMapBasedLongSupplierMemoizer<String> memoizer = new ConcurrentMapBasedLongSupplierMemoizer<>(
cache, keySupplier, supplier);
// then
Assert.assertTrue("Cache is not empty before memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoized value does not match expectations", 123L, memoizer.getAsLong());
Assert.assertFalse("Cache is still empty after memoization", memoizer.viewCacheForTest().isEmpty());
Assert.assertEquals("Memoization key does not match expectations", "key",
memoizer.viewCacheForTest().keySet().iterator().next());
}
示例11: shouldTriggerOnce
import java.util.function.LongSupplier; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.BOXING)
public void shouldTriggerOnce() {
// given
final ConcurrentMap<String, Long> cache = new ConcurrentHashMap<>();
final Supplier<String> keySupplier = () -> "key";
final LongSupplier supplier = mock(LongSupplier.class);
given(supplier.getAsLong()).willReturn(123L);
// when
final ConcurrentMapBasedLongSupplierMemoizer<String> memoizer = new ConcurrentMapBasedLongSupplierMemoizer<>(
cache, keySupplier, supplier);
// then
Assert.assertEquals("Memoized value does not match expectations", 123L, memoizer.getAsLong()); // triggers
Assert.assertEquals("Memoized value does not match expectations", 123L, memoizer.getAsLong()); // memoized
Assert.assertEquals("Memoized value does not match expectations", 123L, memoizer.getAsLong()); // memoized
Assert.assertEquals("Memoized value does not match expectations", 123L, memoizer.getAsLong()); // memoized
verify(supplier, times(1)).getAsLong(); // real supplier triggered once, all other calls were memoized
}
示例12: shouldReplyToOnNotLeaderWith
import java.util.function.LongSupplier; //导入依赖的package包/类
private void shouldReplyToOnNotLeaderWith(
final IntSupplier libraryId,
final LongSupplier connectCorrelationId,
final String... channels)
{
whenPolled()
.then(
(inv) ->
{
library.onNotLeader(libraryId.getAsInt(), connectCorrelationId.getAsLong(), LEADER_CHANNEL);
return 1;
})
.then(replyWithApplicationHeartbeat())
.then(noReply());
newLibraryPoller(CLUSTER_CHANNELS);
library.startConnecting();
pollTwice();
poll();
attemptToConnectTo(channels);
verify(connectHandler).onConnect(fixLibrary);
}
示例13: from
import java.util.function.LongSupplier; //导入依赖的package包/类
/** Creates a `Box.Long` from a `LongSupplier` and a `LongConsumer`. */
public static Lng from(LongSupplier getter, LongConsumer setter) {
return new Lng() {
@Override
public long getAsLong() {
return getter.getAsLong();
}
@Override
public void set(long value) {
setter.accept(value);
}
@Override
public String toString() {
return "Box.Long.from[" + get() + "]";
}
};
}
示例14: createCustomMetric
import java.util.function.LongSupplier; //导入依赖的package包/类
@Override
public synchronized void createCustomMetric(String name, String description, String kind, LongSupplier value) {
LongSupplier supplier = requireNonNull(value);
Metric cm = context.getMetrics().createCustomMetric(
requireNonNull(name),
requireNonNull(description),
Metric.Kind.valueOf(kind.toUpperCase(Locale.US)));
cm.setValue(supplier.getAsLong());
if (metrics == null) {
metrics = new ArrayList<>();
metricsGetter = getScheduledExecutorService().scheduleWithFixedDelay(this::updateMetrics,
1, 1, TimeUnit.SECONDS);
}
metrics.add(() -> cm.setValue(supplier.getAsLong()));
}
示例15: awaitOnLatch
import java.util.function.LongSupplier; //导入依赖的package包/类
private void awaitOnLatch(CountDownLatch countDownLatch, LongSupplier nanosRemaining) throws TimeoutException {
boolean interrupted = Thread.interrupted();
try {
while (true) {
try {
if (countDownLatch.await(nanosRemaining.getAsLong(), TimeUnit.NANOSECONDS)) {
if (!entity.isConnected()) {
throw new IllegalStateException("Cluster tier manager disconnected");
} else {
return;
}
} else {
throw new TimeoutException();
}
} catch (InterruptedException e) {
interrupted = true;
}
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}