Skip to content

Commit 87f1be2

Browse files
authored
[java] simplify several statements with isEmpty function call (#16836)
1 parent 6829c4c commit 87f1be2

File tree

18 files changed

+22
-24
lines changed

18 files changed

+22
-24
lines changed

java/src/org/openqa/selenium/devtools/v141/v141Events.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {
8787

8888
JavascriptException exception = new JavascriptException(message);
8989

90-
if (!maybeTrace.isPresent()) {
90+
if (maybeTrace.isEmpty()) {
9191
StackTraceElement element =
9292
new StackTraceElement(
9393
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());

java/src/org/openqa/selenium/devtools/v142/v142Events.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {
8787

8888
JavascriptException exception = new JavascriptException(message);
8989

90-
if (!maybeTrace.isPresent()) {
90+
if (maybeTrace.isEmpty()) {
9191
StackTraceElement element =
9292
new StackTraceElement(
9393
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());

java/src/org/openqa/selenium/devtools/v143/v143Events.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected JavascriptException toJsException(ExceptionThrown event) {
8787

8888
JavascriptException exception = new JavascriptException(message);
8989

90-
if (!maybeTrace.isPresent()) {
90+
if (maybeTrace.isEmpty()) {
9191
StackTraceElement element =
9292
new StackTraceElement(
9393
"unknown", "unknown", details.getUrl().orElse("unknown"), details.getLineNumber());

java/src/org/openqa/selenium/docker/Docker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private Optional<DockerProtocol> getDocker() {
9595
}
9696

9797
synchronized (this) {
98-
if (!dockerClient.isPresent()) {
98+
if (dockerClient.isEmpty()) {
9999
VersionCommand versionCommand = new VersionCommand(client);
100100
dockerClient =
101101
apiVersion != null

java/src/org/openqa/selenium/grid/config/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ default Optional<Boolean> getBool(String section, String option) {
4848

4949
default Optional<List<List<String>>> getArray(String section, String option) {
5050
Optional<List<String>> flatConfigs = getAll(section, option);
51-
if (!flatConfigs.isPresent()) {
51+
if (flatConfigs.isEmpty()) {
5252
return Optional.empty();
5353
}
5454

java/src/org/openqa/selenium/grid/distributor/local/LocalGridModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ public boolean reserve(SlotId slotId) {
339339
Optional<Slot> maybeSlot =
340340
node.getSlots().stream().filter(slot -> slotId.equals(slot.getId())).findFirst();
341341

342-
if (!maybeSlot.isPresent()) {
342+
if (maybeSlot.isEmpty()) {
343343
LOG.warning(
344344
String.format(
345345
"Asked to reserve slot on node %s, but no slot with id %s found",
@@ -437,7 +437,7 @@ public void setSession(SlotId slotId, Session session) {
437437
Optional<Slot> maybeSlot =
438438
node.getSlots().stream().filter(slot -> slotId.equals(slot.getId())).findFirst();
439439

440-
if (!maybeSlot.isPresent()) {
440+
if (maybeSlot.isEmpty()) {
441441
LOG.warning("Grid model and reality have diverged. Unable to find slot " + slotId);
442442
return;
443443
}

java/src/org/openqa/selenium/grid/distributor/selector/DefaultSlotSelector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ public Set<SlotId> selectSlot(
5959
// Then sort by stereotype browserVersion (descending order). SemVer comparison with
6060
// considering empty value at first.
6161
.thenComparing(
62-
Comparator.comparing(
63-
NodeStatus::getBrowserVersion, new SemanticVersionComparator().reversed()))
62+
NodeStatus::getBrowserVersion, new SemanticVersionComparator().reversed())
6463
// And use the node id as a tie-breaker.
6564
.thenComparing(NodeStatus::getNodeId))
6665
.flatMap(

java/src/org/openqa/selenium/grid/distributor/selector/GreedySlotSelector.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ public Set<SlotId> selectSlot(
6161
.thenComparingLong(NodeStatus::getLastSessionCreated)
6262
// Then sort by stereotype browserVersion (descending order)
6363
.thenComparing(
64-
Comparator.comparing(
65-
NodeStatus::getBrowserVersion, new SemanticVersionComparator().reversed())))
64+
NodeStatus::getBrowserVersion, new SemanticVersionComparator().reversed()))
6665
.flatMap(
6766
node ->
6867
node.getSlots().stream()

java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ private String getApiVersion() {
120120
}
121121

122122
private boolean isEnabled(Docker docker) {
123-
if (!config.getAll(DOCKER_SECTION, "configs").isPresent()) {
123+
if (config.getAll(DOCKER_SECTION, "configs").isEmpty()) {
124124
return false;
125125
}
126126

java/src/org/openqa/selenium/grid/node/docker/DockerSessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ private TimeZone getTimeZone(Capabilities sessionRequestCapabilities) {
470470
private Dimension getScreenResolution(Capabilities sessionRequestCapabilities) {
471471
Optional<Object> screenResolution =
472472
ofNullable(sessionRequestCapabilities.getCapability("se:screenResolution"));
473-
if (!screenResolution.isPresent()) {
473+
if (screenResolution.isEmpty()) {
474474
return null;
475475
}
476476
try {

0 commit comments

Comments
 (0)