Example usage for org.openqa.selenium.remote.session CapabilityTransform apply

List of usage examples for org.openqa.selenium.remote.session CapabilityTransform apply

Introduction

In this page you can find the example usage for org.openqa.selenium.remote.session CapabilityTransform apply.

Prototype

@Override
Collection<Map.Entry<String, Object>> apply(Map.Entry<String, Object> entry);

Source Link

Usage

From source file:io.appium.java_client.remote.NewAppiumSessionPayload.java

License:Apache License

private Map<String, Object> applyTransforms(Map<String, Object> caps) {
    Queue<Map.Entry<String, Object>> toExamine = new LinkedList<>(caps.entrySet());
    Set<String> seenKeys = new HashSet<>();
    Map<String, Object> toReturn = new TreeMap<>();

    // Take each entry and apply the transforms
    while (!toExamine.isEmpty()) {
        Map.Entry<String, Object> entry = toExamine.remove();
        seenKeys.add(entry.getKey());//from   w  w w  . j a v a 2 s.  com

        if (entry.getValue() == null) {
            continue;
        }

        for (CapabilityTransform transform : transforms) {
            Collection<Map.Entry<String, Object>> result = transform.apply(entry);
            if (result == null) {
                toReturn.remove(entry.getKey());
                break;
            }

            for (Map.Entry<String, Object> newEntry : result) {
                if (!seenKeys.contains(newEntry.getKey())) {
                    toExamine.add(newEntry);
                    continue;
                }
                if (newEntry.getKey().equals(entry.getKey())) {
                    entry = newEntry;
                }
                toReturn.put(newEntry.getKey(), newEntry.getValue());
            }
        }
    }
    return toReturn;
}