// Sorting an array of pizzas by size
import java.util.*;			//needed to get the Arrays class

enum Size {small, medium, large, gazza};
enum Topping {cheese, tomato, tuna, beans, pepperoni, 
				olives, goats_cheese, rocket, salmon, 
				chillies, walnuts, poached_egg, ham, 
				anchovy};

public class Pizza2 implements Comparable {
	private Size size;
	private Topping[] toppings;

	public Pizza2(Size s, Topping... t) {
		size = s;
		toppings = t;
	}
	
	public int compareTo(Object o) {		//required by Comparable
		Pizza2 p = (Pizza2)o;				//cast Object to Pizza2 (messy)
		return size.compareTo(p.size);		//enums are Comparable
	}
	
	public void printPizza() {
		System.out.print("My " + size.toString() + " pizza has");
		for (Topping t : toppings) {
			System.out.print(" " + t.toString());
		}
		System.out.println();
	}				
	
	public static void main(String[] args) {
		Pizza2[] myPizzas = new Pizza2[5];
		
		myPizzas[0] = new Pizza2(Size.small, 
									Topping.cheese, 
									Topping.tomato);
		myPizzas[1] = new Pizza2(Size.gazza, Topping.cheese, 
							Topping.tomato, Topping.beans, 
							Topping.chillies, Topping.ham,
							Topping.olives, Topping.anchovy);
		myPizzas[2] = new Pizza2(Size.medium, 
									Topping.cheese, 
									Topping.tomato,
									Topping.ham);
		myPizzas[3] = new Pizza2(Size.large, Topping.cheese, 
							Topping.tomato, 
							Topping.chillies,
							Topping.olives, 
							Topping.anchovy);
		myPizzas[4] = new Pizza2(Size.gazza, Topping.cheese, 
							Topping.tomato, Topping.beans, 
							Topping.olives, Topping.anchovy);
							
		System.out.println("unsorted:");					
		for (Pizza2 p : myPizzas) {
			p.printPizza();
		}
		Arrays.sort(myPizzas);			//do the sort
		System.out.println("sorted:");					
		for (Pizza2 p : myPizzas) {
			p.printPizza();
		}							
	}	
}