public class Network { private Set points = new HashSet<>(); private Set links = new HashSet<>(); public Network(Point... points) { for (Point p : points) { this.points.add(p); } } public Set points() { return Collections.unmodifiableSet(points); } public void addLink(Point p1, Point p2) { links.add(new Link(p1, p2)); } public Set links() { return Collections.unmodifiableSet(links); } // Returns the link betweeen the points p1 and p2 if it exists, // null otherwise. public Link link(Point p1, Point p2) { for (Link l : links) if ((l.p1().equals(p1) && l.p2().equals(p2)) || (l.p2().equals(p1) && l.p1().equals(p2))) return l; return null; } }