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

com.arm.mbed.cloud.sdk.subscribe.adapters.ResourceValueNotificationAdapter Maven / Gradle / Ivy

package com.arm.mbed.cloud.sdk.subscribe.adapters;

import java.util.List;

import com.arm.mbed.cloud.sdk.annotations.Internal;
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.lowlevel.pelionclouddevicemanagement.model.NotificationData;
import com.arm.mbed.cloud.sdk.lowlevel.pelionclouddevicemanagement.model.NotificationMessage;
import com.arm.mbed.cloud.sdk.subscribe.model.ResourceValueNotification;

@Preamble(description = "Adapter for resource value change notifications")
@Internal
public final class ResourceValueNotificationAdapter {

    private ResourceValueNotificationAdapter() {
        super();
    }

    /**
     * Maps resource value notification.
     *
     * @param notificationData
     *            notification data.
     * @return a resource value notification.
     */
    public static ResourceValueNotification map(NotificationData notificationData) {
        if (notificationData == null) {
            return null;
        }
        final ResourceValueNotification notification = new ResourceValueNotification(notificationData.getEp(),
                                                                                     notificationData.getPath());
        notification.setMaxAge(notificationData.getMaxAge());
        notification.decodePayload(notificationData.getPayload(), notificationData.getCt());
        return notification;
    }

    /**
     * Gets a mapper.
     *
     * @return a mapper
     */
    public static Mapper getMapper() {
        return new Mapper() {

            @Override
            public ResourceValueNotification map(NotificationData toBeMapped) {
                return ResourceValueNotificationAdapter.map(toBeMapped);
            }
        };
    }

    /**
     * Maps a list of notification data.
     *
     * @param list
     *            list of notification data.
     * @return list of resource value notification.
     */
    public static List mapList(List list) {
        return GenericAdapter.mapList(list, getMapper());
    }

    /**
     * Gets list mapper.
     *
     *
     * @return a list mapper.
     */
    public static Mapper, List> getListMapper() {

        return new Mapper, List>() {

            @Override
            public List map(List toBeMapped) {
                return ResourceValueNotificationAdapter.mapList(toBeMapped);
            }

        };
    }

    /**
     * Maps resource value change notifications.
     *
     * @param notificationMessage
     *            notification message.
     * @return list of resource value change notification.
     */
    public static List mapNotificationMessage(NotificationMessage notificationMessage) {
        if (notificationMessage == null) {
            return null;
        }
        return ResourceValueNotificationAdapter.mapList(notificationMessage.getNotifications());
    }

    /**
     * Gets notification message mapper.
     *
     * @return a list mapper.
     */
    public static Mapper> getNotificationMessageMapper() {
        return new Mapper>() {

            @Override
            public List map(NotificationMessage toBeMapped) {
                return ResourceValueNotificationAdapter.mapNotificationMessage(toBeMapped);
            }

        };
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy