import java.util.Comparator;

/**
 * A type for objects that have an area and a perimeter. An example of this is
 * a plane figure, such as a {@link Circle} or {@link Rectangle}.
 * <p>
 * This version has been modified to add some static methods and constants.
 *
 * @author Mark Young (A00000000)
 */
public interface Measurable {

    /**
     * The area of the Measurable object. That is, the amount of space it 
     * covers on the plane.
     */
    public double getArea();

    /**
     * The perimeter of the Measurable object. That is, the total distance
     * around its edge.
     */
    public double getPerimeter();

    /**
     * How round this object is. A circle is perfectly round (1.0), while a
     * square is only moderately round (0.8), while a long, thin rectangle
     * may have a roundness close to zero.
     *
     * @param m the object whose roundness is to be calculated
     * @return the roundness of {@code m} as a number in the range [0,1]
     */
    public static double roundness(Measurable m) {
        return 4 * Math.PI * m.getArea() / Math.pow(m.getPerimeter(), 2);
    }

    /**
     * A {link java.util.Comparator Comparator} to allow sorting by area.
     */
    public static final Comparator<Measurable> BY_AREA =
            (a, b) -> Double.compare(a.getArea(), b.getArea());

    /**
     * A {link java.util.Comparator Comparator} to allow sorting by perimeter.
     */
    public static final Comparator<Measurable> BY_PERIMETER =
            (a, b) -> Double.compare(a.getPerimeter(), b.getPerimeter());

}

