本文整理匯總了Java中java.util.OptionalInt.ifPresentOrElse方法的典型用法代碼示例。如果您正苦於以下問題:Java OptionalInt.ifPresentOrElse方法的具體用法?Java OptionalInt.ifPresentOrElse怎麽用?Java OptionalInt.ifPresentOrElse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.OptionalInt
的用法示例。
在下文中一共展示了OptionalInt.ifPresentOrElse方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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));
}
示例2: 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));
}
示例3: verifyFrameStart
import java.util.OptionalInt; //導入方法依賴的package包/類
private void verifyFrameStart(boolean fin,
boolean rsv1,
boolean rsv2,
boolean rsv3,
Opcode opcode,
long payloadLen,
OptionalInt mask) {
frames++;
Frame.HeaderWriter w = new Frame.HeaderWriter();
ByteBuffer h = ByteBuffer.allocate(Frame.MAX_HEADER_SIZE_BYTES);
w.fin(fin).rsv1(rsv1).rsv2(rsv2).rsv3(rsv3).opcode(opcode).payloadLen(payloadLen);
mask.ifPresentOrElse(w::mask, w::noMask);
w.write(h);
h.flip();
forEachBufferPartition(h,
buffers -> {
cases++;
Frame.Reader r = new Frame.Reader();
MockConsumer c = new MockConsumer();
for (ByteBuffer b : buffers) {
r.readFrame(b, c);
}
assertEquals(fin, c.fin());
assertEquals(rsv1, c.rsv1());
assertEquals(rsv2, c.rsv2());
assertEquals(rsv3, c.rsv3());
assertEquals(opcode, c.opcode());
assertEquals(mask.isPresent(), c.mask());
assertEquals(payloadLen, c.payloadLen());
assertEquals(mask, c.maskingKey());
assertEquals(payloadLen == 0, c.isEndFrame());
});
}