A 2-D point.
| 5 | |
| 6 | /** A 2-D point. */ |
| 7 | public record Point(int x, int y) implements Comparable<Point>, Shape { |
| 8 | public static final Point ORIGIN = new Point(0, 0); |
| 9 | private static int created; |
| 10 | |
| 11 | public Point { |
| 12 | if (x < 0) throw new IllegalArgumentException("x"); |
| 13 | created++; |
| 14 | } |
| 15 | |
| 16 | public Point(int v) { this(v, v); } |
| 17 | |
| 18 | /** Explicit accessor — no implicit one is minted. */ |
| 19 | public int x() { return x; } |
| 20 | |
| 21 | public double norm() { return Math.sqrt(x * x + y * y); } |
| 22 | |
| 23 | @Override |
| 24 | public int compareTo(Point o) { return Double.compare(norm(), o.norm()); } |
| 25 | |
| 26 | record Inner(String name, List<String> tags) { |
| 27 | String first() { return tags.get(0); } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | record Pair<A, B>(A first, B second) { |
| 32 | A left() { return first; } |
nothing calls this directly
no outgoing calls
no test coverage detected