use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testSortByIteratorOnComplex.
@Test
public void testSortByIteratorOnComplex() {
FeatureCollection collectionComplex = buildComplexFeatureCollection();
FeatureCollection collection = buildSimpleFeatureCollection();
// test string sort -----------------------------------------------------
SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.DESCENDING) };
FeatureIterator ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// test string sort -----------------------------------------------------
sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.DESCENDING) };
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// test double sort -----------------------------------------------------
sorts = new SortProperty[] { FF.sort(FF.property("att_double"), SortOrder.ASCENDING) };
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
assertEquals(COMPLEX_ID_2, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(COMPLEX_ID_1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.sort(collectionComplex.iterator(), sorts);
testIterationOnNext(ite, 2);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.sort(checkIte, sorts);
while (ite.hasNext()) ite.next();
ite.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testEmptyIterator.
@Test
public void testEmptyIterator() {
final FeatureIterator iterator = FeatureStreams.emptyIterator();
assertFalse(iterator.hasNext());
try {
iterator.next();
fail("Next on empty iterator should have raised a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
try {
iterator.remove();
fail("Remove should have raise an error.");
} catch (Exception ex) {
// ok
}
iterator.close();
}
use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class AddDelta method modify.
/**
* {@inheritDoc }
*/
@Override
public FeatureIterator modify(final Query query, final FeatureIterator reader) throws DataStoreException {
if (!query.getTypeName().equals(type))
return reader;
// remove the filter, it is handle at the end by the session
// we can not filter here since some modify operation can follow
// and change the filter result
final Query qb = new Query();
qb.copy(query);
qb.setSelection(Filter.include());
final FeatureIterator affected = features.subset(qb).iterator();
final SortProperty[] sort = QueryUtilities.getSortProperties(query.getSortBy());
if (sort != null && sort.length > 0) {
return FeatureStreams.combine(query.getSortBy(), reader, affected);
} else {
return FeatureStreams.sequence(reader, affected);
}
}
use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class RenderingRoutines method getIterator.
public static GraphicIterator getIterator(final FeatureSet features, final RenderingContext2D renderingContext) throws DataStoreException {
final FeatureIterator iterator;
final Stream<Feature> stream = features.features(false);
final Iterator<Feature> i = stream.iterator();
iterator = new FeatureIterator() {
@Override
public Feature next() throws FeatureStoreRuntimeException {
return i.next();
}
@Override
public boolean hasNext() throws FeatureStoreRuntimeException {
return i.hasNext();
}
@Override
public void close() {
stream.close();
}
};
final ProjectedFeature projectedFeature = new ProjectedFeature(renderingContext);
return new GraphicIterator(iterator, projectedFeature);
}
use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class DBRelationOperation method apply.
@Override
public Property apply(Feature ftr, ParameterValueGroup pvg) {
final Object key = ftr.getPropertyValue(relation.getCurrentColumn());
final Query qb = new Query();
qb.setTypeName(NamesExt.create(relation.getForeignTable()));
qb.setSelection(relation.toFilter(key));
final FeatureCollection res = store.createSession(false).getFeatureCollection(qb);
final Object value;
if (type.getMaximumOccurs() == 1) {
try (FeatureIterator ite = res.iterator()) {
if (ite.hasNext()) {
value = ite.next();
} else {
value = null;
}
}
} else {
value = res;
}
return new AbstractAssociation(type) {
@Override
public Feature getValue() throws MultiValuedPropertyException {
if (value == null || value instanceof Feature) {
return (Feature) value;
}
throw new MultiValuedPropertyException();
}
@Override
public Collection<Feature> getValues() {
if (value == null) {
return Collections.EMPTY_LIST;
} else if (value instanceof Feature) {
return Arrays.asList((Feature) value);
} else {
return res;
}
}
@Override
public void setValue(Feature value) throws InvalidPropertyValueException {
throw new UnsupportedOperationException("Not supported.");
}
};
}
Aggregations