MCPcopy Index your code
hub / github.com/SeleniumHQ/selenium / MapConfig

Class MapConfig

java/src/org/openqa/selenium/grid/config/MapConfig.java:32–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30import org.openqa.selenium.internal.Require;
31
32public class MapConfig implements Config {
33
34 private final Map<String, Map<String, Object>> raw;
35
36 public MapConfig() {
37 this(emptyMap());
38 }
39
40 public MapConfig(Map<String, Object> raw) {
41 Require.nonNull("Underlying map", raw);
42
43 this.raw =
44 raw.entrySet().stream()
45 .filter(entry -> entry.getValue() instanceof Map)
46 .collect(
47 toUnmodifiableMap(
48 entry -> entry.getKey(),
49 entry ->
50 ((Map<?, ?>) entry.getValue())
51 .entrySet().stream()
52 .filter(e -> e.getKey() instanceof String)
53 .collect(
54 toUnmodifiableMap(
55 e -> String.valueOf(e.getKey()), e -> e.getValue()))));
56 }
57
58 @Override
59 public Optional<List<String>> getAll(String section, String option) {
60 Require.nonNull("Section name", section);
61 Require.nonNull("Option name", option);
62
63 Map<String, Object> rawSection = raw.get(section);
64 if (rawSection == null) {
65 return Optional.empty();
66 }
67
68 Object value = rawSection.get(option);
69 if (value == null) {
70 return Optional.empty();
71 }
72
73 if (value instanceof Collection) {
74 Collection<?> collection = (Collection<?>) value;
75 // Case when an array of map is used as config
76 if (collection.stream().anyMatch(item -> item instanceof Map)) {
77 return Optional.of(
78 collection.stream()
79 .map(item -> (Map<String, Object>) item)
80 .map(this::toEntryList)
81 .flatMap(Collection::stream)
82 .collect(toUnmodifiableList()));
83 }
84
85 return Optional.of(
86 collection.stream()
87 .filter(item -> (!(item instanceof Collection)))
88 .map(String::valueOf)
89 .collect(toUnmodifiableList()));

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected