Revision: 4860 http://sourceforge.net/p/jump-pilot/code/4860 Author: michaudm Date: 2016-03-23 21:30:03 +0000 (Wed, 23 Mar 2016) Log Message: ----------- Cleaning, formatting rewriting + 2 small fixes in fr language file
Modified Paths: -------------- core/trunk/pom.xml core/trunk/src/com/vividsolutions/jump/qa/ValidationErrorType.java core/trunk/src/com/vividsolutions/jump/qa/Validator.java core/trunk/src/com/vividsolutions/jump/util/FlexibleDateParser.java core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/ValidateSelectedLayersPlugIn.java core/trunk/src/jumptest/junit/FlexibleDateParserTestCase.java core/trunk/src/jumptest/junit/GMLWriterTestCase.java core/trunk/src/jumptest/junit/ValidatorTestCase.java core/trunk/src/language/jump.properties Modified: core/trunk/pom.xml =================================================================== --- core/trunk/pom.xml 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/pom.xml 2016-03-23 21:30:03 UTC (rev 4860) @@ -542,6 +542,7 @@ <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> + <version>3.5.1</version> <configuration> <source>1.7</source> <target>1.7</target> @@ -553,6 +554,7 @@ <inherited>true</inherited> <groupId>org.codehaus.mojo</groupId> <artifactId>buildnumber-maven-plugin</artifactId> + <version>1.4</version> <executions> <execution> <id>generate-buildnumber</id> @@ -621,6 +623,7 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> + <version>2.6</version> <executions> <execution> <id>nolang</id> Modified: core/trunk/src/com/vividsolutions/jump/qa/ValidationErrorType.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/qa/ValidationErrorType.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/com/vividsolutions/jump/qa/ValidationErrorType.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -56,13 +56,6 @@ /** Polygon hole is oriented clockwise */ public final static ValidationErrorType INTERIOR_RING_CW = new ValidationErrorType( I18N.get("qa.ValidationErrorType.polygon-hole-is-oriented-clockwise")); - - /** - * Linestring not simple - * @deprecated As of OpenJUMP 1.6, replaced by {@link #NONSIMPLE} - */ - public final static ValidationErrorType NONSIMPLE_LINESTRING = new ValidationErrorType( - I18N.get("qa.ValidationErrorType.linestring-not-simple")); /** * Linestring not simple Modified: core/trunk/src/com/vividsolutions/jump/qa/Validator.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/qa/Validator.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/com/vividsolutions/jump/qa/Validator.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -35,7 +35,7 @@ import java.util.*; -import com.vividsolutions.jts.algorithm.RobustCGAlgorithms; +import com.vividsolutions.jts.algorithm.CGAlgorithms; import com.vividsolutions.jts.geom.*; import com.vividsolutions.jts.operation.IsSimpleOp; import com.vividsolutions.jts.operation.valid.*; @@ -52,10 +52,9 @@ * orientation. */ public class Validator { - private int validatedFeatureCount; + private boolean checkingBasicTopology = true; private boolean checkingPolygonOrientation = false; - private boolean checkingLineStringsSimple = false; private boolean checkingGeometriesSimple = false; private boolean checkingMinSegmentLength = false; private boolean checkingMinAngle = false; @@ -65,9 +64,8 @@ private double minSegmentLength = 0; private double minAngle = 0; private double minPolygonArea = 0; - private Collection disallowedGeometryClassNames = new ArrayList(); + private Collection<String> disallowedGeometryClassNames = new ArrayList<>(); private RepeatedPointTester repeatedPointTester = new RepeatedPointTester(); - private RobustCGAlgorithms cgAlgorithms = new RobustCGAlgorithms(); //<<TODO:REFACTORING>> Move this class and associated classes to JTS [Jon Aquino] public Validator() { @@ -140,16 +138,6 @@ public void setMinPolygonArea(double minPolygonArea) { this.minPolygonArea = minPolygonArea; } - - /** - * Sets whether to enforce the constraint that LineStrings must be simple - * @param checkingLineStringsSimple whether to enforce the constraint that - * LineStrings must be simple - * @deprecated As of OpenJUMP 1.6, replaced by {@link #setCheckingGeometriesSimple} - */ - public void setCheckingLineStringsSimple(boolean checkingLineStringsSimple) { - this.checkingLineStringsSimple = checkingLineStringsSimple; - } /** * Sets whether to enforce the constraint that Geometries must be simple @@ -198,13 +186,11 @@ * @param disallowedGeometryClasses Geometry classes (Polygon.class, for * example) that are not allowed */ - public void setDisallowedGeometryClasses( - Collection disallowedGeometryClasses) { + public void setDisallowedGeometryClasses(Collection<Class> disallowedGeometryClasses) { disallowedGeometryClassNames.clear(); - for (Iterator i = disallowedGeometryClasses.iterator(); i.hasNext();) { - Class c = (Class) i.next(); - disallowedGeometryClassNames.add(c.getName()); + for (Class clazz : disallowedGeometryClasses) { + disallowedGeometryClassNames.add(clazz.getName()); } } @@ -216,10 +202,10 @@ */ public List validate(Collection features, TaskMonitor monitor) { monitor.allowCancellationRequests(); - validatedFeatureCount = 0; + int validatedFeatureCount = 0; monitor.report(I18N.get("qa.Validator.validating")); - ArrayList validationErrors = new ArrayList(); + List<Object> validationErrors = new ArrayList<>(); int totalFeatures = features.size(); for (Iterator i = features.iterator(); @@ -233,11 +219,10 @@ return validationErrors; } - protected void addIfNotNull(Object item, Collection collection) { + protected void addIfNotNull(Object item, Collection<Object> collection) { if (item == null) { return; } - collection.add(item); } @@ -247,8 +232,8 @@ * @param validationErrors a List of ValidationError's to add to if the feature * is not valid */ - protected void validate(Feature feature, List validationErrors) { - addIfNotNull((validateGeometryClass(feature)), validationErrors); + protected void validate(Feature feature, List<Object> validationErrors) { + addIfNotNull(validateGeometryClass(feature), validationErrors); if (checkingBasicTopology) { addIfNotNull(validateBasicTopology(feature), validationErrors); @@ -335,14 +320,14 @@ public ValidationError validate(Geometry g, Feature f) { Polygon polygon = (Polygon) g; - if (cgAlgorithms.isCCW(polygon.getExteriorRing() + if (CGAlgorithms.isCCW(polygon.getExteriorRing() .getCoordinates())) { return new ValidationError(ValidationErrorType.EXTERIOR_RING_CCW, f, polygon); } for (int i = 0; i < polygon.getNumInteriorRing(); i++) { - if (!cgAlgorithms.isCCW(polygon.getInteriorRingN(i) + if (!CGAlgorithms.isCCW(polygon.getInteriorRingN(i) .getCoordinates())) { return new ValidationError(ValidationErrorType.INTERIOR_RING_CW, f, polygon); @@ -411,13 +396,11 @@ } protected ValidationError validateMinSegmentLength(Feature feature) { - List arrays = CoordinateArrays.toCoordinateArrays(feature.getGeometry(), - false); + List<Coordinate[]> coordArrays = + CoordinateArrays.toCoordinateArrays(feature.getGeometry(), false); - for (Iterator i = arrays.iterator(); i.hasNext();) { - Coordinate[] coordinates = (Coordinate[]) i.next(); - ValidationError error = validateMinSegmentLength(coordinates, - feature); + for (Coordinate[] coordArray : coordArrays) { + ValidationError error = validateMinSegmentLength(coordArray, feature); if (error != null) { return error; @@ -428,12 +411,11 @@ } protected ValidationError validateMinAngle(Feature feature) { - List arrays = CoordinateArrays.toCoordinateArrays(feature.getGeometry(), - false); + List<Coordinate[]> coordArrays = + CoordinateArrays.toCoordinateArrays(feature.getGeometry(), false); - for (Iterator i = arrays.iterator(); i.hasNext();) { - Coordinate[] coordinates = (Coordinate[]) i.next(); - ValidationError error = validateMinAngle(coordinates, feature); + for (Coordinate[] coordArray : coordArrays) { + ValidationError error = validateMinAngle(coordArray, feature); if (error != null) { return error; @@ -533,11 +515,11 @@ * @param f used when constructing a ValidationError * @return a ValidationError if the validation fails; otherwise, null */ - public ValidationError validate(Geometry g, Feature f); + ValidationError validate(Geometry g, Feature f); /** * @return the Geometry class that this RecursiveValidation can validate. */ - public Class getTargetGeometryClass(); + Class getTargetGeometryClass(); } } Modified: core/trunk/src/com/vividsolutions/jump/util/FlexibleDateParser.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/util/FlexibleDateParser.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/com/vividsolutions/jump/util/FlexibleDateParser.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -40,20 +40,9 @@ import java.io.IOException; import java.io.InputStream; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.ParsePosition; -import java.text.SimpleDateFormat; +import java.text.*; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Comparator; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; -import java.util.TreeSet; +import java.util.*; import javax.swing.DefaultCellEditor; import javax.swing.JComponent; @@ -61,7 +50,6 @@ import javax.swing.JTextField; import javax.swing.border.LineBorder; import javax.swing.table.DefaultTableCellRenderer; -import javax.swing.table.TableCellEditor; /** * Warning: This class can parse a wide variety of formats. This flexibility is fine for parsing user @@ -72,8 +60,10 @@ * in FlexibleDateParser.txt). */ public class FlexibleDateParser { + private static Collection lenientFormatters = null; private static Collection unlenientFormatters = null; + //CellEditor used to be a static field CELL_EDITOR, but I was getting //problems calling it from ESETextField (it simply didn't appear). //The problems vanished when I turned it into a static class. I didn't @@ -287,10 +277,24 @@ } } + public FlexibleDateParser setLocale(Locale locale) { + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(locale); + lenientFormatters = null; + unlenientFormatters = null; + load(); + Locale.setDefault(defaultLocale); + return this; + } + private void load() { if (lenientFormatters == null) { + // Does not use 18N to be able to reload another language file dynamically + // (with 18N, things seems to be started only once at the start of the application) + ResourceBundle resourceBundle = ResourceBundle.getBundle("language/jump"); InputStream inputStream = - getClass().getResourceAsStream(I18N.get("com.vividsolutions.jump.util.FlexibleDateParser")); + getClass().getResourceAsStream(resourceBundle + .getString("com.vividsolutions.jump.util.FlexibleDateParser")); try { try { @@ -339,7 +343,7 @@ } public static void main(String[] args) throws Exception { - System.out.println(DateFormat.getDateInstance().parse("03-Mar-1998")); + //System.out.println(new FlexibleDateParser().parse("03-Mars-1998", false)); } public void setVerbose(boolean b) { Modified: core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/ValidateSelectedLayersPlugIn.java =================================================================== --- core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/ValidateSelectedLayersPlugIn.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/com/vividsolutions/jump/workbench/ui/plugin/ValidateSelectedLayersPlugIn.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -186,7 +186,7 @@ validator.setMinAngle(dialog.getDouble(MIN_ANGLE)); validator.setMinPolygonArea(dialog.getDouble(MIN_POLYGON_AREA)); - ArrayList disallowedGeometryClasses = new ArrayList(); + List<Class> disallowedGeometryClasses = new ArrayList<>(); if (dialog.getBoolean(DISALLOW_POINTS)) { disallowedGeometryClasses.add(Point.class); Modified: core/trunk/src/jumptest/junit/FlexibleDateParserTestCase.java =================================================================== --- core/trunk/src/jumptest/junit/FlexibleDateParserTestCase.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/jumptest/junit/FlexibleDateParserTestCase.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -5,9 +5,12 @@ import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.Locale; public class FlexibleDateParserTestCase extends TestCase { - private FlexibleDateParser parser = new FlexibleDateParser(); + + FlexibleDateParser parser = new FlexibleDateParser(); + static Locale defaultLocale = Locale.getDefault(); private SimpleDateFormat simpleFormat1 = new SimpleDateFormat("yyyy-MM-dd"); private SimpleDateFormat simpleFormat2 = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss:SSS"); @@ -23,9 +26,19 @@ junit.textui.TestRunner.run(FlexibleDateParserTestCase.class); } + protected void setUp() throws Exception { + parser.setLocale(Locale.ENGLISH); + } + + protected void tearDown() throws Exception { + parser.setLocale(defaultLocale); + } + public void test() throws Exception { + parser.setVerbose(true); - + //Locale oldLocale = Locale.getDefault(); + //Locale.setDefault(Locale.ENGLISH); //Some of these test are based on the formats in Excel [Jon Aquino] assertEquals(simpleFormat1.parse("2003-05-21"), parser.parse("2003-05-21", false)); @@ -42,7 +55,7 @@ //assertEquals(simpleFormat1.parse("1998-03-14"), // parser.parse("14-Mar-98", false)); assertEquals(simpleFormat1.parse("1998-03-01"), - parser.parse("Mar-1998", false)); + parser.parse("March-1998", false)); assertEquals(simpleFormat1.parse("1998-03-01"), parser.parse("March-1998", false)); assertEquals(simpleFormat1.parse("1998-03-14"), @@ -99,5 +112,6 @@ // parser.parse("02/03/04", false)); //assertEquals(simpleFormat1.parse("1999-03-04"), // parser.parse("99/03/04", false)); + } } Modified: core/trunk/src/jumptest/junit/GMLWriterTestCase.java =================================================================== --- core/trunk/src/jumptest/junit/GMLWriterTestCase.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/jumptest/junit/GMLWriterTestCase.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -1,6 +1,7 @@ package jumptest.junit; import java.text.SimpleDateFormat; +import java.util.Locale; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.GeometryFactory; @@ -32,15 +33,19 @@ public void testToString() throws Exception { doAssert("ABC 123", "ABC 123", AttributeType.STRING); - doAssert("", null, AttributeType.STRING); + doAssert(null, null, AttributeType.STRING); doAssert("", "", AttributeType.STRING); doAssert(" ", " ", AttributeType.STRING); - doAssert("1.23", new Double(1.23), AttributeType.DOUBLE); - doAssert("", null, AttributeType.DOUBLE); - doAssert("4", new Integer(4), AttributeType.INTEGER); - doAssert("", null, AttributeType.INTEGER); - doAssert(dateFormatter.format(new FlexibleDateParser().parse("April 18, 1921", false)), new FlexibleDateParser().parse("1921-04-18", false), AttributeType.DATE); - doAssert("", null, AttributeType.DATE); + doAssert("1.23", 1.23, AttributeType.DOUBLE); + doAssert(null, null, AttributeType.DOUBLE); + doAssert("4", 4, AttributeType.INTEGER); + doAssert(null, null, AttributeType.INTEGER); + if (Locale.getDefault().getLanguage().equals("fr")) { + doAssert(dateFormatter.format(new FlexibleDateParser().parse("18 Avril 1921", false)), new FlexibleDateParser().parse("1921-04-18", false), AttributeType.DATE); + } else{ + doAssert(dateFormatter.format(new FlexibleDateParser().parse("April 18, 1921", false)), new FlexibleDateParser().parse("1921-04-18", false), AttributeType.DATE); + } + doAssert(null, null, AttributeType.DATE); try { doAssert("", factory.createPoint(new Coordinate()), Modified: core/trunk/src/jumptest/junit/ValidatorTestCase.java =================================================================== --- core/trunk/src/jumptest/junit/ValidatorTestCase.java 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/jumptest/junit/ValidatorTestCase.java 2016-03-23 21:30:03 UTC (rev 4860) @@ -16,6 +16,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.List; public class ValidatorTestCase extends TestCase { @@ -29,7 +30,7 @@ } private class TestValidator extends Validator { - protected void addIfNotNull(Object item, Collection collection) { + protected void addIfNotNull(Object item, Collection<Object> collection) { super.addIfNotNull(item, collection); } protected ValidationError validateNoRepeatedConsecutivePoints(Feature feature) { @@ -64,7 +65,7 @@ private TestValidator testValidator; public void testAddIfNotNull() { - ArrayList list = new ArrayList(); + List<Object> list = new ArrayList<>(); assertTrue(list.isEmpty()); testValidator.addIfNotNull(null, list); assertTrue(list.isEmpty()); @@ -85,7 +86,7 @@ assertTypeEquals(null, testValidator.validateGeometryClass(toFeature("POINT EMPTY"))); assertTypeEquals(ValidationErrorType.GEOMETRY_CLASS_DISALLOWED, testValidator.validateGeometryClass(toFeature("LINESTRING EMPTY"))); - assertTypeEquals(null, testValidator.validateGeometryClass(toFeature(new LinearRing(null, null, 0)))); + assertTypeEquals(null, testValidator.validateGeometryClass(toFeature("LINEARRING EMPTY"))); assertTypeEquals(null, testValidator.validateGeometryClass(toFeature("POLYGON EMPTY"))); } @@ -266,14 +267,14 @@ } public void testValidateGeometriesSimple() { - testValidator.setCheckingLineStringsSimple(true); + testValidator.setCheckingGeometriesSimple(true); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("GEOMETRYCOLLECTION EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("MULTIPOINT EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("MULTILINESTRING EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("MULTIPOLYGON EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("POINT EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("LINESTRING EMPTY"))); - assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature(new LinearRing(null, null, 0)))); + assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("LINEARRING EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature("POLYGON EMPTY"))); assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature( @@ -290,9 +291,8 @@ assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature( "LINESTRING(0 0, 10 10, 10 0, 0 0)"))); - assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature(new LinearRing(new Coordinate[] { - new Coordinate(0, 0), new Coordinate(10, 10), new Coordinate(10, 0), - new Coordinate(0, 0)}, null, 0)))); + assertTypeEquals(null, testValidator.validateGeometriesSimple(toFeature( + "LINEARRING(0 0, 10 10, 10 0, 0 0)"))); } public void testValidatePolygonOrientation() { @@ -303,7 +303,7 @@ assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature("MULTIPOLYGON EMPTY"))); assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature("POINT EMPTY"))); assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature("LINESTRING EMPTY"))); - assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature(new LinearRing(null, null, 0)))); + assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature("LINEARRING EMPTY"))); assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature("POLYGON EMPTY"))); assertTypeEquals(null, testValidator.validatePolygonOrientation(toFeature( Modified: core/trunk/src/language/jump.properties =================================================================== --- core/trunk/src/language/jump.properties 2016-03-23 17:52:32 UTC (rev 4859) +++ core/trunk/src/language/jump.properties 2016-03-23 21:30:03 UTC (rev 4860) @@ -1804,7 +1804,6 @@ qa.ValidationErrorType.contains-segments-with-angle-below-minimum = Contains Segments With Angle Below Minimum qa.ValidationErrorType.geometry-class-not-allowed = Geometry Class Not Allowed qa.ValidationErrorType.is-contain-polygon-with-area-below-minimum = Is/Contains Polygon With Area Below Minimum -#qa.ValidationErrorType.linestring-not-simple = Linestring Not Simple qa.ValidationErrorType.non-simple = Non Simple Geometry qa.ValidationErrorType.polygon-has-holes = Polygon Has Holes qa.ValidationErrorType.polygon-hole-is-oriented-clockwise = Polygon Hole Is Oriented Clockwise ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785351&iu=/4140 _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel