Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/shared/model/AttributedTheme.java @ 804:374712890b94
Facets read from Collection's DESCRIBE document keep all their attributes after the Collection's attribute has been modified.
flys-client/trunk@2362 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 19 Jul 2011 16:32:52 +0000 |
parents | |
children | aa2313e0f18d |
comparison
equal
deleted
inserted
replaced
803:653ae84533e7 | 804:374712890b94 |
---|---|
1 package de.intevation.flys.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 | |
16 public AttributedTheme() { | |
17 this.attributes = new HashMap<String, String>(); | |
18 } | |
19 | |
20 | |
21 public Set<String> getKeys() { | |
22 return attributes.keySet(); | |
23 } | |
24 | |
25 | |
26 public void addAttr(String name, String value) { | |
27 if (name != null && value != null) { | |
28 attributes.put(name, value); | |
29 } | |
30 } | |
31 | |
32 | |
33 public String getAttr(String name) { | |
34 return attributes.get(name); | |
35 } | |
36 | |
37 | |
38 public Integer getAttrAsInt(String name) { | |
39 String attr = getAttr(name); | |
40 | |
41 if (attr != null && attr.length() > 0) { | |
42 try { | |
43 return Integer.parseInt(attr); | |
44 } | |
45 catch (NumberFormatException nfe) { | |
46 } | |
47 } | |
48 | |
49 return null; | |
50 } | |
51 | |
52 | |
53 public boolean getAttrAsBoolean(String name) { | |
54 String attr = getAttr(name); | |
55 | |
56 if (attr != null) { | |
57 try { | |
58 int num = Integer.valueOf(attr); | |
59 return num > 0; | |
60 } | |
61 catch (NumberFormatException nfe) { | |
62 // do nothing | |
63 } | |
64 } | |
65 | |
66 return Boolean.valueOf(attr); | |
67 } | |
68 | |
69 | |
70 @Override | |
71 public int getPosition() { | |
72 Integer pos = getAttrAsInt("pos"); | |
73 | |
74 return pos != null ? pos.intValue() : -1; | |
75 } | |
76 | |
77 | |
78 @Override | |
79 public void setPosition(int pos) { | |
80 addAttr("pos", String.valueOf(pos)); | |
81 } | |
82 | |
83 | |
84 @Override | |
85 public int getIndex() { | |
86 Integer idx = getAttrAsInt("index"); | |
87 | |
88 return idx != null ? idx.intValue() : -1; | |
89 } | |
90 | |
91 | |
92 @Override | |
93 public int getActive() { | |
94 return getAttrAsInt("active"); | |
95 } | |
96 | |
97 | |
98 @Override | |
99 public void setActive(int active) { | |
100 addAttr("active", String.valueOf(active)); | |
101 } | |
102 | |
103 | |
104 @Override | |
105 public String getArtifact() { | |
106 return getAttr("artifact"); | |
107 } | |
108 | |
109 | |
110 @Override | |
111 public String getFacet() { | |
112 return getAttr("facet"); | |
113 } | |
114 | |
115 | |
116 @Override | |
117 public String getDescription() { | |
118 return getAttr("description"); | |
119 } | |
120 | |
121 | |
122 @Override | |
123 public boolean equals(Object o) { | |
124 if (!(o instanceof AttributedTheme)) { | |
125 return false; | |
126 } | |
127 | |
128 AttributedTheme other = (AttributedTheme) o; | |
129 | |
130 if (other.getPosition() != getPosition()) { | |
131 return false; | |
132 } | |
133 | |
134 if (!other.getArtifact().equals(getArtifact())) { | |
135 return false; | |
136 } | |
137 | |
138 if (other.getActive() != getActive()) { | |
139 return false; | |
140 } | |
141 | |
142 if (!other.getFacet().equals(getFacet())) { | |
143 return false; | |
144 } | |
145 | |
146 if (!other.getDescription().equals(getDescription())) { | |
147 return false; | |
148 } | |
149 | |
150 if (other.getIndex() != getIndex()) { | |
151 return false; | |
152 } | |
153 | |
154 return true; | |
155 } | |
156 } | |
157 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |