package lab5;

public class Pair <First, Second> implements Comparable{
	/*properties*/
	private final First _first;
	private final Second _second;

	/*constructor*/
	public Pair(final First first, final Second second){
		_first = first;
		_second = second;
	}

	/*getter*/
	public First getFirst(){
		return _first;
	}

	public Second getSecond(){
		return _second;
	}

	public int compareTo(Object arg0) {
		if(!(arg0 instanceof Pair))
			throw new ClassCastException();
		if(!(_second instanceof Comparable))
			throw new ClassCastException();
		return ((Comparable) _second).compareTo(((Pair)arg0).getSecond());
	}

	public String toString(){
		return _first.toString() + " : " + _second.toString();
	}

	public boolean equals(Pair o){
		return o.getFirst() == getFirst() && o.getSecond() == getSecond();
	}

	public Object clone(){
		return this;
	}

	public int hashCode(){
		return 134 + _first.hashCode() * 17 + _second.hashCode();
	}
}
