Skip to content

Commit

Permalink
Merge pull request #102 from pdowler/master
Browse files Browse the repository at this point in the history
DALI-1.2 updates
  • Loading branch information
pdowler authored May 8, 2024
2 parents 1f65f4f + 8574990 commit 727c836
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cadc-dali/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.2.17'
version = '1.2.18'

description = 'OpenCADC DALI library'
def git_url = 'https://github.com/opencadc/dal'
Expand Down
10 changes: 7 additions & 3 deletions cadc-dali/src/main/java/ca/nrc/cadc/dali/util/FormatFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public Format getFormat(VOTableField field) {
ret = new CircleFormat();
} else if ("polygon".equalsIgnoreCase(field.xtype)) {
ret = new PolygonFormat();
} else if ("multipolygon".equalsIgnoreCase(field.xtype)) {
ret = new MultiPolygonFormat();
} else if ("interval".equalsIgnoreCase(field.xtype)) {
ret = new DoubleIntervalFormat();
} else if (field.getArrayShape().length == 1) {
Expand All @@ -163,6 +165,8 @@ public Format getFormat(VOTableField field) {
ret = new CircleFormat();
} else if ("polygon".equalsIgnoreCase(field.xtype)) {
ret = new PolygonFormat();
} else if ("multipolygon".equalsIgnoreCase(field.xtype)) {
ret = new MultiPolygonFormat();
} else if ("interval".equalsIgnoreCase(field.xtype)) {
if (field.getArrayShape().length == 1 && field.getArrayShape()[0] == 2) {
ret = new DoubleIntervalFormat();
Expand All @@ -185,17 +189,17 @@ public Format getFormat(VOTableField field) {
if (isArray(field)) {
if ("timestamp".equalsIgnoreCase(field.xtype)) { // DALI-1.1
ret = new UTCTimestampFormat();
} else if (field.xtype != null && field.xtype.endsWith("shape")) { // DALI-1.2 prototype, ignore prefix
} else if (field.xtype != null && field.xtype.endsWith("shape")) { // DALI-1.2
ret = new ShapeFormat();
} else if ("adql:timestamp".equalsIgnoreCase(field.xtype)) {
ret = new UTCTimestampFormat();
} else if ("adql:point".equalsIgnoreCase(field.xtype)) {
ret = new STCPositionFormat();
} else if ("adql:region".equalsIgnoreCase(field.xtype)) {
ret = new STCRegionFormat();
} else if ("uuid".equalsIgnoreCase(field.xtype)) { // custom
} else if ("uuid".equalsIgnoreCase(field.xtype)) { // DALI-1.2
ret = new UUIDFormat();
} else if ("uri".equalsIgnoreCase(field.xtype)) { // custom
} else if ("uri".equalsIgnoreCase(field.xtype)) { // DALI-1.2
ret = new URIFormat();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class MultiPolygonFormat implements Format<MultiPolygon> {
private final PolygonFormat pf = new PolygonFormat();
private final DoubleArrayFormat fmt = new DoubleArrayFormat();

private static final String MP_SEPARATOR = " NaN NaN ";

public MultiPolygonFormat() {
}

Expand All @@ -96,7 +98,12 @@ public MultiPolygon parse(String s) {
return null;
}

return parseSingleNaN(s); // format is single NaN
double[] dd = fmt.parse(s);
return parseDoubleNaN(dd, s);
}

public MultiPolygon build(double[] dd) {
return parseDoubleNaN(dd, null);
}

MultiPolygon parseSingleNaN(String s) {
Expand All @@ -115,10 +122,9 @@ MultiPolygon parseSingleNaN(String s) {

return ret;
}

MultiPolygon parseDoubleNaN(String s) {
double[] dd = fmt.parse(s);

// string rep is for error messages
MultiPolygon parseDoubleNaN(double[] dd, String s) {
MultiPolygon ret = new MultiPolygon();
Polygon poly = new Polygon();
try {
Expand Down Expand Up @@ -163,7 +169,7 @@ public String format(MultiPolygon mp) {
while (i.hasNext()) {
sb.append(pf.format(i.next()));
if (i.hasNext()) {
sb.append(" NaN ");
sb.append(MP_SEPARATOR);
}
}
return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void testMultiValue() {
}
}

@Test
//@Test
public void testParseSingleNaN() throws Exception {
log.debug("testParseSingleNaN");

Expand Down Expand Up @@ -216,11 +216,11 @@ public void testParseDoubleNaN() throws Exception {

// OK
try {
MultiPolygon mp1 = format.parseDoubleNaN(noSep);
MultiPolygon mp1 = format.parse(noSep);
Assert.assertNotNull(mp1);
Assert.assertEquals(1, mp1.getPolygons().size());

MultiPolygon mp2 = format.parseDoubleNaN(singleSep);
MultiPolygon mp2 = format.parse(singleSep);
Assert.assertNotNull(mp2);
Assert.assertEquals(2, mp2.getPolygons().size());
} catch (Exception unexpected) {
Expand All @@ -230,21 +230,21 @@ public void testParseDoubleNaN() throws Exception {

// invalid
try {
MultiPolygon mp = format.parseDoubleNaN(shortBeforeSep);
MultiPolygon mp = format.parse(shortBeforeSep);
Assert.fail("expected IllegalArgumentException, got: " + mp);
} catch (IllegalArgumentException expected) {
log.info("caught expected fail: shortBeforeSep " + expected);
}

try {
MultiPolygon mp = format.parseDoubleNaN(shortAfterSep);
MultiPolygon mp = format.parse(shortAfterSep);
Assert.fail("expected IllegalArgumentException, got: " + mp);
} catch (IllegalArgumentException expected) {
log.info("caught expected fail: shortAfterSep " + expected);
}

try {
MultiPolygon mp = format.parseDoubleNaN(singleNaN);
MultiPolygon mp = format.parse(singleNaN);
Assert.fail("expected IllegalArgumentException, got: " + mp);
} catch (IllegalArgumentException expected) {
log.info("caught expected fail: doubleNaN " + expected);
Expand Down
2 changes: 1 addition & 1 deletion cadc-soda-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sourceCompatibility = 1.8

group = 'org.opencadc'

version = '1.2.3'
version = '1.2.4'

description = 'OpenCADC SODA server library'
def git_url = 'https://github.com/opencadc/dal'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class ExtensionSliceFormat implements Format<ExtensionSlice> {
private static final String PIXEL_AXIS_DELIMITER = ",";
private static final String PIXEL_VALUE_DELIMITER = ":";

private final Pattern singleRangePattern = Pattern.compile("\\*?(\\d+)?(:\\d+)?(:\\d*)?");
private final Pattern singleRangePattern = Pattern.compile("\\*?(\\d+)?(:\\d+)?(:-?\\d*)?");

public ExtensionSliceFormat() {
}
Expand Down

0 comments on commit 727c836

Please sign in to comment.