finterval.patch
| src/com/iver/cit/gvsig/fmap/rendering/FInterval.java (working copy) | ||
|---|---|---|
| 40 | 40 |
*/ |
| 41 | 41 |
package com.iver.cit.gvsig.fmap.rendering; |
| 42 | 42 | |
| 43 |
import java.util.regex.Matcher; |
|
| 44 |
import java.util.regex.Pattern; |
|
| 45 | ||
| 43 | 46 |
import com.hardcode.gdbms.engine.values.DateValue; |
| 44 | 47 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
| 45 | 48 |
import com.hardcode.gdbms.engine.values.FloatValue; |
| ... | ... | |
| 124 | 127 |
* @return FInterval nuevo. |
| 125 | 128 |
*/ |
| 126 | 129 |
public static IInterval create(String s) {
|
| 127 |
String[] str = s.split("-");
|
|
| 128 |
if (s.startsWith("-")) {
|
|
| 129 |
str[0]="-"+str[1]; |
|
| 130 |
s.replaceFirst("-","");
|
|
| 131 |
str[1]=str[2]; |
|
| 132 |
} |
|
| 133 |
if (s.contentEquals(new StringBuffer("--"))) {
|
|
| 134 |
str[1]=s.substring(s.indexOf('-')+1,s.length()-1);
|
|
| 130 |
Pattern pattern = Pattern.compile("(-?[^-]*)-(-?.*)");
|
|
| 131 |
Matcher matcher = pattern.matcher(s); |
|
| 132 |
IInterval inter=new NullIntervalValue(); // temporal pessimism |
|
| 133 |
if (matcher.find()) {
|
|
| 134 |
try{
|
|
| 135 |
inter = new FInterval(Double.parseDouble(matcher.group(1)), |
|
| 136 |
Double.parseDouble(matcher.group(2))); |
|
| 137 |
}catch (NumberFormatException e) {
|
|
| 138 |
} |
|
| 135 | 139 |
} |
| 136 | 140 | |
| 137 |
IInterval inter=null; |
|
| 138 |
try{
|
|
| 139 |
inter = new FInterval(Double.parseDouble(str[0]), |
|
| 140 |
Double.parseDouble(str[1])); |
|
| 141 |
}catch (NumberFormatException e) {
|
|
| 142 |
return new NullIntervalValue(); |
|
| 143 |
} |
|
| 144 | 141 |
return inter; |
| 145 | 142 |
} |
| 146 | 143 |
} |
| src-test/com/iver/cit/gvsig/fmap/AllTests.java (working copy) | ||
|---|---|---|
| 25 | 25 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
| 26 | 26 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
| 27 | 27 |
import com.iver.cit.gvsig.fmap.layers.LayersIteratorTest; |
| 28 |
import com.iver.cit.gvsig.fmap.rendering.FIntervalTest; |
|
| 28 | 29 |
import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexTest; |
| 29 | 30 |
import com.iver.cit.gvsig.fmap.tools.AreaListenerTest; |
| 30 | 31 |
import com.vividsolutions.jts.operation.overlay.SnappingOverlayOperationTest; |
| ... | ... | |
| 95 | 96 |
suite.addTestSuite(SpatialIndexTest.class); |
| 96 | 97 |
suite.addTestSuite(TestDbf.class); |
| 97 | 98 |
suite.addTestSuite(TestDgn.class); |
| 99 |
|
|
| 100 |
suite.addTestSuite(FIntervalTest.class); |
|
| 98 | 101 | |
| 99 | 102 |
//$JUnit-END$ |
| 100 | 103 |
return suite; |
| src-test/com/iver/cit/gvsig/fmap/rendering/FIntervalTest.java (revision 0) | ||
|---|---|---|
| 1 |
package com.iver.cit.gvsig.fmap.rendering; |
|
| 2 | ||
| 3 |
import junit.framework.TestCase; |
|
| 4 | ||
| 5 |
public class FIntervalTest extends TestCase {
|
|
| 6 | ||
| 7 |
private static final double DELTA = 0.000001; |
|
| 8 | ||
| 9 |
public void testNegativeIntervals() throws Exception {
|
|
| 10 |
testNegativeInterval("-2.1--1.1", -2, -1.1);
|
|
| 11 |
testNegativeInterval("-2.1-1.1", -2.1, 1.1);
|
|
| 12 |
testNegativeInterval("2.1--1", 2.1, -1);
|
|
| 13 |
testNegativeInterval("1.1-2", 1.1, 2);
|
|
| 14 |
} |
|
| 15 | ||
| 16 |
private void testNegativeInterval(String intervalString, double min, |
|
| 17 |
double max) {
|
|
| 18 |
FInterval interval = (FInterval) FInterval.create(intervalString); |
|
| 19 |
assertTrue(interval.getMin() - min < DELTA); |
|
| 20 |
assertTrue(interval.getMax() - max < DELTA); |
|
| 21 |
} |
|
| 22 |
} |
|