Skip to content

Package: Optional

Optional

nameinstructionbranchcomplexitylinemethod
Optional()
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
Optional(Object)
M: 12 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
get()
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
ifPresent(LambdaExpression)
M: 14 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
isPresent()
M: 7 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
orElse(Object)
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
orElseGet(LambdaExpression)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package com.sun.el.stream;
18:
19: import jakarta.el.LambdaExpression;
20:
21: public class Optional {
22:
23: private final Object value;
24:
25: Optional(Object value) {
26:• if (value == null) {
27: throw new NullPointerException();
28: }
29: this.value = value;
30: }
31:
32: Optional() {
33: this.value = null;
34: }
35:
36: public boolean isPresent() {
37:• return value != null;
38: }
39:
40: public void ifPresent(LambdaExpression lambda) {
41:• if (value != null) {
42: lambda.invoke(value);
43: }
44: }
45:
46: public Object get() {
47:• if (value == null) {
48: throw new java.util.NoSuchElementException("No value present");
49: }
50: return value;
51: }
52:
53: public Object orElse(Object other) {
54:• return value != null ? value : other;
55: }
56:
57: public Object orElseGet(LambdaExpression other) {
58:• return value != null ? value : other.invoke();
59: }
60: }