blob: 07438e1e3258a4fced2da22ff5f636a9e4323dd7 [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.OptionalLong;
8
9public final class OptionalLongBackportJava9Main {
10
11 public static void main(String[] args) {
12 testIfPresentOrElseLong();
13 testStreamLong();
14 }
15
16 private static void testIfPresentOrElseLong() {
17 OptionalLong value = OptionalLong.of(1L);
18 OptionalLong emptyValue = OptionalLong.empty();
19 value.ifPresentOrElse(val -> {}, () -> assertTrue(false));
20 emptyValue.ifPresentOrElse(val -> assertTrue(false), () -> {});
21 }
22
23 private static void testStreamLong() {
24 OptionalLong value = OptionalLong.of(2L);
25 OptionalLong emptyValue = OptionalLong.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}