All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.filosganga.geogson.jts.JtsPolygonIterable Maven / Gradle / Ivy

There is a newer version: 1.4.31
Show newest version
package com.github.filosganga.geogson.jts;

import com.google.common.collect.UnmodifiableIterator;
import com.vividsolutions.jts.geom.MultiPolygon;
import com.vividsolutions.jts.geom.Polygon;

/**
 * @author Filippo De Luca - [email protected]
 */
class JtsPolygonIterable implements Iterable {

    private final PolygonProvider src;

    private JtsPolygonIterable(PolygonProvider src) {
        this.src = src;
    }

    public static JtsPolygonIterable of(final MultiPolygon src) {
        return new JtsPolygonIterable(new PolygonProvider() {
            @Override
            public int getNumPolygons() {
                return src.getNumGeometries();
            }

            @Override
            public Polygon getPolygonN(int n) {
                return (Polygon) src.getGeometryN(n);
            }
        });
    }


    @Override
    public UnmodifiableIterator iterator() {
        return new Iterator(src);
    }

    private static class Iterator extends UnmodifiableIterator {

        private final PolygonProvider src;

        private int index = 0;

        private Iterator(PolygonProvider src) {
            this.src = src;
        }

        @Override
        public boolean hasNext() {
            return src.getNumPolygons() > index;
        }

        @Override
        public Polygon next() {
            return src.getPolygonN(index++);

        }

    }

    private interface PolygonProvider {

        int getNumPolygons();

        Polygon getPolygonN(int n);

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy