Example usage for org.apache.commons.collections4.iterators IteratorChain hasNext

List of usage examples for org.apache.commons.collections4.iterators IteratorChain hasNext

Introduction

In this page you can find the example usage for org.apache.commons.collections4.iterators IteratorChain hasNext.

Prototype

public boolean hasNext() 

Source Link

Document

Return true if any Iterator in the IteratorChain has a remaining element.

Usage

From source file:org.apache.jena.geosparql.spatial.property_functions.GenericSpatialPropertyFunction.java

private boolean checkBound(ExecutionContext execCxt, Node subject) {

    try {/*from   w  ww.jav a 2  s. co  m*/
        Graph graph = execCxt.getActiveGraph();

        IteratorChain<Triple> spatialTriples = new IteratorChain<>();

        //Check for Geometry and so GeometryLiterals.
        if (graph.contains(subject, Geo.HAS_GEOMETRY_NODE, null)) {
            //A Feature can have many geometries so add each of them. The check Geo.HAS_DEFAULT_GEOMETRY_NODE will only return one but requires the data to have these present.
            Iterator<Triple> geometryTriples = graph.find(subject, Geo.HAS_GEOMETRY_NODE, null);
            while (geometryTriples.hasNext()) {
                Node geometry = geometryTriples.next().getObject();
                spatialTriples.addIterator(graph.find(geometry, Geo.HAS_SERIALIZATION_NODE, null));
            }
        } else {
            //Check for Geo predicates against the feature when no geometry literals found.
            if (graph.contains(subject, SpatialExtension.GEO_LAT_NODE, null)
                    && graph.contains(subject, SpatialExtension.GEO_LON_NODE, null)) {
                Node lat = graph.find(subject, SpatialExtension.GEO_LAT_NODE, null).next().getObject();
                Node lon = graph.find(subject, SpatialExtension.GEO_LON_NODE, null).next().getObject();
                Node latLonGeometryLiteral = ConvertLatLon.toNode(lat, lon);
                Triple triple = new Triple(subject, Geo.HAS_GEOMETRY_NODE, latLonGeometryLiteral);
                spatialTriples.addIterator(Arrays.asList(triple).iterator());
            }
        }

        //Check through each Geometry and stop if one is accepted.
        boolean isMatched = false;
        while (spatialTriples.hasNext()) {

            Triple triple = spatialTriples.next();
            Node geometryLiteral = triple.getObject();
            GeometryWrapper targetGeometryWrapper = GeometryWrapper.extract(geometryLiteral);
            isMatched = checkSecondFilter(spatialArguments, targetGeometryWrapper);
            if (isMatched) {
                //Stop checking when match is true.
                break;
            }
        }

        return isMatched;
    } catch (DatatypeFormatException ex) {
        throw new ExprEvalException(ex.getMessage(), ex);
    }
}