GeometryConvert { public static MultiLineString toSegmentsMultiLineString(Geometry geometry) { Set<LineString> result = toSegmentsLineString(geometry); if (result != null) { return FACTORY.createMultiLineString(result.toArray(new LineString[result.size()])); } return null; } private  GeometryConvert(); static MultiPoint toMultiPoint(Geometry geometry); static Set<LineString> toSegmentsLineString(Geometry geometry); static MultiLineString toSegmentsMultiLineString(Geometry geometry); static Geometry toGeometry(Envelope envelope, GeometryFactory factory); static Geometry toGeometry(Envelope envelope);  }
@Test public void testToSegmentsMultiLineString() throws Exception { Geometry geom = wKTReader.read("LINESTRING(0 8, 1 8 , 3 8, 8 8, 10 8, 20 8)"); MultiLineString result = GeometryConvert.toSegmentsMultiLineString(geom); assertEquals(result.getNumGeometries(), 5); geom = wKTReader.read("LINEARRING(0 8, 1 8 , 3 8, 8 8, 10 8, 20 8, 0 8)"); result = GeometryConvert.toSegmentsMultiLineString(geom); assertEquals(result.getNumGeometries(), 6); geom = wKTReader.read("LINEARRING(0 8, 1 8 ,1 8, 3 8, 8 8, 10 8, 10 8, 20 8, 0 8)"); result = GeometryConvert.toSegmentsMultiLineString(geom); assertEquals(result.getNumGeometries(), 6); geom = wKTReader.read("POINT(0 8)"); result = GeometryConvert.toSegmentsMultiLineString(geom); assertNull(result); geom = wKTReader.read("MULTIPOINT((0 8), (1 8))"); result = GeometryConvert.toSegmentsMultiLineString(geom); assertNull(result); }