Skip to content
Snippets Groups Projects
Commit 5a4ae663 authored by Robert Butora's avatar Robert Butora
Browse files

cleans up Corrd (and removes last remaining & escapes)

parent 480ae8c8
No related branches found
No related tags found
No related merge requests found
...@@ -146,94 +146,109 @@ class Coord ...@@ -146,94 +146,109 @@ class Coord
} }
// if param present -> must have at least one value
static private String getFirstValue(Map<String, String[]> map, String key)
{
String[] value = map.get(key);
if(value == null) void setSkySystem(String skySystem) { this.skySystem = skySystem; }
return null; void setSpecSystem(String velType) { this.vel_type = velType; }
if(value.length > 0) // key-value present at least once: return first occurance void setVelocity(double vel_low, double vel_up, String vel_type)
return value[0].toString(); {
else // length=0: no values present (array exists but is empty) this.vel_type = vel_type;
throw new IllegalArgumentException("parameter " + key + " has no value."); this.vel_low = vel_low;
this.vel_up = vel_up;
this.vel_valid = true;
} }
/*
Coord(String lon, String lat, String radius, String velLow, String velUp)
{
try
// generate cutout/merge queryStrings
String toQueryString()
{ {
this.skySystem = "GALACTIC"; if(API_VLKB_legacy)
this.lon = Double.parseDouble(lon); return toVlkbLegacyQueryString();
this.lat = Double.parseDouble(lat); else
this.radius = Double.parseDouble(radius); return toVoQueryString();
} }
catch(Exception e)
String toVlkbLegacyQueryString()
{ {
throw new IllegalArgumentException("lon and lat are mandatory: " + e.getMessage()); LOGGER.info("trace");
}
if(this.radius <= 0.0) throw new IllegalArgumentException("radius must be positive and not zero"); StringBuilder sb = new StringBuilder();
this.shape = "CIRCLE"; sb.append("skysystem=" + skySystem);
sb.append("&l=" + lon );
sb.append("&b=" + lat );
if((velLow != null) && (velUp != null)) switch(shape)
{ {
this.vel_low = Double.parseDouble(velLow); case "CIRCLE" : sb.append("&r=" + radius );
this.vel_up = Double.parseDouble(velUp); break;
this.vel_type = "1"; // VELO + LSRK case "RECT" :
//this.vel_type = "2"; // WAVE + Barycentric sb.append("&dl=" + dlon );
this.vel_valid = true; sb.append("&db=" + dlat );
break;
default:
LOGGER.info("Coord::toVlkbLegacyQueryString: unknown shape: " + shape);
} }
else
if(vel_valid)
{ {
this.vel_valid = false; sb.append("&vl=" + vel_low);
sb.append("&vu=" + vel_up );
sb.append("&specsystem=" + vel_type );
} }
return sb.toString();
} }
String toVoQueryString()
{
LOGGER.info("trace");
StringBuilder sb = new StringBuilder();
sb.append("skysystem=" + skySystem);
Coord(double lon, double lat, double radius) switch(shape)
{ {
if(radius < 0.0) case "CIRCLE" :
throw new IllegalArgumentException("radius must be bigger than zero: " + radius); sb.append("&POS=CIRCLE " + lon + " " + lat + " " + + radius );
break;
this.skySystem = "GALACTIC"; case "RECT" :
this.lon = lon; if(vel_valid)
this.lat = lat; sb.append("&POS=RANGE="
this.radius = radius; + " " + (lon - dlon) + " " + (lon + dlon)
this.shape = "CIRCLE"; + " " + (lat - dlat) + " " + (lat + dlat)
this.vel_valid = false; + " " + vel_low + " " + vel_up );
else
sb.append("&POS=RANGE="
+ " " + (lon - dlon) + " " + (lon + dlon)
+ " " + (lat - dlat) + " " + (lat + dlat) );
break;
default:
LOGGER.info("Coord::toVoQueryString: unknown shape: " + shape);
} }
Coord(double lon, double lat, double dlon, double dlat) if(vel_valid)
{ {
if((dlon < 0.0) || (dlat < 0.0)) sb.append("&BAND= " + vel_low + " " + vel_up);
throw new IllegalArgumentException("both dlon and dlat must be bigger than zero: " + dlon + " " + dlat); sb.append("&specsystem=" + vel_type );
}
this.skySystem = "GALACTIC"; return sb.toString();
this.lon = lon;
this.lat = lat;
this.dlon = dlon;
this.dlat = dlat;
this.shape = "RECT";
this.vel_valid = false;
} }
*/
void setSkySystem(String skySystem) { this.skySystem = skySystem; }
void setSpecSystem(String velType) { this.vel_type = velType; }
// spectral axis
void setVelocity(double vel_low, double vel_up, String vel_type)
{
this.vel_type = vel_type;
this.vel_low = vel_low;
this.vel_up = vel_up;
this.vel_valid = true;
}
// utils // utils
...@@ -281,84 +296,24 @@ class Coord ...@@ -281,84 +296,24 @@ class Coord
} }
String toQueryString()
{
if(API_VLKB_legacy)
return toVlkbLegacyQueryString();
else
return toVoQueryString();
}
// FIXME separate keywords into dictionary key-string (LON->"l" LAT->"b" SKYSYSTEM->"skysystem")
// to be part of api/QueryStringParams.java
String toVlkbLegacyQueryString()
{
StringBuilder sb = new StringBuilder();
sb.append("skysystem=" + skySystem);
sb.append("&amp;l=" + lon );
sb.append("&amp;b=" + lat );
switch(shape)
{
case "CIRCLE" : sb.append("&amp;r=" + radius );
break;// writer.println("<r>"+String.valueOf(radius)+"</r>"); break;
case "RECT" :
sb.append("&amp;dl=" + dlon );
sb.append("&amp;db=" + dlat );
//writer.println("<dl>"+String.valueOf(dlon)+"</dl>");
//writer.println("<db>"+String.valueOf(dlat)+"</db>");
break;
default:
// ERROR internal err FIXME writer.println("<shape> unknown shape: "+ shape +" </shape>");
}
if(vel_valid)
{
sb.append("&amp;vl=" + vel_low);
sb.append("&amp;vu=" + vel_up );
sb.append("&amp;vt=" + vel_type );
// writer.println("<vl>" + String.valueOf(vel_low) +"</vl>");
// writer.println("<vu>" + String.valueOf(vel_up) +"</vu>");
// writer.println("<vtype>"+ vel_type +"</vtype>");
}
return sb.toString();
}
String toVoQueryString() // used in constructor and parseVlkb
{ // if param present -> must have at least one value
StringBuilder sb = new StringBuilder(); static private String getFirstValue(Map<String, String[]> map, String key)
sb.append("skysystem=" + skySystem);
switch(shape)
{ {
case "CIRCLE" : String[] value = map.get(key);
sb.append("&POS=CIRCLE " + lon + " " + lat + " " + + radius );
break;
case "RECT" :
if(vel_valid)
sb.append("&POS=RANGE="
+ " " + (lon - dlon) + " " + (lon + dlon)
+ " " + (lat - dlat) + " " + (lat + dlat)
+ " " + vel_low + " " + vel_up );
else if(value == null)
sb.append("&POS=RANGE=" return null;
+ " " + (lon - dlon) + " " + (lon + dlon)
+ " " + (lat - dlat) + " " + (lat + dlat) );
break;
default: if(value.length > 0) // key-value present at least once: return first occurance
;// ERROR internal err FIXME writer.println("<shape> unknown shape: "+ shape +" </shape>"); return value[0].toString();
else // length=0: no values present (array exists but is empty)
throw new IllegalArgumentException("parameter " + key + " has no value.");
} }
return sb.toString();
}
// used in parseSoda
String getFirstString(Map<String, String[]> params, String key) String getFirstString(Map<String, String[]> params, String key)
{ {
String[] values = params.get(key); String[] values = params.get(key);
...@@ -386,11 +341,4 @@ class Coord ...@@ -386,11 +341,4 @@ class Coord
return stringArray; return stringArray;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment