I have a featurecollection:
SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
while (mifReader.hasNext()){
in = (SimpleFeatureImpl) mifReader.next();
SimpleFeature dbFeature = featureBuilder.buildFeature(null);
for(AttributeDescriptor ad : adList){
String name = ad.getLocalName();
Object attrValue;
attrValue = in.getAttribute(name);
if(attrValue instanceof String){
String string3 = new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251");
if(name.trim().equalsIgnoreCase(kadname.trim())){
dbFeature.setAttribute("kadnum", string3);
}
}
if (attrValue instanceof Geometry){
idn++;
com.vividsolutions.jts.geom.Geometry geom = (Geometry) in.getAttribute(name);
dbFeature.setAttribute("id", idn);
System.out.println("after insrt="+idn);
dbFeature.setAttribute("deleted", deleted);
dbFeature.setAttribute("the_geom", geom);
dbFeature.setAttribute("status_id", status_id);
}
collection.add(dbFeature);
}
}
Its all okay. But when I put this collection in Data Base i get a reversed items. So i want to sort or reverse items in this collection. But how to do this?
I try to use this:
collection.sort( new SortBy()
{
@Override
public PropertyName getPropertyName() { return YourPropertyNameImpl("id") ; }
@Override
public SortOrder getSortOrder() { return SortOrder.ASCENDING; }
});
But I don't understand what is YourPropertyNameImpl
.
UPDATE
Okey. I try to put features from my collection to another collection:
Iterator iterator = null;
int count;
iterator = collection.iterator();
while( iterator.hasNext()){
SimpleFeature feature = (SimpleFeature) iterator.next();
coll.add(feature);
System.out.println("Coll= "+coll.features().next().getProperties("id"));
}
But get same result(. In this case i need to read collection from last element to first. Its possible?
YourPropertyNameImpl("id")
what its mean? I try to use SimpleFeatureImpl but cant get a PropertyName.