Go to the documentation of this file.
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){
80 StringBuffer
buf =
null;
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);
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();
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);
284 if (
value ==
null)
return null;
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){
319 if (
value ==
null)
return null;
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])){
348 setProperty(key,
val);
357 String
val =
new String();
358 for (
int i=0;
i<
value.length;
i++) {
361 setProperty(key,
val);
370 String
val =
new String();
372 setProperty(key,
val);
381 String
val =
new String();
382 for (
int i=0;
i<
value.length;
i++) {
385 setProperty(key,
val);
394 String
val =
new String();
396 setProperty(key,
val);
406 String
val =
new String();
407 NumberFormat nf = NumberFormat.getInstance();
408 nf.setMaximumFractionDigits(digits);
410 setProperty(key,
val);
419 String
val =
new String();
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)
static void printErr(String s)
final void setDblAry(String key, double[] value, int digits)
associate double array to key
static void println(String s)
final void setDblAry(String key, double[] value)
associate double array to key
static Activator getDefault()
final Float getFlt(String value)
float[] getFltAry(String value)
final Integer getInt(String key, Integer defaultVal)
get integer value associated to key
final boolean isFalse(String key)
check whether value associated to key includes a word "false"
final double[] getDblAry(String key, double[] defaultVal)
get double array associated to key
final boolean isTrue(String key, boolean defaultVal)
check whether value associated to key includes a word "true"
final void setFltAry(String key, float[] value)
associate float array to key
double[] getDblAry(String value)
get array of double from String
final void setBool(String key, boolean value)
final boolean isTrue(String key)
check whether value associated to key includes a word "true"
final String getStr(String key)
get value associated to keyword
final void setDbl(String key, double value)
associate double value to key
GrxConfigBundle(String fname)
construct from a file
final void setFlt(String key, float value)
associate float value to key
Short getShort(String value)
final Float getFlt(String key, Float defaultVal)
get float value associated to key
void store(String fname, String comments)
store this config
final void setShort(String key, short value)
associate short value to key
final void setInt(String key, int value)
associate int value to key
final String getStr(String key, String defaultVal)
get value associated to key
final float[] getFltAry(String key, float[] defaultVal)
get float array associated to key
final int[] getIntAry(String key)
get integer array associated to key
Double getDbl(String value)
final Double getDbl(String key, Double defaultVal)
get double value associated to key
void load(String fname)
load config from a file
GrxConfigBundle()
constructor
final void setDbl(String key, double value, int digits)
associate double value to key
final boolean isFalse(String key, boolean defaultVal)
check whether value associated to key includes a word "false"
final Short getShort(String key, Short defaultVal)
get short value associated to key
openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:02