List of usage examples for org.apache.commons.collections4.iterators IteratorChain addIterator
public void addIterator(final Iterator<? extends E> iterator)
From source file:org.apache.jena.geosparql.spatial.property_functions.GenericSpatialPropertyFunction.java
private boolean checkBound(ExecutionContext execCxt, Node subject) { try {//from w w w.ja va 2s. com 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); } }
From source file:org.openvpms.archetype.rules.workflow.FreeSlotIterator.java
/** * Creates an iterator to handle the first and last free slot. * <p/>//ww w . j a v a 2s . c om * These cannot be determined by the findFreeSlots named query without using unions which are slow, so two other * queries are issued to find: * <ul> * <li>the start time of the earliest appointment intersecting the start of the date range (before)</li> * <li>the end time of the latest appointment intersecting the end of the date range (after)</li> * </ul> * If there is an appointment at the start, this is used to add a slot (fromDate, before). * <p/> * If there is an appointment at the end, this is used to add a slot (after, toDate). * <p/> * If there are no appointments, then a slot (fromDate, toDate) is added. * * @param iterator the slot iterator * @return an iterator that handles the first free slot in the date range */ private Iterator<Slot> createFirstLastFreeSlotIterator(Iterator<Slot> iterator, Entity schedule, Date fromDate, Date toDate, IArchetypeService service) { IteratorChain<Slot> result = new IteratorChain<Slot>(); Date appointmentBefore = getAppointmentBefore(schedule, fromDate, toDate, service); Date appointmentAfter = getAppointmentAfter(schedule, fromDate, toDate, service); if (appointmentBefore != null || appointmentAfter != null) { if (appointmentBefore != null) { Slot slot = new Slot(schedule.getId(), fromDate, appointmentBefore); result.addIterator(Arrays.asList(slot).iterator()); } result.addIterator(iterator); if (appointmentAfter != null) { Slot slot = new Slot(schedule.getId(), appointmentAfter, toDate); result.addIterator(Arrays.asList(slot).iterator()); } } else { // no appointments Slot slot = new Slot(schedule.getId(), fromDate, toDate); result.addIterator(Arrays.asList(slot).iterator()); } return result; }