-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cursor position tool should consider locale when parsing coord string #330
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
87576ae
cursor position tool should consider locale when parsing coord string
nprigour f052946
further enhance parse() using StringUtils method and improve
nprigour 15e9997
create Locale TestRule and split CursorPosition testing to separate
nprigour cae6819
improve error handling of Coordinate.parse(...) method
nprigour f6bd6f8
test code refactoring and fix of erroneous if statement in
nprigour ddcaebf
rename Locale specific CursorPosition Test classes
nprigour a1633ea
apply udig format style to CursorPosition and associated test classes
nprigour File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...h.udig.tool.default.tests/src/org/locationtech/udig/tool/tests/CursorPositionTest_FR.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* uDig - User Friendly Desktop Internet GIS client | ||
* http://udig.refractions.net | ||
* (C) 2012, Refractions Research Inc. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD | ||
* License v1.0 (http://udig.refractions.net/files/bsd3-v10.html). | ||
*/ | ||
package org.locationtech.udig.tool.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Locale; | ||
|
||
import org.geotools.referencing.crs.DefaultGeographicCRS; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.locationtech.udig.tools.internal.CursorPosition; | ||
|
||
import com.vividsolutions.jts.geom.Coordinate; | ||
|
||
public class CursorPositionTest_FR extends CursorPositionTest { | ||
|
||
@Rule public final DefaultLocaleRule defaultLocaleRule = new DefaultLocaleRule(Locale.FRENCH); | ||
@Test | ||
public void testParseString() throws Exception { | ||
|
||
//System.out.println(Locale.getDefault()); | ||
|
||
// Locales with ',' as decimal operator should work correctly | ||
Coordinate coord = CursorPosition.parse(" 124,88 234,22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
assertEquals(new Coordinate(124.88, 234.22), coord); | ||
|
||
// Locales with ',' as decimal operator should NOT work correctly | ||
coord = CursorPosition.parse(" 124.88, 234.22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
assertEquals(new Coordinate(124.88, 234.22), coord); | ||
|
||
// Locales with ',' as decimal operator should NOT work correctly | ||
coord = CursorPosition.parse(" 124,88, 234,22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
assertEquals(new Coordinate(124.88, 234.22), coord); | ||
|
||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...h.udig.tool.default.tests/src/org/locationtech/udig/tool/tests/CursorPositionTest_US.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* uDig - User Friendly Desktop Internet GIS client | ||
* http://udig.refractions.net | ||
* (C) 2012, Refractions Research Inc. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* (http://www.eclipse.org/legal/epl-v10.html), and the Refractions BSD | ||
* License v1.0 (http://udig.refractions.net/files/bsd3-v10.html). | ||
*/ | ||
package org.locationtech.udig.tool.tests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import java.util.Locale; | ||
|
||
import org.geotools.referencing.crs.DefaultGeographicCRS; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.locationtech.udig.tools.internal.CursorPosition; | ||
|
||
import com.vividsolutions.jts.geom.Coordinate; | ||
|
||
public class CursorPositionTest_US extends CursorPositionTest { | ||
|
||
@Rule public final DefaultLocaleRule defaultLocaleRule = new DefaultLocaleRule(Locale.US); | ||
@Test | ||
public void testParseString() throws Exception { | ||
|
||
//System.out.println(Locale.getDefault()); | ||
|
||
// Locales with '.' as decimal operator parsing of numbers with ',' | ||
// causes a problem | ||
Coordinate coord = CursorPosition.parse(" 124,88 234,22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
// wrong parsing due to wrongly used decimal seperator | ||
assertEquals(new Coordinate(124, 88), coord); | ||
|
||
// Locales with ',' as decimal operator should NOT work correctly | ||
coord = CursorPosition.parse(" 124.88, 234.22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
assertEquals(new Coordinate(124.88, 234.22), coord); | ||
|
||
// Locales with ',' as decimal operator should NOT work correctly | ||
coord = CursorPosition.parse(" 124,88, 234,22", DefaultGeographicCRS.WGS84); //$NON-NLS-1$ | ||
assertNotEquals(new Coordinate(124.88, 234.22), coord); | ||
|
||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
...ntech.udig.tool.default.tests/src/org/locationtech/udig/tool/tests/DefaultLocaleRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.locationtech.udig.tool.tests; | ||
|
||
import java.util.Locale; | ||
import org.junit.rules.TestRule; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
/** JUnit rule for taking control over the Locale. */ | ||
public final class DefaultLocaleRule implements TestRule { | ||
final Locale preference; | ||
|
||
/** Creates the rule and will restore the default locale for each test. */ | ||
public DefaultLocaleRule() { | ||
preference = null; | ||
} | ||
|
||
/** Creates the rule and will set the preferred locale for each test. */ | ||
public DefaultLocaleRule(final Locale preference) { | ||
this.preference = preference; | ||
} | ||
|
||
@Override public Statement apply(final Statement base, final Description description) { | ||
return new Statement() { | ||
@Override public void evaluate() throws Throwable { | ||
final Locale defaultLocale = Locale.getDefault(); | ||
|
||
try { | ||
if (preference != null) { | ||
Locale.setDefault(preference); | ||
} | ||
|
||
base.evaluate(); | ||
} finally { | ||
Locale.setDefault(defaultLocale); | ||
} | ||
} | ||
}; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess regarding Eclipse IP its not allowed to copy code from other projects. So it can inspire uDig but this class needs to be re-written or we add a dependency to the project to use it as a library.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class is quite elementary in terms of behavior and applied logic. Would it be OK if I just rename it (for example ConfigureLocaleRule) and possibly alter a couple of Comments