[Schmitzm-commits] r1117 - in trunk: src/schmitzm/geotools/io src_junit/schmitzm/geotools/feature src_junit/schmitzm/swing
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Thu Oct 14 21:16:16 CEST 2010
Author: alfonx
Date: 2010-10-14 21:16:15 +0200 (Thu, 14 Oct 2010)
New Revision: 1117
Modified:
trunk/src/schmitzm/geotools/io/GeoImportUtil.java
trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
trunk/src_junit/schmitzm/swing/TestingUtil.java
Log:
A new test to check the conversion of Shapefiles with illegal headers
Modified: trunk/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoImportUtil.java 2010-10-14 18:54:15 UTC (rev 1116)
+++ trunk/src/schmitzm/geotools/io/GeoImportUtil.java 2010-10-14 19:16:15 UTC (rev 1117)
@@ -283,9 +283,8 @@
LOGGER.warn(" NOT calling forceSchemaCRS now... please provide a URL to an existing .prj file!");
// store.forceSchemaCRS(DEFAULT_CRS);
}
- String[] typeNames = store.getTypeNames();
FeatureCollection<SimpleFeatureType, SimpleFeature> fc = store
- .getFeatureSource(typeNames[0]).getFeatures();
+ .getFeatureSource().getFeatures();
// Create a new DefaultFeatureCollection to allow modifying
// operations on the collection ("fc" is a DataFeatureCollection, whose
@@ -372,6 +371,8 @@
* @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons Tzeggai</a>
* @throws IOException
* if an error occur
+ *
+ * @deprecated So wird das nicht mehr gemacht. Das wird mit einem Factory Finder gemacht.
*/
public static DataStore readDataStoreFromShape(URL shpURL, URL prjURL)
throws IOException {
Modified: trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java 2010-10-14 18:54:15 UTC (rev 1116)
+++ trunk/src_junit/schmitzm/geotools/feature/FeatureUtilTest.java 2010-10-14 19:16:15 UTC (rev 1117)
@@ -4,12 +4,24 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.io.IOException;
import java.util.List;
+import org.geotools.data.DataUtilities;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.feature.FeatureCollection;
import org.junit.Test;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.GeometryDescriptor;
import schmitzm.geotools.feature.FeatureUtil.GeometryForm;
+import schmitzm.geotools.io.GeoImportUtil;
+import schmitzm.swing.TestingUtil;
+import schmitzm.swing.TestingUtil.TestDatasets;
+import skrueger.geotools.io.GeoImportUtilURL;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Polygon;
@@ -70,4 +82,50 @@
assertFalse(FeatureUtil.checkAttributeNameRestrictions("aوض"));
}
+ @Test
+ public void testModifyFeatureSource() throws Exception {
+
+ FeatureSource<SimpleFeatureType, SimpleFeature> sourceFs = TestingUtil
+ .getTestFeatureSource(TestDatasets.arabicInHeader);
+ assertEquals(4, sourceFs.getSchema().getAttributeCount());
+ assertEquals("the_geom", sourceFs.getSchema().getDescriptor(0)
+ .getLocalName());
+ assertEquals("NOM_AGENCE", sourceFs.getSchema().getDescriptor(1)
+ .getLocalName());
+ assertEquals("SURFACE", sourceFs.getSchema().getDescriptor(2)
+ .getLocalName());
+ assertEquals(Integer.class, sourceFs.getSchema().getDescriptor(2)
+ .getType().getBinding());
+ assertEquals("�����", sourceFs.getSchema().getDescriptor(3)
+ .getLocalName());
+
+ File outFile = File.createTempFile("testModifyFeatureSource", ".shp");
+ ShapefileDataStore outputFs = new ShapefileDataStore(
+ DataUtilities.fileToURL(outFile));
+
+ AttributeModificationRule[] destAttrs = new AttributeModificationRule[3];
+ destAttrs[0] = new AttributeModificationRule(0);
+ destAttrs[1] = new AttributeModificationRule(3, "arab", null, null);
+ destAttrs[2] = new AttributeModificationRule(2);
+
+ // // Umwandlung starten
+ FeatureUtil.modifyFeatureSource(sourceFs, outputFs, destAttrs);
+ outputFs.dispose();
+
+ // Testen, ob das gewünschte Ergebnis erstellt wurde
+ FeatureCollection<SimpleFeatureType, SimpleFeature> correctedFC = GeoImportUtilURL
+ .readFeaturesFromShapeFile(outFile);
+
+ // Schema testen
+ assertEquals(3, correctedFC.getSchema().getAttributeCount());
+ assertEquals("the_geom", sourceFs.getSchema().getDescriptor(0)
+ .getLocalName());
+ assertEquals("arab", sourceFs.getSchema().getDescriptor(1)
+ .getLocalName());
+ assertEquals("SURFACE", sourceFs.getSchema().getDescriptor(2)
+ .getLocalName());
+ assertEquals(Integer.class, sourceFs.getSchema().getDescriptor(2)
+ .getType().getBinding());
+ }
+
}
Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-10-14 18:54:15 UTC (rev 1116)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java 2010-10-14 19:16:15 UTC (rev 1117)
@@ -26,6 +26,8 @@
import javax.swing.JPanel;
import org.geotools.data.DataUtilities;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
@@ -51,280 +53,341 @@
// "java.lang.Exception: No runnable methods"
public class TestingUtil {
- /**
- * Number of seconds to wait until a GUI should be closed by default. Can be
- * set to -1 to always wait forever.
- */
- private static final int WAIT_MAX_DEFAULT = 3;
- /**
- * All these GUI-initiating testGui(...) methods are only executed if the
- * system is not running in headless mode.
- */
- public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+ /**
+ * Number of seconds to wait until a GUI should be closed by default. Can be
+ * set to -1 to always wait forever.
+ */
+ private static final int WAIT_MAX_DEFAULT = 3;
+ /**
+ * All these GUI-initiating testGui(...) methods are only executed if the
+ * system is not running in headless mode.
+ */
+ public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
- /**
- * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
- * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
- * The test is skipped if the JVM is running headless.
- * @param gui
- * @param title can be used to explain the tests what to check
- * @param waitMax Maximum seconds to wait until the GUI should automatically
- * close, set -1 for unlimieted
- */
- public static void testGui(Component gui, String title, int waitMax)
- throws Throwable {
+ /**
+ * Opens a {@link JFrame} and shows the passed {@link JComponent}. If a
+ * {@link ExceptionDialog} is opens in the GUI, an exception is thrown.<br/>
+ * The test is skipped if the JVM is running headless.
+ *
+ * @param gui
+ * @param title
+ * can be used to explain the tests what to check
+ * @param waitMax
+ * Maximum seconds to wait until the GUI should automatically
+ * close, set -1 for unlimieted
+ */
+ public static void testGui(Component gui, String title, int waitMax)
+ throws Throwable {
- if (GraphicsEnvironment.isHeadless())
- return;
+ if (GraphicsEnvironment.isHeadless())
+ return;
- final AtomicBoolean stopFlag = new AtomicBoolean(false);
+ final AtomicBoolean stopFlag = new AtomicBoolean(false);
- final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
+ final AtomicReference<Throwable> err = new AtomicReference<Throwable>();
- ExceptionDialog.addListener(new ActionListener() {
+ ExceptionDialog.addListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- err.set((Throwable) e.getSource());
- stopFlag.set(true);
- }
- });
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ err.set((Throwable) e.getSource());
+ stopFlag.set(true);
+ }
+ });
- Window w = null;
- if (gui instanceof Window) {
- w = (Window) gui;
- } else if (gui instanceof JComponent) {
- JFrame f = new JFrame(title);
- f.setContentPane((JComponent) gui);
- f.pack();
- w = f;
- }
+ Window w = null;
+ if (gui instanceof Window) {
+ w = (Window) gui;
+ } else if (gui instanceof JComponent) {
+ JFrame f = new JFrame(title);
+ f.setContentPane((JComponent) gui);
+ f.pack();
+ w = f;
+ }
- // If it is a modal dialog, unmodalize it
- w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
+ // If it is a modal dialog, unmodalize it
+ w.setModalExclusionType(ModalExclusionType.NO_EXCLUDE);
- if (w instanceof JDialog) {
- // JDialog.setModal must be unset additionally.
- JDialog d = (JDialog) w;
- d.setModal(false);
- }
+ if (w instanceof JDialog) {
+ // JDialog.setModal must be unset additionally.
+ JDialog d = (JDialog) w;
+ d.setModal(false);
+ }
- w.setVisible(true);
- int countWait = 0;
- while (w.isVisible() && !stopFlag.get()) {
- LangUtil.sleepExceptionless(100);
- if (waitMax >= 0 && countWait++ > waitMax * 10) {
- // waitMax < 0 will never brake the waiting and never increase
- // the countWait
- break;
- }
- }
- w.dispose();
+ w.setVisible(true);
+ int countWait = 0;
+ while (w.isVisible() && !stopFlag.get()) {
+ LangUtil.sleepExceptionless(100);
+ if (waitMax >= 0 && countWait++ > waitMax * 10) {
+ // waitMax < 0 will never brake the waiting and never increase
+ // the countWait
+ break;
+ }
+ }
+ w.dispose();
- if (stopFlag.get()) {
- throw err.get();
- }
+ if (stopFlag.get()) {
+ throw err.get();
+ }
- }
+ }
- public static void testGui(Component gui, int waitMax) throws Throwable {
- testGui(gui, gui.getClass().getSimpleName(), waitMax);
- }
+ public static void testGui(Component gui, int waitMax) throws Throwable {
+ testGui(gui, gui.getClass().getSimpleName(), waitMax);
+ }
- public static void testGui(Image image, int waitMax) throws Throwable {
+ public static void testGui(Image image, int waitMax) throws Throwable {
- if (GraphicsEnvironment.isHeadless())
- return;
+ if (GraphicsEnvironment.isHeadless())
+ return;
- JLabel imgLabel = new JLabel(new ImageIcon(image));
- testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
- }
+ JLabel imgLabel = new JLabel(new ImageIcon(image));
+ testGui(imgLabel, imgLabel.getClass().getSimpleName(), waitMax);
+ }
- /**
- * Checks whether an image has a specific color/transparency at a special
- * pixel position.
- */
- public static boolean checkPixel(BufferedImage bi, int x, int y,
- Float... colorParts) {
+ /**
+ * Checks whether an image has a specific color/transparency at a special
+ * pixel position.
+ */
+ public static boolean checkPixel(BufferedImage bi, int x, int y,
+ Float... colorParts) {
- Color expectedColor = new Color(colorParts[0], colorParts[1],
- colorParts[2], colorParts[3]);
+ Color expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2], colorParts[3]);
- return checkPixel(bi, x, y, expectedColor);
+ return checkPixel(bi, x, y, expectedColor);
- }
+ }
- private static boolean checkPixel(BufferedImage bi, int x, int y,
- Color expected) {
- final int rgb = bi.getRGB(x, y);
+ private static boolean checkPixel(BufferedImage bi, int x, int y,
+ Color expected) {
+ final int rgb = bi.getRGB(x, y);
- final Color found = new Color(rgb, true);
+ final Color found = new Color(rgb, true);
- final boolean equals = expected.equals(found);
+ final boolean equals = expected.equals(found);
- if (!equals) {
- System.err.println("At pixel (" + x + "/" + y + ") expected " + expected +
- " but found " + found);
- }
+ if (!equals) {
+ System.err.println("At pixel (" + x + "/" + y + ") expected "
+ + expected + " but found " + found);
+ }
- return equals;
- }
+ return equals;
+ }
- public static boolean checkPixel(BufferedImage bi, int x, int y,
- int... colorParts) {
+ public static boolean checkPixel(BufferedImage bi, int x, int y,
+ int... colorParts) {
- Color expectedColor;
+ Color expectedColor;
- if (colorParts.length == 4) {
- expectedColor = new Color(colorParts[0], colorParts[1], colorParts[2],
- colorParts[3]);
- } else {
- expectedColor = new Color(colorParts[0], colorParts[1], colorParts[2]);
- }
+ if (colorParts.length == 4) {
+ expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2], colorParts[3]);
+ } else {
+ expectedColor = new Color(colorParts[0], colorParts[1],
+ colorParts[2]);
+ }
- return checkPixel(bi, x, y, expectedColor);
- }
+ return checkPixel(bi, x, y, expectedColor);
+ }
- public static void testGui(JPanel jPanel, String title) throws Throwable {
- testGui(jPanel, title, 3);
- }
+ public static void testGui(JPanel jPanel, String title) throws Throwable {
+ testGui(jPanel, title, 3);
+ }
- public static void testGui(Component gui) throws Throwable {
- testGui(gui, WAIT_MAX_DEFAULT);
- }
+ public static void testGui(Component gui) throws Throwable {
+ testGui(gui, WAIT_MAX_DEFAULT);
+ }
- public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
- DefaultMapContext mc = new DefaultMapContext(
- dml.getFeatureSource().getSchema().getCoordinateReferenceSystem());
+ public static BufferedImage visualize(DefaultMapLayer dml) throws Throwable {
+ DefaultMapContext mc = new DefaultMapContext(dml.getFeatureSource()
+ .getSchema().getCoordinateReferenceSystem());
- mc.addLayer(dml);
+ mc.addLayer(dml);
- StreamingRenderer sr = new StreamingRenderer();
- sr.setContext(mc);
+ StreamingRenderer sr = new StreamingRenderer();
+ sr.setContext(mc);
- final BufferedImage bi = new BufferedImage(100, 100,
- BufferedImage.TYPE_4BYTE_ABGR);
- Graphics2D g2d = bi.createGraphics();
- ReferencedEnvelope geoArea = new ReferencedEnvelope(dml.getFeatureSource()
- .getBounds());
- sr.paint(g2d, new Rectangle(100, 100), geoArea);
- g2d.dispose();
+ final BufferedImage bi = new BufferedImage(100, 100,
+ BufferedImage.TYPE_4BYTE_ABGR);
+ Graphics2D g2d = bi.createGraphics();
+ ReferencedEnvelope geoArea = new ReferencedEnvelope(dml
+ .getFeatureSource().getBounds());
+ sr.paint(g2d, new Rectangle(100, 100), geoArea);
+ g2d.dispose();
- TestingUtil.testGui(bi, 1);
+ TestingUtil.testGui(bi, 1);
- return bi;
- }
+ return bi;
+ }
- /**
- * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
- * points to a version of the shapefile copied to the tmp dir.
- * @throws IOException
- * @throws URISyntaxException
- */
- public static URL copyShapefileToTemp(URL urlToShape) throws IOException,
- URISyntaxException {
- File tempDir = new File(IOUtil.getTempDir(), "shape" +
- (System.currentTimeMillis()));
- tempDir.mkdir();
+ /**
+ * Takes a URL to a shapefile, that may be inside a jar. The retuned UTL
+ * points to a version of the shapefile copied to the tmp dir.
+ *
+ * @throws IOException
+ * @throws URISyntaxException
+ */
+ public static URL copyShapefileToTemp(URL urlToShape) throws IOException,
+ URISyntaxException {
+ File tempDir = new File(IOUtil.getTempDir(), "shape"
+ + (System.currentTimeMillis()));
+ tempDir.mkdir();
- /**
- * SHP file!
- */
- final URL shpURL = IOUtil.changeUrlExt(urlToShape, "shp");
- String fileName = shpURL.getPath();
- if (shpURL.getPath().lastIndexOf("/") > 0)
- fileName = shpURL.getPath().substring(shpURL.getPath().lastIndexOf("/"));
+ /**
+ * SHP file!
+ */
+ final URL shpURL = IOUtil.changeUrlExt(urlToShape, "shp");
+ String fileName = shpURL.getPath();
+ if (shpURL.getPath().lastIndexOf("/") > 0)
+ fileName = shpURL.getPath().substring(
+ shpURL.getPath().lastIndexOf("/"));
- IOUtil.copyUrl(shpURL, tempDir, false);
+ IOUtil.copyUrl(shpURL, tempDir, false);
- final URL shxURL = IOUtil.changeUrlExt(urlToShape, "shx");
- IOUtil.copyUrl(shxURL, tempDir, false);
+ final URL shxURL = IOUtil.changeUrlExt(urlToShape, "shx");
+ IOUtil.copyUrl(shxURL, tempDir, false);
- final URL grxURL = IOUtil.changeUrlExt(urlToShape, "grx");
- IOUtil.copyURLNoException(grxURL, tempDir, false);
+ final URL grxURL = IOUtil.changeUrlExt(urlToShape, "grx");
+ IOUtil.copyURLNoException(grxURL, tempDir, false);
- final URL fixURL = IOUtil.changeUrlExt(urlToShape, "fix");
- IOUtil.copyURLNoException(fixURL, tempDir, false);
+ final URL fixURL = IOUtil.changeUrlExt(urlToShape, "fix");
+ IOUtil.copyURLNoException(fixURL, tempDir, false);
- final URL qixURL = IOUtil.changeUrlExt(urlToShape, "qix");
- IOUtil.copyURLNoException(qixURL, tempDir, false);
+ final URL qixURL = IOUtil.changeUrlExt(urlToShape, "qix");
+ IOUtil.copyURLNoException(qixURL, tempDir, false);
- final URL xmlURL = IOUtil.changeUrlExt(urlToShape, "shp.xml");
- IOUtil.copyURLNoException(xmlURL, tempDir, false);
+ final URL xmlURL = IOUtil.changeUrlExt(urlToShape, "shp.xml");
+ IOUtil.copyURLNoException(xmlURL, tempDir, false);
- final URL dbfURL = IOUtil.changeUrlExt(urlToShape, "dbf");
- IOUtil.copyUrl(dbfURL, tempDir, false);
+ final URL dbfURL = IOUtil.changeUrlExt(urlToShape, "dbf");
+ IOUtil.copyUrl(dbfURL, tempDir, false);
- /**
- * Optionally copy a .cpg file that describes the
- */
- final URL cpgURL = IOUtil.changeUrlExt(urlToShape, "cpg");
- IOUtil.copyURLNoException(cpgURL, tempDir, false);
+ /**
+ * Optionally copy a .cpg file that describes the
+ */
+ final URL cpgURL = IOUtil.changeUrlExt(urlToShape, "cpg");
+ IOUtil.copyURLNoException(cpgURL, tempDir, false);
- return DataUtilities.fileToURL(new File(tempDir, fileName));
- }
+ return DataUtilities.fileToURL(new File(tempDir, fileName));
+ }
- final static String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
+ final static String resLocation_Kreise = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
+ final static String resLocation_ArabicHeader = "/schmitzm/geotools/feature/arabicShapefiles/arabicwitharabicinheader.shp";
- /**
- * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
- * <code>test</code> läuft.
- */
- public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures()
- throws IOException {
- // Testdatenshape einlesen
- URL resourceUrl = FeatureChartStyle.class.getResource(resLocation);
+ /**
+ * List of available test datasets
+ */
+ public static enum TestDatasets {
+ kreise, arabicInHeader;
- if (resourceUrl == null)
- throw new IllegalStateException(resLocation + " wurde nicht gefunden!");
+ URL getUrl() {
+ switch (this) {
+ case kreise:
+ return TestingUtil.class.getResource(resLocation_Kreise);
+ case arabicInHeader:
+ return TestingUtil.class.getResource(resLocation_ArabicHeader);
- FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil.readFeaturesFromShapeURL(resourceUrl);
+ }
+ return null;
+ }
+ }
- if (testFeatures == null)
- throw new IllegalStateException(
- "Testfeatures konnten nicht gelesen werden");
+ /**
+ * Stellt Test-Features zur Verfügung, WENN die Anwendung im maven scope
+ * <code>test</code> läuft.
+ *
+ * @deprecated use getTestFeatures(ENUM TestData)
+ */
+ public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures()
+ throws IOException {
+ // Testdatenshape einlesen
+ URL resourceUrl = FeatureChartStyle.class
+ .getResource(resLocation_Kreise);
- return testFeatures;
- }
+ if (resourceUrl == null)
+ throw new IllegalStateException(resLocation_Kreise
+ + " wurde nicht gefunden!");
- public static void testGui(JFreeChart chart, String frameTitle)
- throws Throwable {
- testGui(chart,frameTitle,WAIT_MAX_DEFAULT);
- }
+ FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = GeoImportUtil
+ .readFeaturesFromShapeURL(resourceUrl);
- public static void testGui(JFreeChart chart, String frameTitle, int waitMax)
- throws Throwable {
- if (INTERACTIVE) {
- ChartFrame chartFrame = new ChartFrame(frameTitle, chart);
- chartFrame.pack();
+ if (testFeatures == null)
+ throw new IllegalStateException(
+ "Testfeatures konnten nicht gelesen werden");
- testGui(chartFrame,waitMax);
- }
- }
+ return testFeatures;
+ }
- /**
- * Returns the percentage of the possible maximum head size used (0 to 100)
- */
- public static double getHeapUsedPercentageOfMax() {
+ /**
+ * Stellt Test-FeatureCollections zur Verfügung
+ */
+ public static FeatureCollection<SimpleFeatureType, SimpleFeature> getTestFeatures(
+ TestDatasets dataset) throws IOException {
+ return getTestFeatureSource(dataset).getFeatures();
+ }
- // Get current size of heap in bytes
- long heapSize = Runtime.getRuntime().totalMemory();
+ /**
+ * Stellt Test-FeatureCollections zur Verfügung
+ */
+ public static FeatureSource<SimpleFeatureType, SimpleFeature> getTestFeatureSource(
+ TestDatasets dataset) throws IOException {
+ // Testdatenshape einlesen
+ URL resourceUrl = dataset.getUrl();
- // Get maximum size of heap in bytes. The heap cannot grow beyond this
- // size.
- // Any attempt will result in an OutOfMemoryException.
- long heapMaxSize = Runtime.getRuntime().maxMemory();
+ if (resourceUrl == null)
+ throw new IllegalStateException(dataset
+ + " wurde nicht gefunden!");
- // Get amount of free memory within the heap in bytes. This size will
- // increase
- // after garbage collection and decrease as new objects are created.
- long heapFreeSize = Runtime.getRuntime().freeMemory();
+ ShapefileDataStore store = new ShapefileDataStore(resourceUrl);
+ FeatureSource<SimpleFeatureType, SimpleFeature> fs = store
+ .getFeatureSource();
- long used = (heapSize - heapFreeSize);
+ if (fs == null)
+ throw new IllegalStateException(
+ "Testfeatures konnten nicht gelesen werden");
- double perc = (used * 100. / heapMaxSize);
+ return fs;
+ }
- return perc;
- }
+ public static void testGui(JFreeChart chart, String frameTitle)
+ throws Throwable {
+ testGui(chart, frameTitle, WAIT_MAX_DEFAULT);
+ }
+ public static void testGui(JFreeChart chart, String frameTitle, int waitMax)
+ throws Throwable {
+ if (INTERACTIVE) {
+ ChartFrame chartFrame = new ChartFrame(frameTitle, chart);
+ chartFrame.pack();
+
+ testGui(chartFrame, waitMax);
+ }
+ }
+
+ /**
+ * Returns the percentage of the possible maximum head size used (0 to 100)
+ */
+ public static double getHeapUsedPercentageOfMax() {
+
+ // Get current size of heap in bytes
+ long heapSize = Runtime.getRuntime().totalMemory();
+
+ // Get maximum size of heap in bytes. The heap cannot grow beyond this
+ // size.
+ // Any attempt will result in an OutOfMemoryException.
+ long heapMaxSize = Runtime.getRuntime().maxMemory();
+
+ // Get amount of free memory within the heap in bytes. This size will
+ // increase
+ // after garbage collection and decrease as new objects are created.
+ long heapFreeSize = Runtime.getRuntime().freeMemory();
+
+ long used = (heapSize - heapFreeSize);
+
+ double perc = (used * 100. / heapMaxSize);
+
+ return perc;
+ }
+
}
More information about the Schmitzm-commits
mailing list