Skip to content
Snippets Groups Projects
Pair.java 972 B
Newer Older
Siyu Lin's avatar
Siyu Lin committed
package edu.iastate.cs228.hw2;

public class  Pair<E extends Comparable, T extends Comparable> implements Comparable<Pair<E, T>> {

	private E first;
	private T second;
	
	public Pair(E first, T second){
		this.first = first;
		this.second = second;
	}
	
	@Override
	public int compareTo(Pair<E, T> other) {
		if(this.getFirst().compareTo(other.getFirst()) > 0){
			return 1;
		}
		else if(this.getFirst().compareTo(other.getFirst()) < 0){
			return -1;
		}
		else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) == 0){
			return 0;
		}
		else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) > 0){
			return 1;
		}
		else if(this.getFirst().compareTo(other.getFirst()) == 0 && this.getSecond().compareTo(other.getSecond()) < 0){
			return -1;
		}
		else{
			return 0;
		}
	}
	
	public E getFirst(){
		return first;
	}
	
	public T getSecond(){
		return second;
	}

}