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

com.urbanairship.api.push.model.notification.mpns.MPNSDevicePayload Maven / Gradle / Ivy

There is a newer version: 9.3.0
Show newest version
/*
 * Copyright (c) 2013-2016.  Urban Airship and Contributors
 */

package com.urbanairship.api.push.model.notification.mpns;

import com.google.common.base.Optional;
import com.urbanairship.api.push.model.DeviceType;
import com.urbanairship.api.push.model.PushModelObject;
import com.urbanairship.api.push.model.notification.DevicePayloadOverride;

/**
 * @deprecated Marked to be removed in 2.0.0. MPNS is no longer supported by the Urban Airship API.
 */
@Deprecated
public final class MPNSDevicePayload extends PushModelObject implements DevicePayloadOverride {

    private final Optional body;
    private final Optional alert;

    private MPNSDevicePayload(Optional body, Optional alert) {
        this.body = body;
        this.alert = alert;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    @Override
    public DeviceType getDeviceType() {
        return DeviceType.MPNS;
    }

    @Override
    public Optional getAlert() {
        return alert;
    }

    public MPNSPush.Type getType() {
        if (body.isPresent()) {
            return body.get().getType();
        } else {
            return MPNSPush.Type.TOAST;
        }
    }

    public Optional getBody() {
        return body;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        MPNSDevicePayload that = (MPNSDevicePayload)o;
        if (body != null ? !body.equals(that.body) : that.body != null) {
            return false;
        }
        if (alert != null ? !alert.equals(that.alert) : that.alert != null) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int result = (body != null ? body.hashCode() : 0);
        result = 31 * result + (alert != null ? alert.hashCode() : 0);
        return result;
    }

    public static class Builder {
        private String alert;
        private MPNSPush body;

        private Builder() { }

        public Builder setAlert(String alert) {
            this.alert = alert;
            return this;
        }

        public Builder setBody(MPNSPush body) {
            this.body = body;
            return this;
        }

        public MPNSDevicePayload build() {
            return new MPNSDevicePayload(Optional.fromNullable(body),
                                         Optional.fromNullable(alert));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy