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

com.arm.mbed.cloud.sdk.connect.adapters.ResourceAdapter Maven / Gradle / Ivy

Go to download

The Pelion Cloud SDK (formerly known as Mbed Cloud SDK) provides a simplified interface to the Pelion Cloud APIs by exposing functionality using conventions and paradigms familiar to Java developers.

There is a newer version: 2.5.0
Show newest version
package com.arm.mbed.cloud.sdk.connect.adapters;

import java.util.List;

import com.arm.mbed.cloud.sdk.annotations.Preamble;
import com.arm.mbed.cloud.sdk.common.GenericAdapter;
import com.arm.mbed.cloud.sdk.common.GenericAdapter.Mapper;
import com.arm.mbed.cloud.sdk.common.TranslationUtils;
import com.arm.mbed.cloud.sdk.connect.model.Resource;
import com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.ResourcesData;

@Preamble(description = "Adapter for resource model")
public final class ResourceAdapter {

    private ResourceAdapter() {
        super();
    }

    /**
     * Maps a resource.
     *
     * @param resourceData
     *            resource data.
     * @param deviceId
     *            device id of the device containing the resource
     * @return mapped resource
     */
    public static Resource map(ResourcesData resourceData, String deviceId) {
        if (resourceData == null) {
            return null;
        }
        return new Resource(deviceId, resourceData.getPath(), resourceData.getRt(), resourceData.getCt(),
                            TranslationUtils.toBool(resourceData.isObs(), false), resourceData.getIf());
    }

    /**
     * Maps a resource.
     *
     * @param deviceId
     *            device id of the device containing the resource
     * @param apiResource
     *            resource to map
     * @return mapped resource
     */
    public static Resource map(String deviceId,
                               com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.Resource apiResource) {
        if (apiResource == null || deviceId == null || deviceId.isEmpty()) {
            return null;
        }
        return new Resource(deviceId, apiResource.getUri(), apiResource.getRt(), apiResource.getType(),
                            TranslationUtils.toBool(apiResource.isObs(), false), null);
    }

    /**
     * Gets a mapper.
     *
     * @param deviceId
     *            device id of the device containing the resource
     * @return a mapper for this device.
     */
    public static Mapper getResourceDataMapper(String deviceId) {
        final String immutableDeviceId = deviceId;
        return new Mapper() {

            @Override
            public Resource map(ResourcesData toBeMapped) {
                return ResourceAdapter.map(toBeMapped, immutableDeviceId);
            }
        };
    }

    /**
     * Maps a list of resources.
     *
     * @param deviceId
     *            device id of the device containing the resources
     * @param list
     *            resource data
     * @return list of resources
     */
    public static List mapResourceDataList(String deviceId, List list) {
        return GenericAdapter.mapList(list, getResourceDataMapper(deviceId));
    }

    /**
     * Gets a mapper.
     *
     * @param deviceId
     *            device id of the device containing the resource
     * @return a mapper for this device.
     */
    public static Mapper
           getMapper(String deviceId) {
        final String immutableDeviceId = deviceId;
        return new Mapper() {

            @Override
            public Resource map(com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.Resource toBeMapped) {
                return ResourceAdapter.map(immutableDeviceId, toBeMapped);
            }
        };
    }

    /**
     * Maps a list of resources.
     *
     * @param deviceId
     *            device id of the device containing the resources
     * @param list
     *            resource page
     * @return list of resources
     */
    public static List
           mapList(String deviceId,
                   List list) {
        return GenericAdapter.mapList(list, getMapper(deviceId));
    }

    /**
     * Gets list mapper.
     *
     * @param deviceId
     *            device id of the device containing the resources
     * @return a list mapper
     */
    public static
           Mapper, List>
           getListMapper(String deviceId) {
        final String immutableDeviceId = deviceId;
        return new Mapper,
                          List>() {

            @Override
            public List
                   map(List toBeMapped) {
                return ResourceAdapter.mapList(immutableDeviceId, toBeMapped);
            }

        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy