// Arup Guha
// 7/13/2015
// Written in SI@UCF Java GUI class to illustrate use of 
// Arrays.sort of objects.

import java.util.*;

public class point implements Comparable<point> {

	private int x;
	private int y;

	public point(int myx, int myy) {
		x = myx;
		y = myy;
	}

	public int compareTo(point other) {
		if (this.x != other.x)
			return this.x - other.x;
		return this.y - other.y;
	}

	public String toString() {
		return "("+x+","+y+")";
	}

/*   This is a main utilizing an array of points.

	public static void main(String[] args) {

		Random r = new Random();
		point[] myPts = new point[10];
		for (int i=0; i<10; i++) {
			myPts[i] = new point(r.nextInt(50), r.nextInt(50));
			System.out.print(myPts[i]+" ");
		}
		System.out.println();
		Arrays.sort(myPts);
		for (int i=0; i<10; i++)
			System.out.print(myPts[i]+" ");
		System.out.println();

		Arrays.sort(myPts, new Comparator<point>(){
			public int compare(point a, point b) {
				if (a.y != b.y) return a.y - b.y;
				return a.x - b.x;
			}});

		for (int i=0; i<10; i++)
			System.out.print(myPts[i]+" ");
		System.out.println();
	}
*/

     // This main utilizes an ArrayList of points.
	public static void main(String[] args) {

		Random r = new Random();
		ArrayList<point> myPts = new ArrayList<point>();
		for (int i=0; i<10; i++) {
			myPts.add(new point(r.nextInt(50), r.nextInt(50)));
			System.out.print(myPts.get(i)+" ");
		}
		System.out.println();

           // Natural sort, using comparator in class.
		Collections.sort(myPts);
		for (int i=0; i<10; i++)
			System.out.print(myPts.get(i)+" ");
		System.out.println();

           // Inline definition of alternative comparator.
		Collections.sort(myPts, new Comparator<point>(){
			public int compare(point a, point b) {
				if (a.y != b.y) return a.y - b.y;
				return a.x - b.x;
			}});

		for (int i=0; i<10; i++)
			System.out.print(myPts.get(i)+" ");
		System.out.println();

           // Also tested shuffle here.
		Collections.reverse(myPts);

		for (int i=0; i<10; i++)
			System.out.print(myPts.get(i)+" ");
		System.out.println();

	}
}