1717
1818package org .openqa .selenium ;
1919
20+ import java .util .Collections ;
2021import java .util .Map ;
2122import java .util .Set ;
2223import java .util .function .Function ;
24+ import java .util .stream .Collector ;
2325import java .util .stream .Collectors ;
2426import java .util .stream .Stream ;
2527import org .openqa .selenium .internal .Require ;
@@ -56,7 +58,7 @@ public PersistentCapabilities setCapability(String name, Object value) {
5658 @ Override
5759 public Map <String , Object > asMap () {
5860 return getCapabilityNames ().stream ()
59- .collect (Collectors . toUnmodifiableMap (Function .identity (), this ::getCapability ));
61+ .collect (toUnmodifiableMap (Function .identity (), this ::getCapability ));
6062 }
6163
6264 @ Override
@@ -79,7 +81,19 @@ public Capabilities merge(Capabilities other) {
7981 public Set <String > getCapabilityNames () {
8082 return Stream .concat (
8183 caps .getCapabilityNames ().stream (), overrides .getCapabilityNames ().stream ())
82- .collect (Collectors .toUnmodifiableSet ());
84+ .collect (toUnmodifiableSet ());
85+ }
86+
87+ // Needed, since we're dependent on Java 8 as a minimum version
88+ private <T , K , U > Collector <T , ?, Map <K , U >> toUnmodifiableMap (
89+ Function <? super T , ? extends K > keyMapper , Function <? super T , ? extends U > valueMapper ) {
90+ return Collectors .collectingAndThen (
91+ Collectors .toMap (keyMapper , valueMapper ), Collections ::unmodifiableMap );
92+ }
93+
94+ // Needed, since we're dependent on Java 8 as a minimum version
95+ private <T > Collector <T , ?, Set <T >> toUnmodifiableSet () {
96+ return Collectors .collectingAndThen (Collectors .toSet (), Collections ::unmodifiableSet );
8397 }
8498
8599 @ Override
0 commit comments