code: public static void addGeometryToSegments(Geometry geometry, int flag, ArrayList<SegmentString> segments) {
          for (int i = 0; i < geometry.getNumGeometries(); i++) {
              Geometry component = geometry.getGeometryN(i);
              if (component instanceof Polygon) {
                  add((Polygon) component, flag, segments);
              } else if (component instanceof LineString) {
                  add((LineString) component, flag, segments);
              }
          }
      }
docs: Convert the a geometry as a list of segments and mark it with a flag
  @param geometry
  @param flag
  @param segments