GraphProperties.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00010 package com.generalrobotix.ui.view.graph;
00011 
00012 import java.util.*;
00013 import java.io.*;
00014 import java.net.URL;
00015 
00022 public class GraphProperties {
00023 
00024     // -----------------------------------------------------------------
00025     // 定数
00026     private static final String GRAPH_PROPERTIES = "/resources/graph.properties";
00027     private static final String SEP = ".";
00028     private static final String DATA_KIND_NAMES = "dataKindNames";
00029     private static final String UNIT = "unit";
00030     private static final String BASE = "base";
00031     private static final String EXTENT = "extent";
00032     private static final String FACTOR = "factor";
00033     private static final String DATA_KIND = "dataKind";
00034 
00035     // -----------------------------------------------------------------
00036     // クラス変数
00037     private static GraphProperties this_;   // シングルトン用オブジェクトホルダ
00038     private static HashMap<String, DataKind> dataKindMap_;    // データ種別名とデータ種別の対応表
00039     private static HashMap<String, DataKind> attributeMap_;   // アトリビュートとデータ種別の対応表
00040 
00041     // -----------------------------------------------------------------
00042     // コンストラクタ
00048     private GraphProperties() {
00049         // プロパティファイルの読み込み
00050         URL url = this.getClass().getResource(GRAPH_PROPERTIES);
00051         Properties prop = new Properties();
00052         try {
00053             prop.load(url.openStream());    // プロパティファイル読み込み
00054         } catch (IOException ex) {
00055             ex.printStackTrace();
00056             System.exit(0);
00057         }
00058 
00059         // データ種別の読み込み
00060         dataKindMap_ = new HashMap<String, DataKind>();
00061         StringTokenizer dkNames =
00062             new StringTokenizer(prop.getProperty(DATA_KIND_NAMES), ",");
00063         while (dkNames.hasMoreTokens()) {
00064             String dkName = dkNames.nextToken();
00065             String unit = prop.getProperty(dkName + SEP + UNIT);
00066             double base = Double.parseDouble(prop.getProperty(dkName + SEP + BASE));
00067             double extent = Double.parseDouble(prop.getProperty(dkName + SEP + EXTENT));
00068             double factor = (
00069                 (prop.containsKey(dkName + SEP + FACTOR))
00070                 ? Double.parseDouble((String)prop.getProperty(dkName + SEP + FACTOR))
00071                 : 1
00072             );
00073             DataKind dk = new DataKind(dkName, unit, base, extent, factor);
00074             dataKindMap_.put(dkName, dk);
00075         }
00076 
00077         // アトリビュート毎のデータ種別の読み込み
00078         attributeMap_ = new HashMap<String, DataKind>();
00079         String postfix = SEP + DATA_KIND;
00080         int postfixlen = postfix.length();
00081         Enumeration elm = prop.propertyNames();
00082         while (elm.hasMoreElements()) {
00083             String pname = (String)elm.nextElement();
00084             if (pname.endsWith(postfix)) {
00085                 String aname = pname.substring(
00086                     0, pname.length() - postfixlen
00087                 );
00088                 attributeMap_.put(aname, dataKindMap_.get(prop.getProperty(pname)));
00089             }
00090         }
00091     }
00092 
00093     // -----------------------------------------------------------------
00094     // クラスメソッド
00100     public static DataKind getDataKindFromName(
00101         String dataKindName
00102     ) {
00103         if (this_ == null) {
00104             this_ = new GraphProperties();
00105         }
00106         return (DataKind)dataKindMap_.get(dataKindName);
00107     }
00108 
00114     public static DataKind getDataKindFromAttr(
00115         String attribute
00116     ) {
00117         if (this_ == null) {
00118             this_ = new GraphProperties();
00119         }
00120         return (DataKind)attributeMap_.get(attribute);
00121     }
00122 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:53