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

com.urbanairship.api.push.model.notification.wns.WNSBadgeData Maven / Gradle / Ivy

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

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

import java.util.Optional;

public class WNSBadgeData {
    public enum Glyph {
        NONE,
        ACTIVITY,
        ALERT,
        AVAILABLE,
        AWAY,
        BUSY,
        NEW_MESSAGE,
        PAUSED,
        PLAYING,
        UNAVAILABLE,
        ERROR,
        ATTENTION;

        private final String id;

        Glyph() {
            id = name().toLowerCase().replace('_', '-');
        }

        public String getIdentifier() {
            return id;
        }

        public static Glyph get(String value) {
            for (Glyph glyph : values()) {
                if (value.equalsIgnoreCase(glyph.getIdentifier())) {
                    return glyph;
                }
            }
            return null;
        }

    }

    private final Optional value;
    private final Optional glyph;

    private WNSBadgeData(Optional value,
                         Optional glyph)
    {
        this.value = value;
        this.glyph = glyph;
    }

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

    public Optional getValue() {
        return this.value;
    }

    public Optional getGlyph() {
        return this.glyph;
    }

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

        WNSBadgeData that = (WNSBadgeData)o;
        if (value != null ? !value.equals(that.value) : that.value != null) {
            return false;
        }

        return !(glyph != null ? !glyph.equals(that.glyph) : that.glyph != null);
    }

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

    public static class Builder {

        private Integer value;
        private Glyph glyph;

        private Builder() { }

        public Builder setValue(int value) {
            this.value = value;
            return this;
        }

        public Builder setGlyph(Glyph value) {
            this.glyph = value;
            return this;
        }

        public WNSBadgeData build() {
            if (glyph == null && value == null) {
                throw new IllegalArgumentException("Must supply one of 'value' or 'glyph'.");
            }
            if (glyph != null && value != null) {
                throw new IllegalArgumentException("Must supply one of 'value' or 'glyph', but not both.");
            }
            return new WNSBadgeData(Optional.ofNullable(value),
                                    Optional.ofNullable(glyph));
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy