/** * Copy this parameter.to the specified parent parameter set * while changing its name. * @param parent the parameter set into which to copy this parameter; * the parent of the destination parameter. * If the parent is null, the destination parameter will be an orphan. * @param name the destination parameter name. * @return the destination parameter. */ public Parameter copyTo(ParameterSet parent, String name) { if (_parent==parent && _name==name) return this; Parameter p = (parent!=null)?parent.addParameter(name):new Parameter(name); p.setUnits(getUnits()); p.setValues(getValues()); return p; }
/** * Tests if parameter type is double. * @return true, if parameter type is double; false, otherwise. */ public boolean isDouble() { return (getType()==DOUBLE); }
public void testParameter() { Parameter par = new Parameter("fo<o","Hello"); assertTrue(par.getString().equals("Hello")); par.setString("true"); assertTrue(par.getBoolean()); par.setString("3141"); assertTrue(par.getInt()==3141); par.setString("3141.0"); assertTrue(par.getFloat()==3141.0f); par.setString("3.141"); assertTrue(par.getDouble()==3.141); double[] empty = new double[0]; par.setDoubles(empty); assertTrue(par.getType()==Parameter.DOUBLE); par.setFloats(null); assertTrue(par.getType()==Parameter.FLOAT); float[] fvalues = {1.2f,3.4f}; par.setFloats(fvalues); fvalues = par.getFloats(); assertTrue(fvalues[0]==1.2f); assertTrue(fvalues[1]==3.4f); par.setUnits("km/s"); assertTrue(par.getUnits().equals("km/s")); boolean[] bvalues = {true,false}; par.setBooleans(bvalues); bvalues = par.getBooleans(); assertTrue(bvalues[0]); assertTrue(!bvalues[1]); par.setUnits(null); assertTrue(par.getUnits()==null);
pb1.setBoolean(true); Parameter pi1 = ss1.addParameter("pi1"); pi1.setInt(1); Parameter pf1 = ss1.addParameter("pf1"); pf1.setFloat(1.0f); Parameter pd1 = ss1.addParameter("pd1"); pd1.setDouble(1.0); Parameter ps1 = ss1.addParameter("ps1"); ps1.setString("1.0"); assertTrue(pfind==null); boolean b1 = ss1.getParameter("pb1").getBoolean(); assertTrue(b1); int i1 = ss1.getParameter("pi1").getInt(); assertTrue(i1==1); float f1 = ss1.getParameter("pf1").getFloat(); assertTrue(f1==1.0f); double d1 = ss1.getParameter("pd1").getDouble(); assertTrue(d1==1.0); String s1 = ss1.getParameter("ps1").getString(); assertTrue(s1.equals("1.0"));
if (getType() != other.getType()) return false; int nvalues = countValues(); if (nvalues!=other.countValues()) return false; int type = getType(); if (type==BOOLEAN) { boolean[] values = (boolean[])_values;
public void testSpecialCharacters() { ParameterSet root = new ParameterSet("foo<&>\"\'\\ bar"); Parameter foo = root.addParameter("foo"); String[] sa = { "foo", "foo<&>\"\'\\ bar", "foo\nbar", "foo\\nbar", "foo\tbar", "foo\\tbar", "foo\"bar", "foo\\", "foo \\", }; foo.setStrings(sa); String s1 = root.toString(); //System.out.print(s1); root.fromString(s1); String s2 = root.toString(); //System.out.print(s2); assertTrue(s1.equals(s2)); foo = root.getParameter("foo"); String[] sb = foo.getStrings(); assertTrue(sa.length==sb.length); for (int i=0; i<sa.length; ++i) { assertTrue(sa[i].equals(sb[i])); } }
/** * Get the double value of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValue default value returned if this parameter set * does not contain a parameter with the specified name. * @return parameter value or default value. * @exception ParameterConvertException if the parameter value cannot be * converted to double. */ public double getDouble(String name, double defaultValue) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getDouble():defaultValue; }
/** * Get the boolean value of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValue default value returned if this parameter set * does not contain a parameter with the specified name. * @return parameter value or default value. * @exception ParameterConvertException if the parameter value cannot be * converted to boolean. */ public boolean getBoolean(String name, boolean defaultValue) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getBoolean():defaultValue; }
/** * Get the int value of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValue default value returned if this parameter set * does not contain a parameter with the specified name. * @return parameter value or default value. * @exception ParameterConvertException if the parameter value cannot be * converted to int. */ public int getInt(String name, int defaultValue) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getInt():defaultValue; }
/** * Get the float values of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValues default values returned if this parameter set * does not contain a parameter with the specified name. * @return parameter values or default values. * @exception ParameterConvertException if the parameter values cannot be * converted to float. */ public float[] getFloats(String name, float[] defaultValues) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getFloats():defaultValues; }
/** * Get the boolean values of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValues default values returned if this parameter set * does not contain a parameter with the specified name. * @return parameter values or default values. * @exception ParameterConvertException if the parameter values cannot be * converted to boolean. */ public boolean[] getBooleans(String name, boolean[] defaultValues) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getBooleans():defaultValues; }
/** * Get the String values of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValues default values returned if this parameter set * does not contain a parameter with the specified name. * @return parameter values or default values. * @exception ParameterConvertException if the parameter values cannot be * converted to String. */ public String[] getStrings(String name, String[] defaultValues) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getStrings():defaultValues; }
/** * Add a new parameter to this parameter set. * If this parameter set already contains a parameter or subset * with the specified name, replace that parameter or subset with * with the new parameter. * @param name name of the parameter to add. * @return parameter; null, if name is null. */ public Parameter addParameter(String name) { if (name==null) return null; Parameter par = new Parameter(name); insert(name,par); return par; }
/** * Get the float value of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValue default value returned if this parameter set * does not contain a parameter with the specified name. * @return parameter value or default value. * @exception ParameterConvertException if the parameter value cannot be * converted to float. */ public float getFloat(String name, float defaultValue) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getFloat():defaultValue; }
/** * Get the String value of a named parameter in this parameter set. * @param name name of the parameter. * @param defaultValue default value returned if this parameter set * does not contain a parameter with the specified name. * @return parameter value or default value. * @exception ParameterConvertException if the parameter value cannot be * converted to String. */ public String getString(String name, String defaultValue) throws ParameterConvertException { Parameter par = getParameter(name); return (par!=null)?par.getString():defaultValue; }
String name = (_name!=null)?_name:"name"; String units = (_units!=null)?_units:"units"; int type = getType(); int code = name.hashCode()^units.hashCode()^type; int nvalues = countValues(); if (type==BOOLEAN) { boolean[] values = (boolean[])_values;
/** * Tests if parameter type is null. * @return true, if parameter type is null; false, otherwise. */ public boolean isNull() { return (getType()==NULL); }
/** * Tests if parameter type is String. * @return true, if parameter type is String; false, otherwise. */ public boolean isString() { return (getType()==STRING); }
/** * Tests if parameter type is long. * @return true, if parameter type is long; false, otherwise. */ public boolean isLong() { return (getType()==LONG); }
/** * Tests if parameter type is boolean. * @return true, if parameter type is boolean; false, otherwise. */ public boolean isBoolean() { return (getType()==BOOLEAN); }