All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.appium.device.DevicesByHost Maven / Gradle / Ivy

There is a newer version: 14.0.4
Show newest version
package com.appium.device;

import com.appium.ios.IOSDeviceConfiguration;
import com.appium.manager.AppiumDevice;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class DevicesByHost {
    private ConcurrentHashMap> devicesByHost;

    DevicesByHost(Map> devicesByHost) {
        this.devicesByHost = new ConcurrentHashMap<>(devicesByHost);
    }

    public List getAllDevices() {
        return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
                stringListEntry.getValue().parallelStream())
                .collect(Collectors.toList());
    }

    public List getAllSimulators() {
        return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
                stringListEntry.getValue().parallelStream().filter(device ->
                        device.getDevice().getUdid().length()
                                == IOSDeviceConfiguration.SIM_UDID_LENGTH))
                .collect(Collectors.toList());
    }

    public List getAllIOSDevices() {
        return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
                stringListEntry.getValue().parallelStream().filter(device ->
                        device.getDevice().getUdid().length()
                                == IOSDeviceConfiguration.IOS_UDID_LENGTH))
                .collect(Collectors.toList());
    }

    public List getAllAndroidDevices() {
        return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
                stringListEntry.getValue().parallelStream().filter(device ->
                        (device.getDevice().getUdid().length()
                                != IOSDeviceConfiguration.IOS_UDID_LENGTH
                                && device.getDevice().getUdid().length()
                                != IOSDeviceConfiguration.SIM_UDID_LENGTH)))
                .collect(Collectors.toList());
    }

    public AppiumDevice getDeviceProperty(String uuid) {
        return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
                stringListEntry.getValue().parallelStream().filter(device ->
                        device.getDevice().getUdid().equalsIgnoreCase(uuid)))
                .collect(Collectors.toList()).get(0);
    }

    public Set getAllHosts() {
        return devicesByHost.keySet();
    }

    public Map> getAllHostDevices() {
        return devicesByHost;
    }

    public AppiumDevice getAppiumDevice(String deviceUdid, String hostName) {
        List devicesInHost = devicesByHost.get(hostName);
        return devicesInHost.stream().filter(appiumDevice ->
                appiumDevice.getDevice().getUdid().equals(deviceUdid)).findFirst().get();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy