SimpleFeatureCollection to remove generics from example code
------------------------------------------------------------
Key: GEOT-3051
URL: http://jira.codehaus.org/browse/GEOT-3051
Project: GeoTools
Issue Type: Improvement
Components: data
Affects Versions: 2.6.3
Reporter: Jody Garnett
Priority: Minor
Fix For: 2.7-M0
I have had the pleasure of running through the geotools training material a
couple times in the last month; and I have watched each person get stuck in the
same spot.
Generics.
Generics in the Csv2Shape.java class.
{code}
public static void main(String[] args) throws Exception {
...
String typeName = newDataStore.getTypeNames()[0];
FeatureSource<SimpleFeatureType,SimpleFeature> featureSource =
(<SimpleFeatureType,SimpleFeature>)
newDataStore.getFeatureSource(typeName);
if (featureSource instanceof FeatureStore<?,?>) {
FeatureStore<SimpleFeatureType,SimpleFeature> featureStore =
(FeatureStore<SimpleFeatureType,SimpleFeature>) featureSource;
...
}
} else {
System.out.println(typeName + " does not support read/write access");
System.exit(1);
}
}
{code}
For now the solution (committed) is to use:
{code}
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
...
String typeName = newDataStore.getTypeNames()[0];
FeatureSource featureSource = newDataStore.getFeatureSource(typeName);
if (featureSource instanceof FeatureStore) {
FeatureStore featureStore = (FeatureStore) featureSource;
...
}
} else {
System.out.println(typeName + " does not support read/write access");
System.exit(1);
}
}
{code}
In addition to being magic to beginning Java users generics make the lines so
long it no longer looks like a simple assignment; and by the time they have
read word for word through the cast to feature store they need to start again
to see what happened.
Previous attempts using FeatureSource<?,?> were even more scary; they did not
even try reading the code.
So here is the minimal idea for the Csv2SShape example:
- no new methods
- SimpleFeatureCollection extends
FeatureCollection<SimpleFeatureType,SimpleFeature>
- SimpleFeatureSource and SimpleFeatureStore once again with no new API; just
returning SimpleFeatureCollection
This task is done when:
- casts are no longer needed example
I am prepared for this to be a change only on trunk; but I would need some
assurances I will have a release of trunk for FOSS4G this year.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel