Skip to content

Commit

Permalink
[bidi][java] Update Locator class to not use optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Apr 3, 2024
1 parent 309b3e8 commit baf6116
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions java/src/org/openqa/selenium/bidi/browsingcontext/Locator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Optional;

public class Locator {
final Map<String, Object> map = new HashMap<>();

private enum Type {
CSS("css"),
INNER("innerText"),
Expand All @@ -39,32 +41,22 @@ public String toString() {
}
}

private final Type type;

private final String value;

private Optional<Boolean> ignoreCase = Optional.empty();

private Optional<String> matchType = Optional.empty();

private Optional<Long> maxDepth = Optional.empty();

private Locator(Type type, String value) {
this.type = type;
this.value = value;
map.put("type", type.toString());
map.put("value", value);
}

public Locator(
private Locator(
Type type,
String value,
Optional<Boolean> ignoreCase,
Optional<String> matchType,
Optional<Long> maxDepth) {
this.type = type;
this.value = value;
this.ignoreCase = ignoreCase;
this.matchType = matchType;
this.maxDepth = maxDepth;
map.put("type", type.toString());
map.put("value", value);
ignoreCase.ifPresent(val -> map.put("ignoreCase", val));
matchType.ifPresent(val -> map.put("matchType", val));
maxDepth.ifPresent(val -> map.put("maxDepth", val));
}

public static Locator css(String value) {
Expand All @@ -88,14 +80,6 @@ public static Locator xpath(String value) {
}

public Map<String, Object> toMap() {
final Map<String, Object> map = new HashMap<>();
map.put("type", type.toString());
map.put("value", value);

ignoreCase.ifPresent(val -> map.put("ignoreCase", val));
matchType.ifPresent(val -> map.put("matchType", val));
maxDepth.ifPresent(val -> map.put("maxDepth", val));

return map;
}
}

0 comments on commit baf6116

Please sign in to comment.