Java Code Examples for java.util.OptionalDouble#ifPresent()
The following examples show how to use
java.util.OptionalDouble#ifPresent() .
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: BasicDouble.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 2
Source File: BasicDouble.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 3
Source File: BasicDouble.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 4
Source File: BasicDouble.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 5
Source File: BasicDouble.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 6
Source File: BasicDouble.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 7
Source File: BasicDouble.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Test(groups = "unit") public void testEmpty() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // empty assertTrue(empty.equals(empty)); assertTrue(empty.equals(OptionalDouble.empty())); assertTrue(!empty.equals(present)); assertTrue(0 == empty.hashCode()); assertTrue(!empty.toString().isEmpty()); assertTrue(!empty.isPresent()); empty.ifPresent(v -> { fail(); }); assertEquals(2.0, empty.orElse(2.0)); assertEquals(2.0, empty.orElseGet(()-> 2.0)); }
Example 8
Source File: BasicDouble.java From hottub with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 9
Source File: BasicDouble.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 10
Source File: OptionalDoubleAttributeConverter.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Override public OptionalDouble transformTo(AttributeValue input) { OptionalDouble result; if (input.n() != null) { result = EnhancedAttributeValue.fromNumber(input.n()).convert(VISITOR); } else { result = EnhancedAttributeValue.fromAttributeValue(input).convert(VISITOR); } result.ifPresent(ConverterUtils::validateDouble); return result; }
Example 11
Source File: BasicDouble.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 12
Source File: BasicDouble.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 13
Source File: BasicDouble.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 14
Source File: BasicDouble.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 15
Source File: BasicDouble.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 16
Source File: BasicDouble.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 17
Source File: BasicDouble.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 18
Source File: BasicDouble.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Test(groups = "unit") public void testPresent() { OptionalDouble empty = OptionalDouble.empty(); OptionalDouble present = OptionalDouble.of(1.0); // present assertTrue(present.equals(present)); assertFalse(present.equals(OptionalDouble.of(0.0))); assertTrue(present.equals(OptionalDouble.of(1.0))); assertTrue(!present.equals(empty)); assertTrue(Double.hashCode(1.0) == present.hashCode()); assertFalse(present.toString().isEmpty()); assertTrue(-1 != present.toString().indexOf(Double.toString(present.getAsDouble()).toString())); assertEquals(1.0, present.getAsDouble()); try { present.ifPresent(v -> { throw new ObscureException(); }); fail(); } catch(ObscureException expected) { } assertEquals(1.0, present.orElse(2.0)); assertEquals(1.0, present.orElseGet(null)); assertEquals(1.0, present.orElseGet(()-> 2.0)); assertEquals(1.0, present.orElseGet(()-> 3.0)); assertEquals(1.0, present.<RuntimeException>orElseThrow(null)); assertEquals(1.0, present.<RuntimeException>orElseThrow(ObscureException::new)); }
Example 19
Source File: RecordJsonMapper.java From component-runtime with Apache License 2.0 | 4 votes |
@Override public void onDouble(final Schema.Entry entry, final OptionalDouble optionalDouble) { optionalDouble.ifPresent(v -> builder.add(entry.getName(), v)); }
Example 20
Source File: OptionalDoubleExample.java From levelup-java-examples with Apache License 2.0 | 3 votes |
@Test public void optional_double_ifPresent() { OptionalDouble optionalDouble = OptionalDouble.of(56); optionalDouble.ifPresent(p -> System.out.println(p)); // or optionalDouble.ifPresent(System.out::println); }