mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8291954: Use Optional.isEmpty instead of !Optional.isPresent in java.base
Reviewed-by: jpai, alanb, lancea, rriggs, bpb
This commit is contained in:
parent
87cda21c5d
commit
ae52053757
6 changed files with 21 additions and 23 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, Azul Systems, Inc. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
|
@ -36,7 +36,6 @@ import java.util.Optional;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.loader.NativeLibrary;
|
||||
import jdk.internal.reflect.CallerSensitive;
|
||||
import jdk.internal.reflect.Reflection;
|
||||
|
||||
|
@ -1075,7 +1074,7 @@ public class Runtime {
|
|||
m.group(VersionPattern.OPT_GROUP));
|
||||
|
||||
// empty '+'
|
||||
if (!build.isPresent()) {
|
||||
if (build.isEmpty()) {
|
||||
if (m.group(VersionPattern.PLUS_GROUP) != null) {
|
||||
if (optional.isPresent()) {
|
||||
if (pre.isPresent())
|
||||
|
@ -1087,7 +1086,7 @@ public class Runtime {
|
|||
+ " build or optional components: '" + s + "'");
|
||||
}
|
||||
} else {
|
||||
if (optional.isPresent() && !pre.isPresent()) {
|
||||
if (optional.isPresent() && pre.isEmpty()) {
|
||||
throw new IllegalArgumentException("optional component"
|
||||
+ " must be preceded by a pre-release component"
|
||||
+ " or '+': '" + s + "'");
|
||||
|
@ -1353,11 +1352,11 @@ public class Runtime {
|
|||
|
||||
private int comparePre(Version obj) {
|
||||
Optional<String> oPre = obj.pre();
|
||||
if (!pre.isPresent()) {
|
||||
if (pre.isEmpty()) {
|
||||
if (oPre.isPresent())
|
||||
return 1;
|
||||
} else {
|
||||
if (!oPre.isPresent())
|
||||
if (oPre.isEmpty())
|
||||
return -1;
|
||||
String val = pre.get();
|
||||
String oVal = oPre.get();
|
||||
|
@ -1388,11 +1387,11 @@ public class Runtime {
|
|||
|
||||
private int compareOptional(Version obj) {
|
||||
Optional<String> oOpt = obj.optional();
|
||||
if (!optional.isPresent()) {
|
||||
if (optional.isEmpty()) {
|
||||
if (oOpt.isPresent())
|
||||
return -1;
|
||||
} else {
|
||||
if (!oOpt.isPresent())
|
||||
if (oOpt.isEmpty())
|
||||
return 1;
|
||||
return optional.get().compareTo(oOpt.get());
|
||||
}
|
||||
|
|
|
@ -6780,7 +6780,7 @@ assertEquals("boojum", (String) catTrace.invokeExact("boo", "jum"));
|
|||
loopReturnType + ")");
|
||||
}
|
||||
|
||||
if (!pred.stream().filter(Objects::nonNull).findFirst().isPresent()) {
|
||||
if (pred.stream().noneMatch(Objects::nonNull)) {
|
||||
throw newIllegalArgumentException("no predicate found", pred);
|
||||
}
|
||||
if (pred.stream().filter(Objects::nonNull).map(MethodHandle::type).map(MethodType::returnType).
|
||||
|
|
|
@ -867,7 +867,7 @@ final class Resolver {
|
|||
Set<ModuleReference> result = new HashSet<>(beforeModules);
|
||||
for (ModuleReference mref : afterModules) {
|
||||
String name = mref.descriptor().name();
|
||||
if (!beforeFinder.find(name).isPresent()
|
||||
if (beforeFinder.find(name).isEmpty()
|
||||
&& findInParent(name) == null) {
|
||||
result.add(mref);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -212,7 +212,7 @@ public final class Optional<T> {
|
|||
*/
|
||||
public Optional<T> filter(Predicate<? super T> predicate) {
|
||||
Objects.requireNonNull(predicate);
|
||||
if (!isPresent()) {
|
||||
if (isEmpty()) {
|
||||
return this;
|
||||
} else {
|
||||
return predicate.test(value) ? this : empty();
|
||||
|
@ -254,7 +254,7 @@ public final class Optional<T> {
|
|||
*/
|
||||
public <U> Optional<U> map(Function<? super T, ? extends U> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (!isPresent()) {
|
||||
if (isEmpty()) {
|
||||
return empty();
|
||||
} else {
|
||||
return Optional.ofNullable(mapper.apply(value));
|
||||
|
@ -282,7 +282,7 @@ public final class Optional<T> {
|
|||
*/
|
||||
public <U> Optional<U> flatMap(Function<? super T, ? extends Optional<? extends U>> mapper) {
|
||||
Objects.requireNonNull(mapper);
|
||||
if (!isPresent()) {
|
||||
if (isEmpty()) {
|
||||
return empty();
|
||||
} else {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -331,7 +331,7 @@ public final class Optional<T> {
|
|||
* @since 9
|
||||
*/
|
||||
public Stream<T> stream() {
|
||||
if (!isPresent()) {
|
||||
if (isEmpty()) {
|
||||
return Stream.empty();
|
||||
} else {
|
||||
return Stream.of(value);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue