GraphProperties.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
10 package com.generalrobotix.ui.view.graph;
11 
12 import java.util.*;
13 import java.io.*;
14 import java.net.URL;
15 
22 public class GraphProperties {
23 
24  // -----------------------------------------------------------------
25  // 定数
26  private static final String GRAPH_PROPERTIES = "/resources/graph.properties";
27  private static final String SEP = ".";
28  private static final String DATA_KIND_NAMES = "dataKindNames";
29  private static final String UNIT = "unit";
30  private static final String BASE = "base";
31  private static final String EXTENT = "extent";
32  private static final String FACTOR = "factor";
33  private static final String DATA_KIND = "dataKind";
34 
35  // -----------------------------------------------------------------
36  // クラス変数
37  private static GraphProperties this_; // シングルトン用オブジェクトホルダ
38  private static HashMap<String, DataKind> dataKindMap_; // データ種別名とデータ種別の対応表
39  private static HashMap<String, DataKind> attributeMap_; // アトリビュートとデータ種別の対応表
40 
41  // -----------------------------------------------------------------
42  // コンストラクタ
48  private GraphProperties() {
49  // プロパティファイルの読み込み
50  URL url = this.getClass().getResource(GRAPH_PROPERTIES);
51  Properties prop = new Properties();
52  try {
53  prop.load(url.openStream()); // プロパティファイル読み込み
54  } catch (IOException ex) {
55  ex.printStackTrace();
56  System.exit(0);
57  }
58 
59  // データ種別の読み込み
60  dataKindMap_ = new HashMap<String, DataKind>();
61  StringTokenizer dkNames =
62  new StringTokenizer(prop.getProperty(DATA_KIND_NAMES), ",");
63  while (dkNames.hasMoreTokens()) {
64  String dkName = dkNames.nextToken();
65  String unit = prop.getProperty(dkName + SEP + UNIT);
66  double base = Double.parseDouble(prop.getProperty(dkName + SEP + BASE));
67  double extent = Double.parseDouble(prop.getProperty(dkName + SEP + EXTENT));
68  double factor = (
69  (prop.containsKey(dkName + SEP + FACTOR))
70  ? Double.parseDouble((String)prop.getProperty(dkName + SEP + FACTOR))
71  : 1
72  );
73  DataKind dk = new DataKind(dkName, unit, base, extent, factor);
74  dataKindMap_.put(dkName, dk);
75  }
76 
77  // アトリビュート毎のデータ種別の読み込み
78  attributeMap_ = new HashMap<String, DataKind>();
79  String postfix = SEP + DATA_KIND;
80  int postfixlen = postfix.length();
81  Enumeration elm = prop.propertyNames();
82  while (elm.hasMoreElements()) {
83  String pname = (String)elm.nextElement();
84  if (pname.endsWith(postfix)) {
85  String aname = pname.substring(
86  0, pname.length() - postfixlen
87  );
88  attributeMap_.put(aname, dataKindMap_.get(prop.getProperty(pname)));
89  }
90  }
91  }
92 
93  // -----------------------------------------------------------------
94  // クラスメソッド
101  String dataKindName
102  ) {
103  if (this_ == null) {
104  this_ = new GraphProperties();
105  }
106  return (DataKind)dataKindMap_.get(dataKindName);
107  }
108 
115  String attribute
116  ) {
117  if (this_ == null) {
118  this_ = new GraphProperties();
119  }
120  return (DataKind)attributeMap_.get(attribute);
121  }
122 }
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop int * unit
Definition: png.h:2451
static HashMap< String, DataKind > dataKindMap_
static HashMap< String, DataKind > attributeMap_
static DataKind getDataKindFromName(String dataKindName)
prop
static DataKind getDataKindFromAttr(String attribute)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:21