comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java @ 875:5e9efdda6894

merged gnv-artifacts/1.0
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:56 +0200
parents 05bf8534a35a
children c07d9f9a738c
comparison
equal deleted inserted replaced
722:bb3ffe7d719e 875:5e9efdda6894
1 package de.intevation.gnv.state;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.apache.log4j.Logger;
7
8 /**
9 * The default implementation of <code>InputData</code>. This object stores
10 * multiple values separated by {@link #VALUE_SEPARATOR} for a specific key.
11 *
12 * @author <a href="mailto:tim.englich@intevation.de">Tim Englich</a>
13 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
14 */
15 public class DefaultInputData implements InputData {
16
17 /**
18 *
19 */
20 private static final long serialVersionUID = 4308041648698108066L;
21
22 private static final Logger logger = Logger.getLogger(DefaultInputData.class);
23
24 /**
25 * The character used to separate the different values.
26 */
27 public final static String VALUE_SEPARATOR = " , ";
28
29 /**
30 * The key/name of this object.
31 */
32 protected String name;
33
34 /**
35 * Values separated by {@link #VALUE_SEPARATOR}.
36 */
37 protected String value;
38
39 /**
40 * Descriptions for values used for user interface creation. Each value
41 * should have an own description in this map.
42 */
43 protected Map description;
44
45 /**
46 * An extra object. Might be everything.
47 */
48 protected Object object;
49
50
51 /**
52 * Constructor
53 */
54 public DefaultInputData(String name, String value) {
55 this.name = name;
56 this.value = value;
57 }
58
59
60 public DefaultInputData(String name, Object object) {
61 this.name = name;
62 this.object = object;
63 }
64
65
66 public DefaultInputData(
67 String name,
68 String value,
69 Object object)
70 {
71 this.name = name;
72 this.object = object;
73 this.value = value;
74 }
75
76
77 public String getName() {
78 return this.name;
79 }
80
81
82 public String getValue() {
83 return this.value;
84 }
85
86
87 public void setObject(Object object) {
88 this.object = object;
89 }
90
91
92 public Object getObject() {
93 return object;
94 }
95
96 /**
97 *
98 * @param key Key needs to be a single value of {@link #value}.
99 * @return the description.
100 */
101 public String getDescription(String key) {
102 if (description == null)
103 return null;
104
105 return (String) description.get(key);
106 }
107
108 /**
109 * Return all descriptions as array.
110 *
111 * @return descriptions as array.
112 */
113 public String[] getDescription() {
114 String[] values = splitValue();
115 int length = values.length;
116
117 String[] description = new String[length];
118 for (int i = 0; i < length; i++) {
119 description[i] = (String) this.description.get(values[i]);
120 }
121
122 return description;
123 }
124
125
126 public void setDescription(String[] description) {
127 if (this.description == null)
128 this.description = new HashMap();
129
130 String[] values = splitValue();
131
132 int length = values.length;
133 int descLength = description.length;
134
135 for (int i = 0; i < length; i++) {
136 if (i < descLength) {
137 this.description.put(values[i], description[i]);
138 }
139 else {
140 break;
141 }
142 }
143 }
144
145
146 @Override
147 public String toString() {
148 return this.name + "==> " + this.value;
149 }
150
151
152 public void concartValue(String value) {
153 this.value = this.value + VALUE_SEPARATOR + value;
154 }
155
156
157 public String[] splitValue() {
158 if (this.value != null){
159 return this.value.split(VALUE_SEPARATOR);
160 }
161 return null;
162 }
163
164 }
165 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org