本文整理汇总了Java中java.util.OptionalLong类的典型用法代码示例。如果您正苦于以下问题:Java OptionalLong类的具体用法?Java OptionalLong怎么用?Java OptionalLong使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OptionalLong类属于java.util包,在下文中一共展示了OptionalLong类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equals
import java.util.OptionalLong; //导入依赖的package包/类
@Test
public void equals() {
ImmutableJdkOptionals o1 = ImmutableJdkOptionals.of()
.withV2("v2")
.withI1(1)
.withD1(1.0);
ImmutableJdkOptionals o2 = ImmutableJdkOptionals.of(
Optional.of("v2"),
OptionalInt.of(1),
OptionalLong.empty(),
OptionalDouble.of(1.0));
check(o1).is(o2);
check(o1.hashCode()).is(o2.hashCode());
}
示例2: setup
import java.util.OptionalLong; //导入依赖的package包/类
@Override
public <C extends VPackSetupContext<C>> void setup(final C context) {
context.registerDeserializer(Instant.class, VPackJdk8Deserializers.INSTANT);
context.registerDeserializer(LocalDate.class, VPackJdk8Deserializers.LOCAL_DATE);
context.registerDeserializer(LocalDateTime.class, VPackJdk8Deserializers.LOCAL_DATE_TIME);
context.registerDeserializer(ZonedDateTime.class, VPackJdk8Deserializers.ZONED_DATE_TIME);
context.registerDeserializer(OffsetDateTime.class, VPackJdk8Deserializers.OFFSET_DATE_TIME);
context.registerDeserializer(ZoneId.class, VPackJdk8Deserializers.ZONE_ID);
context.registerDeserializer(Optional.class, VPackJdk8Deserializers.OPTIONAL, true);
context.registerDeserializer(OptionalDouble.class, VPackJdk8Deserializers.OPTIONAL_DOUBLE, true);
context.registerDeserializer(OptionalInt.class, VPackJdk8Deserializers.OPTIONAL_INT, true);
context.registerDeserializer(OptionalLong.class, VPackJdk8Deserializers.OPTIONAL_LONG, true);
context.registerSerializer(Instant.class, VPackJdk8Serializers.INSTANT);
context.registerSerializer(LocalDate.class, VPackJdk8Serializers.LOCAL_DATE);
context.registerSerializer(LocalDateTime.class, VPackJdk8Serializers.LOCAL_DATE_TIME);
context.registerSerializer(ZonedDateTime.class, VPackJdk8Serializers.ZONED_DATE_TIME);
context.registerSerializer(OffsetDateTime.class, VPackJdk8Serializers.OFFSET_DATE_TIME);
context.registerSerializer(ZoneId.class, VPackJdk8Serializers.ZONE_ID);
context.registerSerializer(Optional.class, VPackJdk8Serializers.OPTIONAL);
context.registerSerializer(OptionalDouble.class, VPackJdk8Serializers.OPTIONAL_DOUBLE);
context.registerSerializer(OptionalInt.class, VPackJdk8Serializers.OPTIONAL_INT);
context.registerSerializer(OptionalLong.class, VPackJdk8Serializers.OPTIONAL_LONG);
}
示例3: setupTestForMasterElementWithOneChildAndElementSizedBasedTermination
import java.util.OptionalLong; //导入依赖的package包/类
private ByteArrayOutputStream setupTestForMasterElementWithOneChildAndElementSizedBasedTermination()
throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte [] EBML_element_rawbytes = writeElement(EBML_id_bytes, wrapByte(0x84), outputStream);
byte [] EBMLVersion_element_rawbytes = writeElement(EBMLVersion_id_bytes, wrapByte(0x81), outputStream);
byte [] EBMLVersion_data_bytes = new byte [] { (byte) 0x4};
outputStream.write(EBMLVersion_data_bytes);
parserCallback.setCheckExpectedCallbacks(true);
parserCallback.expectCallback(TestEBMLParserCallback.CallbackDescription.builder()
.callbackType(TestEBMLParserCallback.CallbackDescription.CallbackType.START)
.typeInfo(TestEBMLTypeInfoProvider.EBML)
.elementCount(0)
.numBytes(OptionalLong.of(4))
.bytes(EBML_element_rawbytes)
.build());
addExpectedCallbacksForEBMLVersion(EBMLVersion_element_rawbytes, EBMLVersion_data_bytes, 1)
.expectCallback(createExpectedCallbackForEndEBML(0));
return outputStream;
}
示例4: testSerialHeader
import java.util.OptionalLong; //导入依赖的package包/类
@Test(timeout = 10000)
@DirtiesContext
public void testSerialHeader() throws Exception {
UUID id = UUID.randomUUID();
uut.publish(Fact.of("{\"id\":\"" + id
+ "\",\"type\":\"someType\",\"ns\":\"default\",\"aggIds\":[\"" + id + "\"]}",
"{}"));
UUID id2 = UUID.randomUUID();
uut.publish(Fact.of("{\"id\":\"" + id2
+ "\",\"type\":\"someType\",\"meta\":{\"foo\":\"bar\"},\"ns\":\"default\",\"aggIds\":[\""
+ id2 + "\"]}",
"{}"));
OptionalLong serialOf = uut.serialOf(id);
assertTrue(serialOf.isPresent());
Fact f = uut.fetchById(id).get();
Fact fact2 = uut.fetchById(id2).get();
assertEquals(serialOf.getAsLong(), f.serial());
assertTrue(f.before(fact2));
}
示例5: test02
import java.util.OptionalLong; //导入依赖的package包/类
@Test
public void test02() throws Exception {
try (SqlAgent agent = config.agent()) {
agent.required(() -> {
PropertyMapperTestEntity test1 = new PropertyMapperTestEntity(1);
test1.intValue = OptionalInt.empty();
test1.longValue = OptionalLong.empty();
test1.doubleValue = OptionalDouble.empty();
test1.dateValue = null;
test1.datetimeValue = null;
test1.enumValue = null;
test1.bigIntValue = null;
agent.insert(test1);
PropertyMapperTestEntity data = agent.find(PropertyMapperTestEntity.class, 1).orElse(null);
assertThat(data, is(test1));
});
}
}
示例6: setupTestForMasterElementWithOneChildAndUnknownlength
import java.util.OptionalLong; //导入依赖的package包/类
private ByteArrayOutputStream setupTestForMasterElementWithOneChildAndUnknownlength() throws IOException {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte [] EBML_element_rawbytes = writeElement(EBML_id_bytes, UNKNOWN_LENGTH, outputStream);
byte [] EBMLVersion_element_rawbytes = writeElement(EBMLVersion_id_bytes, wrapByte(0x83), outputStream);
byte [] EBMLVersion_data_bytes = new byte[] {0x1, 0x4, 0xD};
outputStream.write(EBMLVersion_data_bytes);
outputStream.write(EBML_ZERO_LENGTH_RAWBYTES);
parserCallback.setCheckExpectedCallbacks(true);
parserCallback.expectCallback(createExpectedCallbackForStartOfEBMLUnknownLength(EBML_element_rawbytes));
addExpectedCallbacksForEBMLVersion(EBMLVersion_element_rawbytes, EBMLVersion_data_bytes, 1)
.expectCallback(createExpectedCallbackForEndEBML(0))
.expectCallback(TestEBMLParserCallback.CallbackDescription.builder()
.callbackType(TestEBMLParserCallback.CallbackDescription.CallbackType.START)
.elementCount(2)
.typeInfo(TestEBMLTypeInfoProvider.EBML)
.numBytes(OptionalLong.of(0))
.bytes(EBML_ZERO_LENGTH_RAWBYTES)
.build())
.expectCallback(createExpectedCallbackForEndEBML(2));
return outputStream;
}
示例7: createBodyReader
import java.util.OptionalLong; //导入依赖的package包/类
@Nullable
private BodyReader createBodyReader(InputStream inputStream, RawHttpHeaders headers, boolean hasBody) {
@Nullable BodyReader bodyReader;
if (hasBody) {
@Nullable Long bodyLength = null;
OptionalLong headerLength = parseContentLength(headers);
if (headerLength.isPresent()) {
bodyLength = headerLength.getAsLong();
}
BodyType bodyType = getBodyType(headers, bodyLength);
bodyReader = new LazyBodyReader(bodyType, inputStream, bodyLength, options.allowNewLineWithoutReturn());
} else {
bodyReader = null;
}
return bodyReader;
}
示例8: use
import java.util.OptionalLong; //导入依赖的package包/类
void use() {
UsingAllOptionals value =
ImmutableUsingAllOptionals.builder()
.v1(1)
.v2(2)
.i1(OptionalInt.of(1))
.d1(1.1)
.l1(OptionalLong.empty())
.jso(javaslang.control.Option.none())
.build();
Objects.equals(value.v1().get(), value.v2().get());
Objects.hash(value.i1(), value.l1(), value.d1());
}
示例9: maybeMaxTickTime
import java.util.OptionalLong; //导入依赖的package包/类
private OptionalLong maybeMaxTickTime() {
return tickQuoteRepository
.getAll()
.values()
.stream()
.map(TickQuote::tick)
.mapToLong(ITick::getTime)
.max();
}
示例10: parseLong
import java.util.OptionalLong; //导入依赖的package包/类
@Nonnull
public static OptionalLong parseLong(@Nonnull String s) {
try {
return OptionalLong.of(Long.parseLong(s));
} catch (NumberFormatException e) {
return OptionalLong.empty();
}
}
示例11: getLongProperty
import java.util.OptionalLong; //导入依赖的package包/类
default OptionalLong getLongProperty(String name) {
Optional<String> optValue = getProperty(name);
if (optValue.isPresent()) {
return OptionalLong.of(Long.parseLong(optValue.get()));
} else {
return OptionalLong.empty();
}
}
示例12: invokeAll
import java.util.OptionalLong; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "OptionalUsedAsFieldOrParameterType"})
private <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, OptionalLong timeoutNanos)
throws InterruptedException {
Objects.requireNonNull(tasks, "'tasks' should not be 'null'.");
CompletableFuture[] futures = new CompletableFuture[tasks.size()];
int index = 0;
for (Callable<T> task : tasks) {
futures[index++] = submit(task);
}
boolean completeWithTimeout = timeoutNanos.isPresent();
try {
if (completeWithTimeout) {
CompletableFuture.allOf(futures)
.get(timeoutNanos.getAsLong(), TimeUnit.NANOSECONDS);
completeWithTimeout = false;
} else {
CompletableFuture.allOf(futures)
.get();
}
} catch (ExecutionException | TimeoutException ignored) {
logger.error("Got exception while waiting for completion of '{}' tasks.", tasks.size(), ignored);
}
if (completeWithTimeout) {
TimeoutException timeoutException = new TimeoutException(
"Got timeout after '" + timeoutNanos.getAsLong() + "' nanos."
);
for (CompletableFuture future : futures) {
future.completeExceptionally(timeoutException);
}
}
return Arrays.stream(futures)
.map(future -> (Future<T>) future)
.collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList));
}
示例13: addJavaHandlers
import java.util.OptionalLong; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public JsonPrinter addJavaHandlers() {
return this
.addObjectClassHandler(Enum.class, e -> e.name())
.addObjectClassHandler(Optional.class, o -> o.orElse(null))
.addObjectClassHandler(OptionalInt.class, i -> i.isPresent() ? i.getAsInt() : null)
.addObjectClassHandler(OptionalDouble.class, i -> i.isPresent() ? i.getAsDouble() : null)
.addObjectClassHandler(OptionalLong.class, i -> i.isPresent() ? i.getAsLong() : null)
.addObjectClassHandler(Class.class, c -> c.getName())
.addObjectClassHandler(Path.class, p -> p.toString().replace('\\', '/'))
.addObjectClassHandler(File.class, f -> f.toString().replace('\\', '/'));
}
示例14: testFindLast_longStream
import java.util.OptionalLong; //导入依赖的package包/类
public void testFindLast_longStream() {
Truth.assertThat(findLast(LongStream.of())).isEqualTo(OptionalLong.empty());
Truth.assertThat(findLast(LongStream.of(1, 2, 3, 4, 5))).isEqualTo(OptionalLong.of(5));
// test with a large, not-subsized Spliterator
List<Long> list =
LongStream.rangeClosed(0, 10000).boxed().collect(Collectors.toCollection(LinkedList::new));
Truth.assertThat(findLast(list.stream().mapToLong(i -> i))).isEqualTo(OptionalLong.of(10000));
// no way to find out the stream is empty without walking its spliterator
Truth.assertThat(findLast(list.stream().mapToLong(i -> i).filter(i -> i < 0)))
.isEqualTo(OptionalLong.empty());
}
示例15: testNumberToOptionalIntConverter
import java.util.OptionalLong; //导入依赖的package包/类
@Test
public void testNumberToOptionalIntConverter(){
converter = new JavaOptionalConverterModule.NumberToOptionalIntConverter();
assertTrue(converter.canHandle(1l, TypeToken.of(OptionalInt.class)));
assertFalse(converter.canHandle(1l, TypeToken.of(OptionalLong.class)));
Object result = converter.convert(1l, TypeToken.of(OptionalInt.class));
assertTrue(result instanceof OptionalInt);
assertEquals(1, ((OptionalInt) result).getAsInt());
}