[Schmitzm-commits] r113 - in trunk: dist src/schmitzm/geotools/feature src/schmitzm/geotools/gui

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 13 13:38:57 CEST 2009


Author: mojays
Date: 2009-05-13 13:38:56 +0200 (Wed, 13 May 2009)
New Revision: 113

Modified:
   trunk/dist/schmitzm-src.zip
   trunk/dist/schmitzm.jar
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
Log:
some changes to avoid NPEs when FeatureCollection.getSize() returns a to big value

Modified: trunk/dist/schmitzm-src.zip
===================================================================
(Binary files differ)

Modified: trunk/dist/schmitzm.jar
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-05-13 09:18:53 UTC (rev 112)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2009-05-13 11:38:56 UTC (rev 113)
@@ -336,7 +336,7 @@
   public static Feature[] featuresToArray(FeatureCollection fc) {
     if ( fc == null )
       return new Feature[0];
-    Feature[] featureArray = (Feature[])fc.toArray(new Feature[fc.size()]);
+    Feature[] featureArray = (Feature[])fc.toArray(new Feature[0]);
     if ( featureArray != null )
       return featureArray;
     // Sonst "naiv" kopieren
@@ -348,6 +348,35 @@
   }
 
   /**
+   * Erzeugt einen Array von {@link Feature Features} auf einer
+   * {@link FeatureCollection}. Teilweise liefert
+   * {@code FeatureCollection.toArray(new Feature[.])} statt einem {@code Feature}-Array
+   * einfach {@code null}. In diesem Fall wird der Array "naiv" ueber Durchlaufen
+   * eines {@link FeatureIterator} erzeugt.
+   * @param fc
+   *            eine Feature Collection
+   * @param
+   *        includeNullFeatures
+   *            wenn {@code false} werden NULL-Features in der Collection nicht in den
+   *            Array kopiert
+   * @return einen leeren Array, wenn die Collection leer oder {@code null} ist
+   */
+   public static Feature[] featuresToArray(FeatureCollection fc, boolean includeNullFeatures) {
+     if ( includeNullFeatures )
+       return featuresToArray(fc);
+
+     // Naiv alle Features durchgehen.
+     Vector<Feature> fv = new Vector<Feature>();
+     FeatureIterator fi = fc.features();
+     for (int i=0; fi.hasNext(); i++) {
+       Feature f = fi.next();
+       if ( f != null )
+         fv.add(f);
+     }
+     return fv.toArray(new Feature[0]);
+   }
+
+   /**
    * Clones an {@link FeatureType}.
    * @param fType     type to clone
    * @param fTypeName the name for the clone (if {@code null} the name is

Modified: trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java	2009-05-13 09:18:53 UTC (rev 112)
+++ trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java	2009-05-13 11:38:56 UTC (rev 113)
@@ -133,7 +133,8 @@
     // store feature indexes in HashMap to optimize findFeature(.)
     featureIdx = new HashMap<String, Integer>();
     for (int i=0; i<featureArray.length; i++)
-      featureIdx.put(featureArray[i].getID(), i);
+      if ( featureArray[i] != null )
+        featureIdx.put(featureArray[i].getID(), i);
     
     if ( fireTableStructureChanged )
       fireTableStructureChanged();
@@ -199,7 +200,9 @@
    * Features in der Collection.
    */
   public int getRowCount() {
-    return featureTable == null ? 0 : featureTable.size();
+    if (featureArray == null)
+      featureArray = FeatureUtil.featuresToArray(featureTable);
+    return featureArray.length;
   }
 
   /**
@@ -210,6 +213,8 @@
   public Object getValueAt(final int row, final int col) {
       if (featureArray == null)
           featureArray = FeatureUtil.featuresToArray(featureTable);
+      if (featureArray[row] == null)
+        return null;
       return featureArray[row].getAttribute( attrIdxForCol[col] );
   }
   



More information about the Schmitzm-commits mailing list