1: import java.util.Comparator;
3: /**
4: * A very simple interface to experiment with -- representing a closed planar
5: * shape.
6: *
7: * @see Circle.java
8: * @see Rectangle.java
9: * @see MeasuringStuff.java
10: *
11: * @author Mark Young (A00000000)
12: */
13: public interface Measurable {
15: /**
16: * Get this object's area.
17: *
18: * @return this object's area
19: */
20: public double getArea();
22: /**
23: * Get this object's perimeter.
24: *
25: * @return this object's perimeter
26: */
27: public double getPerimeter();
29: /**
30: * Calculate this object's roundness. The range of values returned is from
31: * zero to one. Circles are perfectly round (1.0), while lines are not
32: * round at all (0.0). Squares are moderately round (Π / 4 ≈
33: * 0.785).
34: *
35: * @return how round this object is
36: */
37: public default double getRoundness() {
38: return 4.0 * Math.PI * getArea() / Math.pow(getPerimeter(), 2);
39: }
41: /**
42: * Compare objects by their areas.
43: */
44: public static final Comparator<Measurable> BY_AREA = (one, other)
45: -> Double.compare(one.getArea(), other.getArea());
47: /**
48: * Compare objects by their perimetera.
49: */
50: public static final Comparator<Measurable> BY_PERIMETER = (one, other)
51: -> Double.compare(one.getPerimeter(), other.getPerimeter());
53: }