package common.tags;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

class TagChar extends Tag {
	private char data;

	TagChar() {
	}

	public TagChar(char data) {
		this.data = data;
	}

	void write(DataOutput output) throws IOException {
		output.writeChar(this.data);
	}

	void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
		tracker.read(10);
		this.data = input.readChar();
	}

	TagType getType() {
		return TagType.CHAR;
	}

	public String toString() {
		return String.format(Character.isLetterOrDigit(this.data) ? "'%c'" : (this.data >= 256 ? "'\\u%04x'" : "'\\x%02x'"), this.data);
	}

	public Tag copy() {
		return new TagChar(this.data);
	}

	public boolean equals(Object other) {
		return super.equals(other) && this.data == ((TagChar)other).data;
	}

	public int hashCode() {
		return super.hashCode() ^ this.data;
	}

	public char getChar() {
		return this.data;
	}
}
