package common.tags;

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

class TagIntArray extends Tag {
	private int[] data;

	TagIntArray() {
	}

	public TagIntArray(int[] data) {
		this.data = data;
	}

	void write(DataOutput output) throws IOException {
		output.writeInt(this.data.length);
		for(int z = 0; z < this.data.length; z++) {
			output.writeInt(this.data[z]);
		}
	}

	void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
		tracker.read(24);
		int len = input.readInt();
		tracker.read(4 * len);
		this.data = new int[len];
		for(int z = 0; z < len; z++) {
			this.data[z] = input.readInt();
		}
	}

	TagType getType() {
		return TagType.INT_ARRAY;
	}

	public String toString() {
		StringBuilder sb = new StringBuilder("[");
		for(int z = 0; z < this.data.length; z++) {
			if(z != 0)
				sb.append(',');
			sb.append(this.data[z]);
		}
		return sb.append("]").toString();
	}

	public Tag copy() {
		int[] data = new int[this.data.length];
		System.arraycopy(this.data, 0, data, 0, this.data.length);
		return new TagIntArray(data);
	}

	public boolean equals(Object other) {
		return super.equals(other) && Arrays.equals(this.data, ((TagIntArray)other).data);
	}

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

	public int[] getIntArray() {
		return this.data;
	}
}
