blob: 9b087180d4995b66f0b9abf7ffb12bb2616b803e [file] [log] [blame]
Jake Whartonb2235272019-12-12 20:39:36 -05001// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5package backport;
6
7import java.util.OptionalDouble;
8
9public final class OptionalDoubleBackportJava9Main {
10
11 public static void main(String[] args) {
12 testIfPresentOrElseDouble();
13 testStreamDouble();
14 }
15
16 private static void testIfPresentOrElseDouble() {
17 OptionalDouble value = OptionalDouble.of(1.0d);
18 OptionalDouble emptyValue = OptionalDouble.empty();
19 value.ifPresentOrElse(val -> {}, () -> assertTrue(false));
20 emptyValue.ifPresentOrElse(val -> assertTrue(false), () -> {});
21 }
22
23 private static void testStreamDouble() {
24 OptionalDouble value = OptionalDouble.of(2d);
25 OptionalDouble emptyValue = OptionalDouble.empty();
26 assertTrue(value.stream().count() == 1);
27 assertTrue(emptyValue.stream().count() == 0);
28 }
29
30 private static void assertTrue(boolean value) {
31 if (!value) {
32 throw new AssertionError("Expected <true> but was <false>");
33 }
34 }
35}