code: public static Geometry lineMerge(Geometry geom, GeometryFactory factory) {
          LineMerger merger = new LineMerger();
          merger.add(geom);
          Collection lines = merger.getMergedLineStrings();
          return factory.buildGeometry(lines);
      }
docs: A method to merge a geometry to a set of linestring
  @param geom
  @param factory
  @return