public static Iterable<OGCGeometry> flattenCollection(OGCGeometry geometry)
    {
        if (geometry == null) {
            return ImmutableList.of();
        }
        if (!(geometry instanceof OGCConcreteGeometryCollection)) {
            return ImmutableList.of(geometry);
        }
        if (((OGCConcreteGeometryCollection) geometry).numGeometries() == 0) {
            return ImmutableList.of();
        }
        return () -> new GeometryCollectionIterator(geometry);
    }
@Test
    public void testFlattenCollection()
    {
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("POINT EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("POINT (1 2)"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOINT EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOINT (1 2)"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOINT (1 2, 3 4)"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("LINESTRING EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("LINESTRING (1 2, 3 4)"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTILINESTRING EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTILINESTRING ((1 2, 3 4))"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("POLYGON EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("POLYGON ((0 0, 0 1, 1 1, 0 0))"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOLYGON EMPTY"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOLYGON (((0 0, 0 1, 1 1, 0 0)))"));
        assertFlattenLeavesUnchanged(OGCGeometry.fromText("MULTIPOLYGON (((0 0, 0 1, 1 1, 0 0)), ((10 10, 10 11, 11 11, 10 10)))"));

        assertFlattens(OGCGeometry.fromText("GEOMETRYCOLLECTION EMPTY"), ImmutableList.of());
        assertFlattens(OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT EMPTY)"), OGCGeometry.fromText("POINT EMPTY"));
        assertFlattens(OGCGeometry.fromText("GEOMETRYCOLLECTION (POINT (0 1))"), OGCGeometry.fromText("POINT (0 1)"));
        assertFlattens(OGCGeometry.fromText("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION EMPTY)"), ImmutableList.of());
        assertFlattens(
                OGCGeometry.fromText("GEOMETRYCOLLECTION (GEOMETRYCOLLECTION (POINT (0 1), POINT (1 2)))"),
                ImmutableList.of(OGCGeometry.fromText("POINT (0 1)"), OGCGeometry.fromText("POINT (1 2)")));
    }