<commit_before>/*
 * Copyright 2014-2015 JKOOL, LLC.
 *
 * 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 com.nastel.jkool.tnt4j.core;

import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.codec.binary.Base64;

import com.nastel.jkool.tnt4j.utils.Utils;


/**
 * <p>Implements a Message entity.</p>
 *
 * <p>A <code>Message</code> represents a logical message represented by: mime type, encoding (e.g. base64) and character set see{@code Charset}.
 * Messages are exchanged between a set of software entities (applications). Message has tracking id, size, tag and content with a set of arguments
 * and age. Content is always represented as text and binary data encoded with base64.
 * </p>
 *
 * @see Activity
 * @see Operation
 * @see Trackable
 *
 * @version $Revision: 7 $
 */
public class Message {
	public static final String ENCODING_BASE64 	= "base64";
	public static final String ENCODING_NONE 	= "none";
	public static final String CHARSET_DEFAULT 	= Charset.defaultCharset().displayName();


	public static final String MIME_TYPE_BINARY = "application/octet-stream";
	public static final String MIME_TYPE_TEXT_PLAIN = "text/plain";
	
	private String		signature;
	private int			size;
	private String		strData;
	private Object[]	argList;
	private long		messageAge;
	private String		mimeType = MIME_TYPE_TEXT_PLAIN;
	private String		encoding = ENCODING_NONE;
	private String		charset = CHARSET_DEFAULT;
	private HashSet<String> tags = new HashSet<String>(89);



	/**
	 * Creates a message object with generated, unique signature.
	 *
	 * @throws NullPointerException if any arguments are <code>null</code>
	 */
	public Message() {
		this(Utils.newUUID());
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature) {
		setTrackingId(signature);
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @param msg actual string message associated with this instance
	 * @param args argument list passed along the message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature, String msg, Object...args) {
		setTrackingId(signature);
		setMessage(msg, args);
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @param msg actual byte message associated with this instance
	 * @param args argument list passed along the message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature, byte[] msg, Object...args) {
		setTrackingId(signature);
		setMessage(msg, args);
	}

	/**
	 * Gets message encoding 
	 *
	 * @return message encoding
	 */
	public String getEncoding() {
	    return encoding;
    }

	/**
	 * Sets message encoding e.g. "base64"
	 * 
	 * @param encoding message content encoding type such as "base64" see {@code Message.ENCODING_BASE64}
	 */
	public void setEncoding(String encoding) {
	    this.encoding = encoding;
    }

	/**
	 * Gets message character as defined by {@code Charset}
	 *
	 * @return message encoding
	 */
	public String getCharset() {
	    return charset;
    }

	/**
	 * Sets message character set see {@code Charset}
	 *
	 * @param charset character set of the body of the message see {@code Charset}
	 */
	public void setCharset(String charset) {
	    this.charset = charset;
    }

	/**
	 * Gets message mime type
	 *
	 * @return message encoding
	 */
	public String getMimeType() {
	    return mimeType;
    }

	/**
	 * Sets message mime type
	 * 
	 * @param mimeType mime type of the message (default <code>text/plain</code>)
	 *
	 */
	public void setMimeType(String mimeType) {
	    this.mimeType = mimeType;
    }

	/**
	 * Gets the message signature, which is the unique identifier for the message.
	 *
	 * @return message signature
	 */
	public String getTrackingId() {
		return signature;
	}

	/**
	 * Sets the message tracking signature, which is the unique identifier for the message.
	 * Could be any string that will uniquely identify this message.
	 *
	 * @param signature unique signature identifying message
	 * @throws NullPointerException if signature is <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or is too long
	 */
	public void setTrackingId(String signature) {
		if (signature == null)
			throw new NullPointerException("signature must be a non-empty string");
		if (signature.length() == 0)
			throw new IllegalArgumentException("signature must be a non-empty string");
		this.signature = signature;
	}

	/**
	 * Gets the age of the message that the operation applies to. 
	 * This value represents the time between when the message was sent/created
	 * and time is was consumed.
	 *
	 * @return age of message, in microseconds
	 */
	public long getMessageAge() {
		return messageAge;
	}

	/**
	 * Sets the age of the message in microseconds. Age represents the relative
	 * time that the message was idle. Typically this applies to messages that
	 * are sent or received.
	 *
	 * @param messageAge age of message, in microseconds
	 * @throws IllegalArgumentException if messageAge is negative
	 */
	public void setMessageAge(long messageAge) {
		if (messageAge < 0)
			throw new IllegalArgumentException("messageAge must be non-negative");
		this.messageAge = messageAge;
	}<commit_msg>message signature, tracking id can be null<commit_after>/*
 * Copyright 2014-2015 JKOOL, LLC.
 *
 * 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 com.nastel.jkool.tnt4j.core;

import java.nio.charset.Charset;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.codec.binary.Base64;

import com.nastel.jkool.tnt4j.utils.Utils;


/**
 * <p>Implements a Message entity.</p>
 *
 * <p>A <code>Message</code> represents a logical message represented by: mime type, encoding (e.g. base64) and character set see{@code Charset}.
 * Messages are exchanged between a set of software entities (applications). Message has tracking id, size, tag and content with a set of arguments
 * and age. Content is always represented as text and binary data encoded with base64.
 * </p>
 *
 * @see Activity
 * @see Operation
 * @see Trackable
 *
 * @version $Revision: 7 $
 */
public class Message {
	public static final String ENCODING_BASE64 	= "base64";
	public static final String ENCODING_NONE 	= "none";
	public static final String CHARSET_DEFAULT 	= Charset.defaultCharset().displayName();


	public static final String MIME_TYPE_BINARY = "application/octet-stream";
	public static final String MIME_TYPE_TEXT_PLAIN = "text/plain";
	
	private String		signature;
	private int			size;
	private String		strData;
	private Object[]	argList;
	private long		messageAge;
	private String		mimeType = MIME_TYPE_TEXT_PLAIN;
	private String		encoding = ENCODING_NONE;
	private String		charset = CHARSET_DEFAULT;
	private HashSet<String> tags = new HashSet<String>(89);



	/**
	 * Creates a message object with generated, unique signature.
	 *
	 * @throws NullPointerException if any arguments are <code>null</code>
	 */
	public Message() {
		this(Utils.newUUID());
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature) {
		setTrackingId(signature);
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @param msg actual string message associated with this instance
	 * @param args argument list passed along the message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature, String msg, Object...args) {
		setTrackingId(signature);
		setMessage(msg, args);
	}

	/**
	 * Creates a message object with the specified properties.
	 *
	 * @param signature unique signature identifying message
	 * @param msg actual byte message associated with this instance
	 * @param args argument list passed along the message
	 * @throws NullPointerException if any arguments are <code>null</code>
	 * @throws IllegalArgumentException if signature is empty or too long
	 */
	public Message(String signature, byte[] msg, Object...args) {
		setTrackingId(signature);
		setMessage(msg, args);
	}

	/**
	 * Gets message encoding 
	 *
	 * @return message encoding
	 */
	public String getEncoding() {
	    return encoding;
    }

	/**
	 * Sets message encoding e.g. "base64"
	 * 
	 * @param encoding message content encoding type such as "base64" see {@code Message.ENCODING_BASE64}
	 */
	public void setEncoding(String encoding) {
	    this.encoding = encoding;
    }

	/**
	 * Gets message character as defined by {@code Charset}
	 *
	 * @return message encoding
	 */
	public String getCharset() {
	    return charset;
    }

	/**
	 * Sets message character set see {@code Charset}
	 *
	 * @param charset character set of the body of the message see {@code Charset}
	 */
	public void setCharset(String charset) {
	    this.charset = charset;
    }

	/**
	 * Gets message mime type
	 *
	 * @return message encoding
	 */
	public String getMimeType() {
	    return mimeType;
    }

	/**
	 * Sets message mime type
	 * 
	 * @param mimeType mime type of the message (default <code>text/plain</code>)
	 *
	 */
	public void setMimeType(String mimeType) {
	    this.mimeType = mimeType;
    }

	/**
	 * Gets the message signature, which is the unique identifier for the message.
	 *
	 * @return message signature
	 */
	public String getTrackingId() {
		return signature;
	}

	/**
	 * Sets the message tracking signature, which is the unique identifier for the message.
	 * Could be any string that will uniquely identify this message.
	 *
	 * @param signature unique signature identifying message
	 */
	public void setTrackingId(String signature) {
		this.signature = signature;
	}

	/**
	 * Gets the age of the message that the operation applies to. 
	 * This value represents the time between when the message was sent/created
	 * and time is was consumed.
	 *
	 * @return age of message, in microseconds
	 */
	public long getMessageAge() {
		return messageAge;
	}

	/**
	 * Sets the age of the message in microseconds. Age represents the relative
	 * time that the message was idle. Typically this applies to messages that
	 * are sent or received.
	 *
	 * @param messageAge age of message, in microseconds
	 * @throws IllegalArgumentException if messageAge is negative
	 */
	public void setMessageAge(long messageAge) {
		if (messageAge < 0)
			throw new IllegalArgumentException("messageAge must be non-negative");
		this.messageAge = messageAge;
	}
{'fraction_non_alphanumeric': 0.08692493946731235, 'fraction_numerical': 0.005569007263922518, 'mean_word_length': 3.734810852120749, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6805948', 'n_tokens_mistral': 3642, 'n_tokens_neox': 3305, 'n_words': 1346}