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

merges Parser into Coord and removes Parse class

parent 36262b8b
No related branches found
No related tags found
No related merge requests found
......@@ -48,12 +48,12 @@ class Coord
Coord coord = null;
pubdid = Parser.getFirstString(params, "ID");
String[] circle = Parser.getFirstStringArray(params,"CIRCLE", " ", 3);
String[] vel = Parser.getFirstStringArray(params,"BAND", " ", 2);
pubdid = getFirstString(params, "ID");
String[] circle = getFirstStringArray(params,"CIRCLE", " ", 3);
String[] vel = getFirstStringArray(params,"BAND", " ", 2);
String skySystem = Parser.getFirstString(params, "skysystem"); // FIXME add sanity checks / use enum
String skySystem = getFirstString(params, "skysystem"); // FIXME add sanity checks / use enum
if(skySystem == null) skySystem = "ICRS";
this.skySystem = skySystem;
......@@ -65,7 +65,7 @@ class Coord
this.shape = "CIRCLE";
String specSystem = Parser.getFirstString(params, "specsystem");
String specSystem = getFirstString(params, "specsystem");
if(specSystem == null) specSystem = "2"; // 2=WAVE BARY
if( (vel != null) && (vel.length >= 2) )
{
......@@ -349,6 +349,33 @@ class Coord
return sb.toString();
}
String getFirstString(Map<String, String[]> params, String key)
{
String[] values = params.get(key);
if (values == null) return null;
if (values.length < 1)
throw new IllegalArgumentException(key + " has no valid value");
else
return values[0];// FIXME if values[0] is null -> canot distinguish from key not found
}
String[] getFirstStringArray(Map<String, String[]> params, String key, String separator, int arrayLength)
{
String array = getFirstString(params, key);
if (array == null) return null;
String[] stringArray = array.split(separator);
if(stringArray.length != arrayLength)
throw new IllegalArgumentException(
key + " parameter has incorrect number of elements ("
+ stringArray.length + " vs " + arrayLength + ") or incorrect separator used");
return stringArray;
}
......
import java.util.Map;
class Parser
{
static String getFirstString(Map<String, String[]> params, String key)
{
String[] values = params.get(key);
if (values == null) return null;
if (values.length < 1)
throw new IllegalArgumentException(key + " has no valid value");
else
return values[0];// FIXME if values[0] is null -> canot distinguish from key not found
}
static String[] getFirstStringArray(Map<String, String[]> params, String key, String separator, int arrayLength)
{
String array = getFirstString(params, key);
if (array == null) return null;
String[] stringArray = array.split(separator);
if(stringArray.length != arrayLength)
throw new IllegalArgumentException(
key + " parameter has incorrect number of elements ("
+ stringArray.length + " vs " + arrayLength + ") or incorrect separator used");
return stringArray;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment