import java.util.Arrays;
import java.util.List;
public class SocketPackage {

	private String name = "";
	private String data = "";

	public SocketPackage(String name, String data) {
		this.setName(name);
		this.setData(data);
	}
	public SocketPackage() {
		this("","");
	}
	public SocketPackage(String message) {
		if (message.length() <= 0) {
			throw new IllegalArgumentException("Socket message cannot be empty.");
		}
		String[] components = message.split(" ");
		this.setName(components[0]);
		if (components.length > 1) {
			this.setData(message.substring(components[0].length() + 1));
		} else {
			this.setData("");
		}
	}

	public void setName(String name) {
		if (name == null) name = "";
		this.name = name.toUpperCase();
	}

	public void setData(String data) {
		if (data == null) data = "";
		this.data = data;
	}

	public String getName() {
		return this.name;
	}

	public String getData() {
		return this.data;
	}

	public String toString() {
		if (this.data == null || this.data.length() == 0) {
			return this.name;
		} else {
			return this.name + " " + this.data;
		}
	}

	public List<String> splitData() {
		return Arrays.asList(this.data.split(" "));
	}
}
