Class MpnBuilder


  • public class MpnBuilder
    extends java.lang.Object
    Utility class that provides methods to build or parse the JSON structure used to represent the format of a push notification.
    It provides getters and setters for the fields of a push notification, following the format specified by Google's Firebase Cloud Messaging (FCM). This format is compatible with MpnSubscription.setNotificationFormat(String).
    See Also:
    MpnSubscription.setNotificationFormat(String)
    • Constructor Summary

      Constructors 
      Constructor Description
      MpnBuilder()
      Creates an empty object to be used to create a push notification format from scratch.
      Use setters methods to set the value of push notification fields.
      MpnBuilder​(java.lang.String notificationFormat)
      Creates an object based on the specified push notification format.
      Use getter methods to obtain the value of push notification fields.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String body()
      Gets the value of android.notification.body field.
      MpnBuilder body​(java.lang.String body)
      Sets the android.notification.body field.
      java.util.List<java.lang.String> bodyLocArguments()
      Gets the value of android.notification.body_loc_args field.
      MpnBuilder bodyLocArguments​(java.util.List<java.lang.String> bodyLocArguments)
      Sets the android.notification.body_loc_args field.
      java.lang.String bodyLocKey()
      Gets the value of android.notification.body_loc_key field.
      MpnBuilder bodyLocKey​(java.lang.String bodyLocKey)
      Sets the android.notification.body_loc_key field.
      java.lang.String build()
      Produces the JSON structure for the push notification format specified by this object.
      java.lang.String clickAction()
      Gets the value of android.notification.click_action field.
      MpnBuilder clickAction​(java.lang.String clickAction)
      Sets the android.notification.click_action field.
      java.lang.String collapseKey()
      Gets the value of android.collapse_key field.
      MpnBuilder collapseKey​(java.lang.String collapseKey)
      Sets the android.collapse_key field.
      java.lang.String color()
      Gets the value of android.notification.color field.
      MpnBuilder color​(java.lang.String color)
      Sets the android.notification.color field.
      java.util.Map<java.lang.String,​java.lang.String> data()
      Gets sub-fields of the android.data field.
      MpnBuilder data​(java.util.Map<java.lang.String,​java.lang.String> data)
      Sets sub-fields of the android.data field.
      java.lang.String icon()
      Gets the value of android.notification.icon field.
      MpnBuilder icon​(java.lang.String icon)
      Sets the android.notification.icon field.
      java.lang.String priority()
      Gets the value of android.priority field.
      MpnBuilder priority​(java.lang.String priority)
      Sets the android.priority field.
      java.lang.String sound()
      Gets the value of android.notification.sound field.
      MpnBuilder sound​(java.lang.String sound)
      Sets the android.notification.sound field.
      java.lang.String tag()
      Gets the value of android.notification.tag field.
      MpnBuilder tag​(java.lang.String tag)
      Sets the android.notification.tag field.
      MpnBuilder timeToLive​(java.lang.Integer timeToLive)
      Sets the android.ttl field with an integer value.
      MpnBuilder timeToLive​(java.lang.String timeToLive)
      Sets the android.ttl field with a string value.
      java.lang.Integer timeToLiveAsInteger()
      Gets the value of android.ttl field as an integer.
      java.lang.String timeToLiveAsString()
      Gets the value of android.ttl field as a string.
      java.lang.String title()
      Gets the value of android.notification.title field.
      MpnBuilder title​(java.lang.String title)
      Sets the android.notification.title field.
      java.util.List<java.lang.String> titleLocArguments()
      Gets the value of android.notification.title_loc_args field.
      MpnBuilder titleLocArguments​(java.util.List<java.lang.String> titleLocArguments)
      Sets the android.notification.title_loc_args field.
      java.lang.String titleLocKey()
      Gets the value of android.notification.title_loc_key field.
      MpnBuilder titleLocKey​(java.lang.String titleLocKey)
      Sets the android.notification.title_loc_key field.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MpnBuilder

        public MpnBuilder()
        Creates an empty object to be used to create a push notification format from scratch.
        Use setters methods to set the value of push notification fields.
      • MpnBuilder

        public MpnBuilder​(@Nonnull
                          java.lang.String notificationFormat)
        Creates an object based on the specified push notification format.
        Use getter methods to obtain the value of push notification fields.
        Parameters:
        notificationFormat - A JSON structure representing a push notification format.
        Throws:
        java.lang.IllegalArgumentException - if the notification is not a valid JSON structure.
    • Method Detail

      • build

        @Nonnull
        public java.lang.String build()
        Produces the JSON structure for the push notification format specified by this object.
        Returns:
        the JSON structure for the push notification format.
      • collapseKey

        public MpnBuilder collapseKey​(java.lang.String collapseKey)
        Sets the android.collapse_key field.
        Parameters:
        collapseKey - A string to be used for the android.collapse_key field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • collapseKey

        public java.lang.String collapseKey()
        Gets the value of android.collapse_key field.
        Returns:
        the value of android.collapse_key field, or null if absent.
      • priority

        public MpnBuilder priority​(java.lang.String priority)
        Sets the android.priority field.
        Parameters:
        priority - A string to be used for the android.priority field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • priority

        public java.lang.String priority()
        Gets the value of android.priority field.
        Returns:
        the value of android.priority field, or null if absent.
      • timeToLive

        public MpnBuilder timeToLive​(java.lang.String timeToLive)
        Sets the android.ttl field with a string value.
        Parameters:
        timeToLive - A string to be used for the android.ttl field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • timeToLiveAsString

        public java.lang.String timeToLiveAsString()
        Gets the value of android.ttl field as a string.
        Returns:
        a string with the value of android.ttl field, or null if absent.
      • timeToLive

        public MpnBuilder timeToLive​(java.lang.Integer timeToLive)
        Sets the android.ttl field with an integer value.
        Parameters:
        timeToLive - An integer to be used for the android.ttl field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • timeToLiveAsInteger

        public java.lang.Integer timeToLiveAsInteger()
        Gets the value of android.ttl field as an integer.
        Returns:
        an integer with the value of android.ttl field, or null if absent.
      • title

        public MpnBuilder title​(java.lang.String title)
        Sets the android.notification.title field.
        Parameters:
        title - A string to be used for the android.notification.title field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • title

        public java.lang.String title()
        Gets the value of android.notification.title field.
        Returns:
        the value of android.notification.title field, or null if absent.
      • titleLocKey

        public MpnBuilder titleLocKey​(java.lang.String titleLocKey)
        Sets the android.notification.title_loc_key field.
        Parameters:
        titleLocKey - A string to be used for the android.notification.title_loc_key field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • titleLocKey

        public java.lang.String titleLocKey()
        Gets the value of android.notification.title_loc_key field.
        Returns:
        the value of android.notification.title_loc_key field, or null if absent.
      • titleLocArguments

        public MpnBuilder titleLocArguments​(java.util.List<java.lang.String> titleLocArguments)
        Sets the android.notification.title_loc_args field.
        Parameters:
        titleLocArguments - A list of strings to be used for the android.notification.title_loc_args field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • titleLocArguments

        public java.util.List<java.lang.String> titleLocArguments()
        Gets the value of android.notification.title_loc_args field.
        Returns:
        a list of strings with the value of android.notification.title_loc_args field, or null if absent.
      • body

        public MpnBuilder body​(java.lang.String body)
        Sets the android.notification.body field.
        Parameters:
        body - A string to be used for the android.notification.body field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • body

        public java.lang.String body()
        Gets the value of android.notification.body field.
        Returns:
        the value of android.notification.body field, or null if absent.
      • bodyLocKey

        public MpnBuilder bodyLocKey​(java.lang.String bodyLocKey)
        Sets the android.notification.body_loc_key field.
        Parameters:
        bodyLocKey - A string to be used for the android.notification.body_loc_key field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • bodyLocKey

        public java.lang.String bodyLocKey()
        Gets the value of android.notification.body_loc_key field.
        Returns:
        the value of android.notification.body_loc_key field, or null if absent.
      • bodyLocArguments

        public MpnBuilder bodyLocArguments​(java.util.List<java.lang.String> bodyLocArguments)
        Sets the android.notification.body_loc_args field.
        Parameters:
        bodyLocArguments - A list of strings to be used for the android.notification.body_loc_args field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • bodyLocArguments

        public java.util.List<java.lang.String> bodyLocArguments()
        Gets the value of android.notification.body_loc_args field.
        Returns:
        a list of strings with the value of android.notification.body_loc_args field, or null if absent.
      • icon

        public MpnBuilder icon​(java.lang.String icon)
        Sets the android.notification.icon field.
        Parameters:
        icon - A string to be used for the android.notification.icon field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • icon

        public java.lang.String icon()
        Gets the value of android.notification.icon field.
        Returns:
        the value of android.notification.icon field, or null if absent.
      • sound

        public MpnBuilder sound​(java.lang.String sound)
        Sets the android.notification.sound field.
        Parameters:
        sound - A string to be used for the android.notification.sound field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • sound

        public java.lang.String sound()
        Gets the value of android.notification.sound field.
        Returns:
        the value of android.notification.sound field, or null if absent.
      • tag

        public MpnBuilder tag​(java.lang.String tag)
        Sets the android.notification.tag field.
        Parameters:
        tag - A string to be used for the android.notification.tag field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • tag

        public java.lang.String tag()
        Gets the value of android.notification.tag field.
        Returns:
        the value of android.notification.tag field, or null if absent.
      • color

        public MpnBuilder color​(java.lang.String color)
        Sets the android.notification.color field.
        Parameters:
        color - A string to be used for the android.notification.color field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • color

        public java.lang.String color()
        Gets the value of android.notification.color field.
        Returns:
        the value of android.notification.color field, or null if absent.
      • clickAction

        public MpnBuilder clickAction​(java.lang.String clickAction)
        Sets the android.notification.click_action field.
        Parameters:
        clickAction - A string to be used for the android.notification.click_action field value, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • clickAction

        public java.lang.String clickAction()
        Gets the value of android.notification.click_action field.
        Returns:
        the value of android.notification.click_action field, or null if absent.
      • data

        public MpnBuilder data​(java.util.Map<java.lang.String,​java.lang.String> data)
        Sets sub-fields of the android.data field.
        Parameters:
        data - A map to be used for sub-fields of the android.data field, or null to clear it.
        Returns:
        this MpnBuilder object, for fluent use.
      • data

        public java.util.Map<java.lang.String,​java.lang.String> data()
        Gets sub-fields of the android.data field.
        Returns:
        A map with sub-fields of the android.data field, or null if absent.