<commit_before>/**
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.aerogear.unifiedpush.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * an UnifiedMessage represents a message in the format expected from the Unified Push Server
 * The message format is very simple: A generic JSON map is used to sent messages to Android and iOS devices.
 * The applications on the devices will receive the JSON map and are responsible for performing a lookup to read values of the given keys.
 * @see <a href="http://www.aerogear.org/docs/specs/aerogear-push-messages/">http://www.aerogear.org/docs/specs/aerogear-push-messages/</a>
 */
public class UnifiedMessage {

    private String pushApplicationId;

    private String masterSecret;

    private List<String> aliases;

    private Map<String, Object> attributes;

    private String category;

    private List<String> deviceType;

    /**
     * A builder to provide a Fluid API
     */
    public static class Builder {

        private String pushApplicationId;

        private String masterSecret;

        private String category;

        private List<String> deviceType = new ArrayList<String>();

        private List<String> aliases = new ArrayList<String>();

        private Map<String, Object> attributes = new HashMap<String, Object>();

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

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

        public Builder aliases(List<String> aliases) {
            this.aliases = aliases;
            return this;
        }

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

        public Builder deviceType(List<String> deviceType) {
            this.deviceType = deviceType;
            return this;
        }

        public Builder attributes(Map<String, Object> attributes) {
            this.attributes = attributes;
            return this;
        }

        public Builder attribute(String key, String value) {
            this.attributes.put(key,value);
            return this;
        }

        public Builder alert(String message) {
            this.attributes.put("alert",message);
            return this;
        }

        public Builder sound(String sound) {
            this.attributes.put("sound",sound);
            return this;
        }

        public UnifiedMessage build() {
            return new UnifiedMessage(this);
        }


    }

    /**
     * private constructor as UnifiedMessage can only be created through the Builder
     * @param builder
     */
    private UnifiedMessage(Builder builder) {
        this.attributes  = builder.attributes;
        this.aliases = builder.aliases;
        this.category = builder.category;
        this.deviceType = builder.deviceType;
        this.pushApplicationId = builder.pushApplicationId;
        this.masterSecret = builder.masterSecret;
    }

    public String getPushApplicationId() {
        return pushApplicationId;
    }

    public void setPushApplicationId(String pushApplicationId) {
        this.pushApplicationId = pushApplicationId;
    }

    public String getMasterSecret() {
        return masterSecret;
    }

    public void setMasterSecret(String masterSecret) {
        this.masterSecret = masterSecret;
    }

    public List<String> getAliases() {
        return aliases;
    }

    public void setAliases(List<String> aliases) {
        this.aliases = aliases;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }
<commit_msg>more JavaDoc<commit_after>/**
 * JBoss, Home of Professional Open Source
 * Copyright Red Hat, Inc., and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jboss.aerogear.unifiedpush.message;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * an UnifiedMessage represents a message in the format expected from the Unified Push Server
 * The message format is very simple: A generic JSON map is used to sent messages to Android and iOS devices.
 * The applications on the devices will receive the JSON map and are responsible for performing a lookup to read values of the given keys.
 * @see <a href="http://www.aerogear.org/docs/specs/aerogear-push-messages/">http://www.aerogear.org/docs/specs/aerogear-push-messages/</a>
 *
 * To construct a message use the {@link org.jboss.aerogear.unifiedpush.message.Builder} like this :
 * <pre>
 * {@code
 * // For a broadcast messages
 * UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
 *       .pushApplicationId("c7fc6525-5506-4ca9-9cf1-55cc261ddb9c")
 *       .masterSecret("8b2f43a9-23c8-44fe-bee9-d6b0af9e316b")
 *       .alert("Hello")
 *       .sound("default")
 *       .badge("welcome")
 *       .build();
 * // For selective messages
 *  List<String> aliases = new ArrayList<String>();
 *  aliases.add("mike");
 *  UnifiedMessage unifiedMessage = new UnifiedMessage.Builder()
 *       .pushApplicationId("c7fc6525-5506-4ca9-9cf1-55cc261ddb9c")
 *       .masterSecret("8b2f43a9-23c8-44fe-bee9-d6b0af9e316b")
 *       .alert("Hello")
 *       .sound("default")
 *       .aliases(aliases)
 *       .deviceType("iPad","AndroidTablet")
 *       .build();
 * </pre>
 * }
 *
 * */
public class UnifiedMessage {

    private String pushApplicationId;

    private String masterSecret;

    private List<String> aliases;

    private Map<String, Object> attributes;

    private String category;

    private List<String> deviceType;

    /**
     * A builder to provide a Fluid API
     */
    public static class Builder {

        private String pushApplicationId;

        private String masterSecret;

        private String category;

        private List<String> deviceType = new ArrayList<String>();

        private List<String> aliases = new ArrayList<String>();

        private Map<String, Object> attributes = new HashMap<String, Object>();

        /**
         * This is a mandatory field
         * @param pushApplicationId
         * @return
         */
        public Builder pushApplicationId(String pushApplicationId) {
            this.pushApplicationId = pushApplicationId;
            return this;
        }

        /**
         * This is a mandatory field
         * @param masterSecret
         * @return
         */
        public Builder masterSecret(String masterSecret) {
            this.masterSecret = masterSecret;
            return this;
        }

        /**
         * Sets a list of "identifiers", like username or email address.
         * @param aliases
         * @return
         */
        public Builder aliases(List<String> aliases) {
            this.aliases = aliases;
            return this;
        }

        /**
         * A category is a semantical tag.
         * @param category
         * @return
         */
        public Builder category(String category) {
            this.category = category;
            return this;
        }

        /**
         * A filter for notifying only users running a certain device
         * @param deviceType
         * @return
         */
        public Builder deviceType(List<String> deviceType) {
            this.deviceType = deviceType;
            return this;
        }

        /**
         * A map of attributes containing business specific values
         * @param attributes
         * @return
         */
        public Builder attributes(Map<String, Object> attributes) {
            this.attributes = attributes;
            return this;
        }

        /**
         * An attribute containing a business value
         * @param key
         * @param value
         * @return
         */
        public Builder attribute(String key, String value) {
            this.attributes.put(key,value);
            return this;
        }

        /**
         * Triggers a dialog, displaying the value - no iOS API needs to be invoked by the app developer
         * @param message
         * @return
         */
        public Builder alert(String message) {
            this.attributes.put("alert",message);
            return this;
        }

        /**
         * Plays a given sound - no iOS API needs to be invoked by the app developer
         * @param sound
         * @return
         */
        public Builder sound(String sound) {
            this.attributes.put("sound",sound);
            return this;
        }

        /**
         * Sets the value of the badge icon - no iOS API needs to be invoked by the app developer
         * @param badge
         * @return
         */
        public Builder badge(String badge) {
            this.attributes.put("badge",badge);
            return this;
        }

        /**
         * Needed when broadcasting a message to a SimplePush Network
         * Note: Do not use this method for a "selective send"
         * @param version
         * @return
         */
        public Builder simplePush(String version) {
            this.attributes.put("simple-push",version);
            return this;
        }

        /**
         * Needed when doing a selective send to a SimplePush Network
         * Note: Do not use this method for a "broadcast send"
         * @param channels
         * @return
         */
        public Builder simplePush(Map channels) {
            this.attributes.put("simple-push",channels);
            return this;
        }

        public UnifiedMessage build() {
            return new UnifiedMessage(this);
        }


    }

    /**
     * private constructor as UnifiedMessage can only be created through the Builder
     * @param builder
     */
    private UnifiedMessage(Builder builder) {
        this.attributes  = builder.attributes;
        this.aliases = builder.aliases;
        this.category = builder.category;
        this.deviceType = builder.deviceType;
        this.pushApplicationId = builder.pushApplicationId;
        this.masterSecret = builder.masterSecret;
    }


    public String getPushApplicationId() {
        return pushApplicationId;
    }

    public void setPushApplicationId(String pushApplicationId) {
        this.pushApplicationId = pushApplicationId;
    }

    public String getMasterSecret() {
        return masterSecret;
    }

    public void setMasterSecret(String masterSecret) {
        this.masterSecret = masterSecret;
    }

    public List<String> getAliases() {
        return aliases;
    }

    public void setAliases(List<String> aliases) {
        this.aliases = aliases;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }

{'fraction_non_alphanumeric': 0.08513828723758747, 'fraction_numerical': 0.006664445184938354, 'mean_word_length': 2.2073203312850653, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1892320', 'n_tokens_mistral': 3153, 'n_tokens_neox': 3041, 'n_words': 979}