code: private Set<LineString> getSegments(Collection<LineString> lines) {
          Set<LineString> set = new HashSet<>();
          for (LineString line : lines) {
              Coordinate[] cc = line.getCoordinates();
              for (int i = 1; i < cc.length; i++) {
                  if (!cc[i - 1].equals(cc[i])) {
                      LineString segment = line.getFactory().createLineString(
                              new Coordinate[]{new Coordinate(cc[i - 1]), new Coordinate(cc[i])});
                      set.add(segment);
                  }
              }
          }
          return set;
      }
docs: Return a set of segments from a linestring
  
  @param lines
  @return