import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * A program to test out the extensions to the Measurable interface. 
 *
 * @see MeasuringStuff
 *
 * @author Mark Young (A00000000)
 */
public class MoreMeasures {

    public static void main(String[] args) {
        // create the shapes
        Circle c1 = new Circle(10.0);
        Circle c2 = new Circle(24.7);
        Rectangle r1 = new Rectangle(10.0, 20.0);
        Rectangle r2 = new Rectangle(0.4, 1000.0);
        RegularPolygon rp = new RegularPolygon(6, 9.0);

        // make a list of the shapes
        List<Measurable> shapes = new ArrayList<>();
        shapes.addAll(Arrays.asList(c1, c2, r1, r2, rp));

        // announce your intentions
        System.out.println();
        System.out.println("Sorting a list of shapes in various ways!");
        System.out.println();

        // sort by area
        shapes.sort(Measurable.BY_AREA);
        System.out.println("Sorted by area:");
        shapes.forEach(s -> 
                System.out.printf("%30s: %8.1f%n", 
                        s.toString(), s.getArea()));
        System.out.println();

        // sort by perimeter
        shapes.sort(Measurable.BY_PERIMETER);
        System.out.println("Sorted by perimeter:");
        shapes.forEach(s -> 
                System.out.printf("%30s: %8.1f%n", 
                        s.toString(), s.getPerimeter()));
        System.out.println();

        // sort by roundness
        shapes.sort((one, other) 
                -> Double.compare(one.getRoundness(), other.getRoundness()));
        System.out.println("Sorted by roundness:");
        shapes.forEach(s -> 
                System.out.printf("%30s: %8.3f%n", 
                        s.toString(), s.getRoundness()));
        System.out.println();
    }

}

