Problem Statement  
Consider the figures made up of line segments below. There are 5 connected figures, but only 3 distinct figures if one considers their topological features (the first and second are equivalent, as are the third and fourth). Two figures are considered to be topological equivalent if one of the figures can be deformed by stretching, bending, etc. into the other (but not necessarily in 2D space). A more formal definition can be expressed in terms of graph theory. A figure can be considered to be an embedding of a multigraph (it may have loops and multiple edges) in the plane, where each vertex has been assigned to a distinct point, and each edge to some polygonal path without selfintersections. We consider two figures to be equivalent if their embeddings could have both originated from the same multigraph. In this problem, we will assume that each edge is disjointly embedded. That is, two embedded edges can only meet at a common endpoint. Create a class TopologicalEquivalence containing the method countDistinct which takes a set of nonintersecting and nonoverlapping line segments and counts the number of distinct connected figures (according to the definition of topological equivalence above). The line segments will be given in a String[] lineSegs, where each element may contain several line segments. A line segment will be given in the form (quotes for clarity) "x1,y1x2,y2" and within each element they will be single space separated. Two line segments are connected if they share a common endpoint. A figure is a minimal nonempty subset of the line segments such that no line segment in the figure is connected to a line segment not in the figure.  
Definition  
 
Constraints  
  The line segments making up a figure will have at most 8 distinct end points.  
  lineSegs will contain between 1 and 50 elements, inclusive.  
  Each element in lineSegs will contain between 7 and 50 characters, inclusive.  
  Each element in lineSegs will be a spaceseparated list of line segments specified in the format above. There will be no leading, trailing, or consecutive spaces.  
  The coordinates for each line segment will be integers between 0 and 1000, inclusive, with no extra leading zeros.  
  No two line segments will partially overlap or intersect, except at the endpoints.  
  All line segments will have a positive length.  
Examples  
0)  
 
1)  
 
2)  
