comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/AttributedTheme.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/shared/model/AttributedTheme.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.shared.model;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Set;
6
7
8 /**
9 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
10 */
11 public class AttributedTheme implements Theme {
12
13 protected Map<String, String> attributes;
14
15 /** CollectionItem associated with this facet/themes artifact. */
16 protected CollectionItem collectionItem;
17
18 public AttributedTheme() {
19 this.attributes = new HashMap<String, String>();
20 }
21
22
23 public Set<String> getKeys() {
24 return attributes.keySet();
25 }
26
27
28 public void addAttr(String name, String value) {
29 if (name != null && value != null) {
30 attributes.put(name, value);
31 }
32 }
33
34
35 public String getAttr(String name) {
36 return attributes.get(name);
37 }
38
39
40 public Integer getAttrAsInt(String name) {
41 String attr = getAttr(name);
42
43 if (attr != null && attr.length() > 0) {
44 try {
45 return Integer.parseInt(attr);
46 }
47 catch (NumberFormatException nfe) {
48 }
49 }
50
51 return null;
52 }
53
54
55 public boolean getAttrAsBoolean(String name) {
56 String attr = getAttr(name);
57
58 if (attr != null) {
59 try {
60 int num = Integer.valueOf(attr);
61 return num > 0;
62 }
63 catch (NumberFormatException nfe) {
64 // do nothing
65 }
66 }
67
68 return Boolean.valueOf(attr);
69 }
70
71
72 @Override
73 public int getPosition() {
74 Integer pos = getAttrAsInt("pos");
75
76 return pos != null ? pos.intValue() : -1;
77 }
78
79
80 @Override
81 public void setPosition(int pos) {
82 addAttr("pos", String.valueOf(pos));
83 }
84
85
86 @Override
87 public int getIndex() {
88 Integer idx = getAttrAsInt("index");
89
90 return idx != null ? idx.intValue() : -1;
91 }
92
93
94 @Override
95 public int getActive() {
96 return getAttrAsInt("active");
97 }
98
99
100 @Override
101 public void setActive(int active) {
102 addAttr("active", String.valueOf(active));
103 }
104
105
106 @Override
107 public String getArtifact() {
108 return getAttr("artifact");
109 }
110
111
112 @Override
113 public String getFacet() {
114 return getAttr("facet");
115 }
116
117
118 @Override
119 public String getDescription() {
120 return getAttr("description");
121 }
122
123
124 @Override
125 public void setDescription(String description) {
126 if (description != null && description.length() > 0) {
127 addAttr("description", description);
128 }
129 }
130
131
132 @Override
133 public int getVisible() {
134 return getAttrAsInt("visible");
135 }
136
137
138 @Override
139 public void setVisible(int visible) {
140 addAttr("visible", String.valueOf(visible));
141 }
142
143
144 @Override
145 public boolean equals(Object o) {
146 if (!(o instanceof AttributedTheme)) {
147 return false;
148 }
149
150 AttributedTheme other = (AttributedTheme) o;
151
152 if (other.getPosition() != getPosition()) {
153 return false;
154 }
155
156 if (!other.getArtifact().equals(getArtifact())) {
157 return false;
158 }
159
160 if (other.getActive() != getActive()) {
161 return false;
162 }
163
164 if (!other.getFacet().equals(getFacet())) {
165 return false;
166 }
167
168 if (!other.getDescription().equals(getDescription())) {
169 return false;
170 }
171
172 if (other.getIndex() != getIndex()) {
173 return false;
174 }
175
176 if (other.getVisible() != getVisible()) {
177 return false;
178 }
179
180 return true;
181 }
182
183
184 /** Get the CollectionItem representing the facets artifact. */
185 @Override
186 public CollectionItem getCollectionItem() {
187 return collectionItem;
188 }
189
190
191 /** Set the CollectionItem representing the facets artifact. */
192 @Override
193 public void setCollectionItem(CollectionItem ci) {
194 this.collectionItem = ci;
195 }
196 }
197 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org