package cokr.xit.fims.stat;

import java.util.Objects;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class CompositeKey {
	private String level1;
	private String level2;
	private String level3;
	private String level4;

	public String[] toArray() {

		if(this.level2 == null) {
			return new String[] { this.level1 };
		}
		if(this.level3 == null) {
			return new String[] { this.level1, this.level2 };
		}
		if(this.level4 == null) {
			return new String[] { this.level1, this.level2, this.level3 };
		}

		return new String[] { this.level1, this.level2, this.level3, this.level4 };
	}

	@Override
	public boolean equals(Object o) {
		if(this == o) return true;
		if(o == null || getClass() != o.getClass()) return false;
		CompositeKey k = (CompositeKey) o;

		return Objects.equals(level1, k.level1)
				&& Objects.equals(level2, k.level2)
				&& Objects.equals(level3, k.level3)
				&& Objects.equals(level4, k.level4);
	}

	@Override
	public int hashCode() {
		return Objects.hash(level1,level2,level3,level4);
	}
}
