Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/DefaultInputData.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 58c32df1a44d |
children | c4156275c1e1 |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
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 * @author Tim Englich (tim.englich@intevation.de) | |
10 * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) | |
11 */ | |
12 public class DefaultInputData implements InputData { | |
13 | |
14 /** | |
15 * | |
16 */ | |
17 private static final long serialVersionUID = 4308041648698108066L; | |
18 | |
19 private static final Logger logger = Logger.getLogger(DefaultInputData.class); | |
20 | |
21 private final static String VALUE_SEPARATOR = " , "; | |
22 | |
23 protected String name; | |
24 protected String value; | |
25 protected Map description; | |
26 protected Object object; | |
27 | |
28 | |
29 /** | |
30 * Constructor | |
31 */ | |
32 public DefaultInputData(String name, String value) { | |
33 this.name = name; | |
34 this.value = value; | |
35 } | |
36 | |
37 public DefaultInputData(String name, Object object) { | |
38 this.name = name; | |
39 this.object = object; | |
40 } | |
41 | |
42 /** | |
43 * @see de.intevation.gnv.state.InputData#getName() | |
44 */ | |
45 public String getName() { | |
46 return this.name; | |
47 } | |
48 | |
49 /** | |
50 * @see de.intevation.gnv.state.InputData#getValue() | |
51 */ | |
52 public String getValue() { | |
53 return this.value; | |
54 } | |
55 | |
56 public void setObject(Object object) { | |
57 this.object = object; | |
58 } | |
59 | |
60 public Object getObject() { | |
61 return object; | |
62 } | |
63 | |
64 public String getDescription(String key) { | |
65 if (description == null) | |
66 return null; | |
67 | |
68 return (String) description.get(key); | |
69 } | |
70 | |
71 public String[] getDescription() { | |
72 String[] values = splitValue(); | |
73 int length = values.length; | |
74 | |
75 String[] description = new String[length]; | |
76 for (int i = 0; i < length; i++) { | |
77 description[i] = (String) this.description.get(values[i]); | |
78 } | |
79 | |
80 return description; | |
81 } | |
82 | |
83 public void setDescription(String[] description) { | |
84 if (this.description == null) | |
85 this.description = new HashMap(); | |
86 | |
87 String[] values = splitValue(); | |
88 | |
89 int length = values.length; | |
90 int descLength = description.length; | |
91 | |
92 for (int i = 0; i < length; i++) { | |
93 if (i < descLength) { | |
94 this.description.put(values[i], description[i]); | |
95 } | |
96 else { | |
97 break; | |
98 } | |
99 } | |
100 } | |
101 | |
102 /** | |
103 * @see java.lang.Object#toString() | |
104 */ | |
105 @Override | |
106 public String toString() { | |
107 return this.name + "==> " + this.value; | |
108 } | |
109 | |
110 /** | |
111 * @see de.intevation.gnv.state.InputData#concartValue(java.lang.String) | |
112 */ | |
113 public void concartValue(String value) { | |
114 this.value = this.value + VALUE_SEPARATOR + value; | |
115 } | |
116 | |
117 /** | |
118 * @see de.intevation.gnv.state.InputData#splitValue() | |
119 */ | |
120 public String[] splitValue() { | |
121 if (this.value != null){ | |
122 return this.value.split(VALUE_SEPARATOR); | |
123 } | |
124 return null; | |
125 } | |
126 | |
127 } |