本文整理匯總了Java中java.util.OptionalInt類的典型用法代碼示例。如果您正苦於以下問題:Java OptionalInt類的具體用法?Java OptionalInt怎麽用?Java OptionalInt使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
OptionalInt類屬於java.util包,在下文中一共展示了OptionalInt類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serializeOptionalPrimitive
import java.util.OptionalInt; //導入依賴的package包/類
@Test
public void serializeOptionalPrimitive() {
final OptionalPrimitiveTestEntity entity = new OptionalPrimitiveTestEntity();
entity.d = OptionalDouble.of(69.5);
entity.i = OptionalInt.of(69);
entity.l = OptionalLong.of(69L);
final VPackSlice vpack = vp.serialize(entity);
assertThat(vpack, is(notNullValue()));
assertThat(vpack.isObject(), is(true));
assertThat(vpack.get("d").isDouble(), is(true));
assertThat(vpack.get("d").getAsDouble(), is(69.5));
assertThat(vpack.get("i").isInteger(), is(true));
assertThat(vpack.get("i").getAsInt(), is(69));
assertThat(vpack.get("l").isInteger(), is(true));
assertThat(vpack.get("l").getAsLong(), is(69L));
}
示例2: StreamingMkvReader
import java.util.OptionalInt; //導入依賴的package包/類
StreamingMkvReader(boolean requirePath,
Collection<EBMLTypeInfo> typeInfosToRead,
ParserByteSource byteSource,
OptionalInt maxContentBytesAtOnce) {
this.requirePath = requirePath;
typeInfosToRead.stream().forEach(t -> Validate.isTrue(t.getType() != EBMLTypeInfo.TYPE.MASTER));
this.typeInfosToRead = new HashSet(typeInfosToRead);
this.byteSource = byteSource;
this.mkvStreamReaderCallback = new MkvStreamReaderCallback(this.requirePath, elementFilter());
this.previousDataElement = Optional.empty();
MkvTypeInfoProvider typeInfoProvider = new MkvTypeInfoProvider();
try {
typeInfoProvider.load();
} catch (IllegalAccessException e) {
//TODO: fix this
throw new RuntimeException("Could not load mkv info", e);
}
if (maxContentBytesAtOnce.isPresent()) {
this.parser = new EBMLParser(typeInfoProvider, mkvStreamReaderCallback, maxContentBytesAtOnce.getAsInt());
} else {
this.parser = new EBMLParser(typeInfoProvider, mkvStreamReaderCallback);
}
}
示例3: frameStart
import java.util.OptionalInt; //導入依賴的package包/類
@Test
public void frameStart() {
final long[] payloads = {0, 126, 65536, Integer.MAX_VALUE + 1L};
final OptionalInt[] masks = {empty(), of(-1), of(0), of(0xCAFEBABE),
of(Integer.MAX_VALUE), of(Integer.MIN_VALUE)};
for (boolean fin : new boolean[]{true, false}) {
for (boolean rsv1 : new boolean[]{true, false}) {
for (boolean rsv2 : new boolean[]{true, false}) {
for (boolean rsv3 : new boolean[]{true, false}) {
for (Opcode opcode : Opcode.values()) {
for (long payloadLen : payloads) {
for (OptionalInt mask : masks) {
verifyFrameStart(fin, rsv1, rsv2, rsv3, opcode, payloadLen, mask);
}
}
}
}
}
}
}
System.out.println("Frames: " + frames + ", Total cases: " + cases);
}
示例4: verify
import java.util.OptionalInt; //導入依賴的package包/類
private void verify(boolean fin,
boolean rsv1,
boolean rsv2,
boolean rsv3,
Opcode opcode,
long payloadLen,
OptionalInt mask) {
frames++;
HeaderWriter writer = new HeaderWriter();
ByteBuffer expected = ByteBuffer.allocate(Frame.MAX_HEADER_SIZE_BYTES);
writer.fin(fin).rsv1(rsv1).rsv2(rsv2).rsv3(rsv3).opcode(opcode).payloadLen(payloadLen);
mask.ifPresentOrElse(writer::mask, writer::noMask);
writer.write(expected);
expected.flip();
verifyPermutations(expected, writer,
() -> writer.fin(fin),
() -> writer.rsv1(rsv1),
() -> writer.rsv2(rsv2),
() -> writer.rsv3(rsv3),
() -> writer.opcode(opcode),
() -> writer.payloadLen(payloadLen),
() -> mask.ifPresentOrElse(writer::mask, writer::noMask));
}
示例5: findAffinityArg
import java.util.OptionalInt; //導入依賴的package包/類
private static OptionalInt findAffinityArg(Method meth) {
OptionalInt affinityArg = OptionalInt.empty();
if (meth.getParameterCount() > 0) {
for (int i = 0; i < meth.getParameterCount() && !affinityArg.isPresent(); i++) {
Annotation[] annotations = meth.getParameterAnnotations()[i];
for (int j = 0; j < annotations.length; j++) {
if (RpcAffinityKey.class.isAssignableFrom(annotations[j].annotationType())) {
affinityArg = OptionalInt.of(i);
break;
}
}
}
}
return affinityArg;
}
示例6: getWinners
import java.util.OptionalInt; //導入依賴的package包/類
public List<CeremonyOfChaosMember> getWinners()
{
final List<CeremonyOfChaosMember> winners = new ArrayList<>();
//@formatter:off
final OptionalInt winnerLifeTime = getMembers().values().stream()
.mapToInt(CeremonyOfChaosMember::getLifeTime)
.max();
if(winnerLifeTime.isPresent())
{
getMembers().values().stream()
.sorted(Comparator.comparingLong(CeremonyOfChaosMember::getLifeTime)
.reversed()
.thenComparingInt(CeremonyOfChaosMember::getScore)
.reversed())
.filter(member -> member.getLifeTime() == winnerLifeTime.getAsInt())
.collect(Collectors.toCollection(() -> winners));
}
//@formatter:on
return winners;
}
示例7: execute
import java.util.OptionalInt; //導入依賴的package包/類
@Override
protected void execute() {
IntentExtensionService service = get(IntentExtensionService.class);
OptionalInt length = service.getCompilers().keySet().stream()
.mapToInt(s -> s.getName().length())
.max();
if (length.isPresent()) {
service.getCompilers().entrySet().forEach(e -> {
print("%-" + length.getAsInt() + "s\t%s",
e.getKey().getName(),
e.getValue().getClass().getName());
});
} else {
print("There are no compilers registered.");
}
}
示例8: getValue
import java.util.OptionalInt; //導入依賴的package包/類
@Override
public OptionalInt getValue(final JavaType type, final ResultSet rs, final int columnIndex,
final PropertyMapperManager mapperManager) throws SQLException {
int value = rs.getInt(columnIndex);
if (!rs.wasNull()) {
return OptionalInt.of(value);
} else {
return OptionalInt.empty();
}
}
示例9: setup
import java.util.OptionalInt; //導入依賴的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);
}
示例10: testEmpty
import java.util.OptionalInt; //導入依賴的package包/類
@Test(groups = "unit")
public void testEmpty() {
OptionalInt empty = OptionalInt.empty();
OptionalInt present = OptionalInt.of(1);
// empty
assertTrue(empty.equals(empty));
assertTrue(empty.equals(OptionalInt.empty()));
assertTrue(!empty.equals(present));
assertTrue(0 == empty.hashCode());
assertTrue(!empty.toString().isEmpty());
assertTrue(!empty.isPresent());
empty.ifPresent(v -> { fail(); });
AtomicBoolean emptyCheck = new AtomicBoolean();
empty.ifPresentOrElse(v -> fail(), () -> emptyCheck.set(true));
assertTrue(emptyCheck.get());
try {
empty.ifPresentOrElse(v -> fail(), () -> { throw new ObscureException(); });
fail();
} catch (ObscureException expected) {
} catch (AssertionError e) {
throw e;
} catch (Throwable t) {
fail();
}
assertEquals(2, empty.orElse(2));
assertEquals(2, empty.orElseGet(()-> 2));
}
示例11: use
import java.util.OptionalInt; //導入依賴的package包/類
static void use() {
new ApplBuilder()
.a(1)
.b("")
.c(1)
.build();
new BbzBuilder(java.util.Optional.empty(), OptionalInt.empty()).build();
}
示例12: testNumberToOptionalIntConverter
import java.util.OptionalInt; //導入依賴的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());
}
示例13: extractResponseSequenceId
import java.util.OptionalInt; //導入依賴的package包/類
@Override
public OptionalInt extractResponseSequenceId(ByteBuf buffer)
{
try {
TTransport inputTransport = new TChannelBufferInputTransport(buffer.duplicate());
TMessage message = protocolFactory.getProtocol(inputTransport).readMessageBegin();
return OptionalInt.of(message.getSequenceId());
}
catch (Throwable ignored) {
}
return OptionalInt.empty();
}
示例14: load
import java.util.OptionalInt; //導入依賴的package包/類
@Override
public final void load()
{
_classZones.clear();
_spawnTerritories.clear();
parseDatapackDirectory("data/zones", false);
parseDatapackDirectory("data/zones/spawnZones", false);
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _classZones.size() + " zone classes and " + getSize() + " zones.");
LOGGER.info(getClass().getSimpleName() + ": Loaded " + _spawnTerritories.size() + " NPC spawn territoriers.");
final OptionalInt maxId = _classZones.values().stream().flatMap(map -> map.keySet().stream()).mapToInt(Integer.class::cast).filter(value -> value < 300000).max();
LOGGER.info(getClass().getSimpleName() + ": Last static id: " + maxId.getAsInt());
}
示例15: addJavaHandlers
import java.util.OptionalInt; //導入依賴的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('\\', '/'));
}