use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testStartIndexIterator.
@Test
public void testStartIndexIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.skip(collection.iterator(), 0);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.skip(collection.iterator(), 1);
assertEquals(2, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.skip(collection.iterator(), 2);
assertTrue(ite.next() != null);
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.skip(collection.iterator(), 1);
testIterationOnNext(ite, 2);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.skip(checkIte, 1);
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 testFilterIterator.
@Test
public void testFilterIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.filter(collection.iterator(), Filter.include());
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), Filter.exclude());
assertEquals(0, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
assertEquals(1, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.filter(collection.iterator(), FF.equal(FF.literal("aaa"), FF.property("att_string")));
assertEquals(id3, 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.filter(collection.iterator(), Filter.include());
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.filter(checkIte, Filter.include());
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 testCacheIterator.
@Test
@Ignore("See #GEOTK-489")
public void testCacheIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.cached(collection.iterator(), 1);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.cached(collection.iterator(), 1);
int mask = 0;
Feature f;
while (ite.hasNext()) {
f = ite.next();
final Object id = f.getPropertyValue(AttributeConvention.IDENTIFIER);
if (id1.equals(id)) {
mask |= 1 << 0;
} else if (id2.equals(id)) {
mask |= 1 << 1;
} else if (id3.equals(id)) {
mask |= 1 << 2;
}
}
ite.close();
if (mask != 7) {
fail("missing features in iterations");
}
}
use of org.geotoolkit.storage.feature.FeatureIterator in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testModifyIterator.
@Test
public void testModifyIterator() {
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureType originalType = collection.getType();
Filter filter = Filter.include();
Map<String, Object> values = new HashMap<>();
values.put("att_string", "toto");
FeatureIterator ite = FeatureStreams.update(collection.iterator(), filter, values);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.update(collection.iterator(), filter, values);
while (ite.hasNext()) {
assertTrue(ite.next().getProperty("att_string").getValue().equals("toto"));
}
filter = FF.equal(FF.literal("aaa"), FF.property("att_string"));
ite = FeatureStreams.update(collection.iterator(), filter, values);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.update(collection.iterator(), filter, values);
while (ite.hasNext()) {
Feature f = ite.next();
if (f.getPropertyValue(AttributeConvention.IDENTIFIER).equals(id3)) {
assertTrue(f.getProperty("att_string").getValue().equals("toto"));
} else {
assertFalse(f.getProperty("att_string").getValue().equals("toto"));
}
}
ite = FeatureStreams.update(collection.iterator(), filter, values);
ite.next();
ite.next();
ite.next();
try {
ite.next();
fail("Should have raise a no such element exception.");
} catch (NoSuchElementException ex) {
// ok
}
// check has next do not iterate
ite = FeatureStreams.update(collection.iterator(), filter, values);
testIterationOnNext(ite, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
ite = FeatureStreams.update(checkIte, filter, values);
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 testSortByIterator.
@Test
public void testSortByIterator() {
SortProperty[] sorts = new SortProperty[] { FF.sort(FF.property("att_string"), SortOrder.ASCENDING) };
FeatureCollection collection = buildSimpleFeatureCollection();
FeatureIterator ite = FeatureStreams.sort(collection.iterator(), sorts);
assertEquals(3, FeatureStoreUtilities.calculateCount(ite));
ite = FeatureStreams.sort(collection.iterator(), sorts);
assertEquals(id3, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(id1, ite.next().getPropertyValue(AttributeConvention.IDENTIFIER));
assertEquals(id2, 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(collection.iterator(), sorts);
testIterationOnNext(ite, 3);
// 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());
}
Aggregations