20 package com.generalrobotix.ui.util;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.text.NumberFormat;
26 import java.util.Properties;
30 @SuppressWarnings(
"serial")
56 public void load(String fname)
throws IOException {
57 FileInputStream in =
new FileInputStream(fname);
68 public void store(String fname,String comments)
throws IOException{
69 FileOutputStream out =
new FileOutputStream(fname);
78 public final String
getStr(String key){
82 str = getProperty(key, System.getenv(key));
83 buf =
new StringBuffer(str);
84 }
catch (java.util.MissingResourceException ex){
87 }
catch (NullPointerException e){
94 if ((index1 = buf.indexOf(
"$(")) == -1)
96 if ((index2 = buf.indexOf(
")" ,index1)) != -1){
99 String
keyword = buf.substring(index1+2,index2);
100 String
prop = System.getProperty(keyword);
104 prop = System.getenv(keyword);
106 prop = getStr(keyword,
"");
109 buf.replace(index1,index2+1,prop);
112 return buf.toString();
121 public final String
getStr(String key, String defaultVal) {
123 if ((ret= getStr(key)) ==
null)
134 public final Integer
getInt(String key, Integer defaultVal) {
137 ret = Integer.parseInt(getStr(key));
138 }
catch(Exception e){
150 public final Short
getShort(String key, Short defaultVal) {
151 Short
ret = getShort(getStr(key));
167 ret = Short.parseShort(value);
168 }
catch(Exception e){
180 String
val =
new String();
181 val += String.valueOf(value)+
" ";
182 setProperty(key,val);
191 String s = getStr(key);
194 String[] str = s.split(
" ");
196 ret =
new int[str.length];
198 for (
int i=0;
i<str.length;
i++)
199 ret[
i] = Integer.parseInt(str[
i]);
212 public final Double
getDbl(String key, Double defaultVal) {
213 Double
ret = getDbl(getStr(key));
229 ret = Double.parseDouble(value);
230 }
catch(Exception e){
242 public final Float
getFlt(String key, Float defaultVal) {
245 ret = Float.parseFloat(getStr(key));
246 }
catch(Exception e){
255 ret = Float.parseFloat(value);
256 }
catch(Exception e){
268 public final double[]
getDblAry(String key,
double[] defaultVal){
269 String s = getStr(key);
270 double[]
ret = getDblAry(s);
285 String[] str = value.split(
" ");
286 double[]
ret =
new double[str.length];
288 for (
int i=0;
i<str.length;
i++)
289 ret[
i] = Double.parseDouble(str[
i]);
290 }
catch(Exception e){
302 public final float[]
getFltAry(String key,
float[] defaultVal){
303 String s = getStr(key);
306 String[] str = s.split(
" ");
307 float[]
ret =
new float[str.length];
309 for (
int i=0;
i<str.length;
i++)
310 ret[
i] = Float.parseFloat(str[
i]);
311 }
catch(Exception e){
320 String[] str = value.split(
" ");
321 float[]
ret =
new float[str.length];
323 for (
int i=0;
i<str.length;
i++)
324 ret[
i] = Float.parseFloat(str[
i]);
325 }
catch(Exception e){
338 String
val =
new String();
339 NumberFormat nf = NumberFormat.getInstance();
340 nf.setMaximumFractionDigits(digits);
341 for (
int i=0;
i<value.length;
i++) {
342 if (Double.isNaN(value[
i])){
345 val += nf.format(value[i])+
" ";
348 setProperty(key,val);
357 String
val =
new String();
358 for (
int i=0;
i<value.length;
i++) {
359 val += String.valueOf(value[
i])+
" ";
361 setProperty(key,val);
370 String
val =
new String();
371 val += String.valueOf(value)+
" ";
372 setProperty(key,val);
381 String
val =
new String();
382 for (
int i=0;
i<value.length;
i++) {
383 val += String.valueOf(value[
i])+
" ";
385 setProperty(key,val);
394 String
val =
new String();
395 val += String.valueOf(value)+
" ";
396 setProperty(key,val);
406 String
val =
new String();
407 NumberFormat nf = NumberFormat.getInstance();
408 nf.setMaximumFractionDigits(digits);
409 val += nf.format(value)+
" ";
410 setProperty(key,val);
419 String
val =
new String();
420 val += String.valueOf(value)+
" ";
421 setProperty(key,val);
426 setProperty(key,
"true");
428 setProperty(key,
"false");
437 return isTrue(key,
false);
446 public final boolean isTrue(String key,
boolean defaultVal){
447 Boolean
b =
new Boolean(defaultVal);
448 String str = getStr(key,b.toString()).toLowerCase();
449 if (str.indexOf(
"true")!=-1)
460 return isFalse(key,
false);
468 public final boolean isFalse(String key,
boolean defaultVal){
469 Boolean
b =
new Boolean(defaultVal);
470 String str = getStr(key,b.toString()).toLowerCase();
471 if (str.indexOf(
"false")!=-1)
final float [] getFltAry(String key, float[] defaultVal)
get float array associated to key
final boolean isTrue(String key)
check whether value associated to key includes a word "true"
final Integer getInt(String key, Integer defaultVal)
get integer value associated to key
final double [] getDblAry(String key, double[] defaultVal)
get double array associated to key
#define null
our own NULL pointer
final void setDbl(String key, double value, int digits)
associate double value to key
GrxConfigBundle()
constructor
final void setBool(String key, boolean value)
float [] getFltAry(String value)
final Short getShort(String key, Short defaultVal)
get short value associated to key
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
final Float getFlt(String key, Float defaultVal)
get float value associated to key
final boolean isFalse(String key, boolean defaultVal)
check whether value associated to key includes a word "false"
final void setFltAry(String key, float[] value)
associate float array to key
final void setDbl(String key, double value)
associate double value to key
static void printErr(String s)
static Activator getDefault()
final void setDblAry(String key, double[] value)
associate double array to key
final void setInt(String key, int value)
associate int value to key
Short getShort(String value)
final void setFlt(String key, float value)
associate float value to key
static void println(String s)
final void setShort(String key, short value)
associate short value to key
final Double getDbl(String key, Double defaultVal)
get double value associated to key
final Float getFlt(String value)
final int [] getIntAry(String key)
get integer array associated to key
final String getStr(String key)
get value associated to keyword
double [] getDblAry(String value)
get array of double from String
void load(String fname)
load config from a file
void store(String fname, String comments)
store this config
GrxConfigBundle(String fname)
construct from a file
final boolean isTrue(String key, boolean defaultVal)
check whether value associated to key includes a word "true"
final void setDblAry(String key, double[] value, int digits)
associate double array to key
Double getDbl(String value)
final boolean isFalse(String key)
check whether value associated to key includes a word "false"
final String getStr(String key, String defaultVal)
get value associated to key