Java Code Examples for java.util.OptionalInt#ifPresentOrElse()
The following examples show how to use
java.util.OptionalInt#ifPresentOrElse() .
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: HeaderWriterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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)); }
Example 2
Source File: BasicInt.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@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)); }
Example 3
Source File: ReaderTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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()); }); }