use of org.geotoolkit.storage.feature.FeatureCollection 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.FeatureCollection in project geotoolkit by Geomatys.
the class FeatureStreamsTest method testWrapReader.
@Test
public void testWrapReader() {
FeatureCollection collection = buildSimpleFeatureCollection();
// check has next do not iterate
FeatureReader reader = FeatureStreams.asReader(collection.iterator(), collection.getType());
testIterationOnNext(reader, 3);
// check sub iterator is properly closed
CheckCloseFeatureIterator checkIte = new CheckCloseFeatureIterator(collection.iterator());
assertFalse(checkIte.isClosed());
reader = FeatureStreams.asReader(checkIte, collection.getType());
while (reader.hasNext()) reader.next();
reader.close();
assertTrue(checkIte.isClosed());
}
use of org.geotoolkit.storage.feature.FeatureCollection 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());
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class FeatureStreamsTest method buildSimpleFeatureCollection.
private FeatureCollection buildSimpleFeatureCollection() {
FeatureType originalType = buildOriginalFT();
FeatureCollection collection = FeatureStoreUtilities.collection("id", originalType);
Feature sf1 = originalType.newInstance();
sf1.setPropertyValue("id", 0);
sf1.setPropertyValue("att_geom", GF.createPoint(new Coordinate(3, 0)));
sf1.setPropertyValue("att_string", "bbb");
sf1.setPropertyValue("att_double", 3d);
collection.add(sf1);
Feature sf2 = originalType.newInstance();
sf2.setPropertyValue("id", 1);
sf2.setPropertyValue("att_geom", GF.createPoint(new Coordinate(1, 0)));
sf2.setPropertyValue("att_string", "ccc");
sf2.setPropertyValue("att_double", 1d);
collection.add(sf2);
Feature sf3 = originalType.newInstance();
sf3.setPropertyValue("id", 2);
sf3.setPropertyValue("att_geom", GF.createPoint(new Coordinate(2, 0)));
sf3.setPropertyValue("att_string", "aaa");
sf3.setPropertyValue("att_double", 2d);
collection.add(sf3);
return collection;
}
use of org.geotoolkit.storage.feature.FeatureCollection in project geotoolkit by Geomatys.
the class FeatureStreamsTest method buildComplexFeatureCollection.
private FeatureCollection buildComplexFeatureCollection() {
FeatureTypeBuilder builder = new FeatureTypeBuilder();
builder.setName(NAME);
builder.addAttribute(Integer.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
builder.addAttribute(String.class).setName("att_string");
builder.addAttribute(Double.class).setName("att_double");
FeatureType ct = builder.build();
FeatureCollection collectionComplex = FeatureStoreUtilities.collection("cid", ct);
Feature f1 = ct.newInstance();
f1.setPropertyValue("id", COMPLEX_ID_1);
f1.setPropertyValue("att_string", "aaaa");
f1.setPropertyValue("att_double", 12.0);
collectionComplex.add(f1);
Feature f2 = ct.newInstance();
f2.setPropertyValue("id", COMPLEX_ID_2);
f2.setPropertyValue("att_string", "bbbb");
f2.setPropertyValue("att_double", 7.0);
collectionComplex.add(f2);
return collectionComplex;
}
Aggregations