View Javadoc
1   package com.github.celldynamics.quimp.plugin;
2   
3   import java.util.Map;
4   
5   import com.github.celldynamics.quimp.plugin.utils.LinkedStringMap;
6   import com.github.celldynamics.quimp.plugin.utils.StringParser;
7   
8   /**
9    * List of parameters in [key,value] HashList, where both key and value are java.lang.String and key
10   * is case insensitive.
11   * 
12   * @author p.baniukiewicz
13   *
14   */
15  public class ParamList extends LinkedStringMap<String> {
16  
17    private static final long serialVersionUID = -8762132735734951785L;
18  
19    /**
20     * Copy constructor.
21     * 
22     * @param src Source to copy
23     */
24    public ParamList href="../../../../../com/github/celldynamics/quimp/plugin/ParamList.html#ParamList">ParamList(ParamList src) {
25      if (src != null) {
26        for (Map.Entry<String, String> e : src.entrySet()) {
27          put(e.getKey(), e.getValue());
28        }
29      }
30    }
31  
32    /**
33     * Default constructor.
34     */
35    public ParamList() {
36      super();
37    }
38  
39    /**
40     * Store Integer value in List. Key is not case sensitive.
41     * 
42     * @param key name of key
43     * @param value to store
44     */
45    public void setIntValue(String key, int value) {
46      put(key, String.valueOf(value));
47    }
48  
49    /**
50     * Store Double value in List. Key is not case sensitive.
51     * 
52     * @param key name of key
53     * @param value to store
54     */
55    public void setDoubleValue(String key, double value) {
56      put(key, String.valueOf(value));
57    }
58  
59    /**
60     * Store String value in List. Key is not case sensitive.
61     * 
62     * @param key name of key
63     * @param value to store
64     */
65    public void setStringValue(String key, String value) {
66      put(key, value);
67    }
68  
69    /**
70     * Store Boolean value in List. Key is not case sensitive.
71     * 
72     * @param key name of key
73     * @param value to store
74     */
75    public void setBooleanValue(String key, boolean value) {
76      put(key, String.valueOf(value));
77    }
78  
79    /**
80     * Get Integer value from list associated with \c key. Key is not case sensitive.
81     * 
82     * <p>For safety it take double and then converts it to integer. It helps with dealing with type
83     * changing in QWindowBuilder. By default it keeps all in double and passed data returns in
84     * double as well
85     * 
86     * @param key name of key
87     * @return associated value
88     */
89    public int getIntValue(String key) {
90      return new Double(getDoubleValue(key)).intValue();
91    }
92  
93    /**
94     * Get Double value from list associated with \c key. Key is not case sensitive.
95     * 
96     * @param key name of key
97     * @return associated value
98     */
99    public double getDoubleValue(String key) {
100     return Double.parseDouble(get(key));
101   }
102 
103   /**
104    * . Get String value from list associated with \c key. Key is not case sensitive
105    * 
106    * @param key name of key
107    * @return associated value
108    */
109   public String getStringValue(String key) {
110     return get(key);
111   }
112 
113   /**
114    * Get Boolean value from list associated with \c key. Key is not case sensitive.
115    * 
116    * @param key name of key
117    * @return associated value
118    */
119   public boolean getBooleanValue(String key) {
120     return Boolean.parseBoolean(get(key));
121   }
122 
123   /**
124    * Get string associated with key and parse it to split according to delimiter.
125    * 
126    * <p>May be used only when val under key can be parsed
127    * 
128    * @param key to be read
129    * @param ch string delimiter
130    * @return Split substrings or empty array in case of any error
131    * @see StringParser
132    */
133   public String[] getParsed(String key, char ch) {
134     String val = get(key);
135     String[] ret = new String[0];
136     if (val == null) { // no control related to such key
137       return ret;
138     }
139     try {
140       ret = StringParser.getParams(val, ch);
141     } catch (Exception e) {
142       ret = new String[0];
143     }
144     return ret;
145   }
146 
147 }