comparison flys-client/src/main/java/org/dive4elements/river/client/shared/model/Recommendation.java @ 5834:f507086aa94b

Repaired internal references.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:31:32 +0200
parents flys-client/src/main/java/de/intevation/flys/client/shared/model/Recommendation.java@0b79630e3bcb
children 821a02bbfb4e
comparison
equal deleted inserted replaced
5833:a2bdc0f524e8 5834:f507086aa94b
1 package de.intevation.flys.client.shared.model;
2
3
4 import java.util.List;
5 import java.util.Map;
6 import java.util.HashMap;
7
8 import java.io.Serializable;
9
10 /**
11 * Information bundle to let client create/clone an artifact with facets.
12 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
13 */
14 public class Recommendation implements Serializable {
15
16 /** Index and name of a facet. */
17 public static class Facet implements Serializable {
18
19 /** Facet name. */
20 protected String name;
21
22 /** Facet index. */
23 protected String index;
24
25 public Facet() {
26 }
27
28 public Facet(String name, String index) {
29 this.name = name;
30 this.index = index;
31 }
32
33 public String getName() {
34 return name;
35 }
36
37 public String getIndex() {
38 return index;
39 }
40
41
42 @Override
43 public int hashCode() {
44 int hash = 0;
45 if (getName() != null) {
46 hash += getName().hashCode();
47 }
48 if (getIndex() != null) {
49 hash += getIndex().hashCode();
50 }
51 return hash;
52 }
53
54
55 @Override
56 public boolean equals(Object other) {
57 if (!(other instanceof Facet) || other == null) {
58 return false;
59 }
60 Facet facet = (Facet) other;
61 return (same(facet.getIndex(), this.getIndex()))
62 && (same(facet.getName(), this.getName()));
63 }
64 } // class Facet
65
66
67 /** Mapping of outnames to Facet-Lists. */
68 public static class Filter implements Serializable {
69
70 protected Map<String, List<Facet>> outs;
71
72 public Filter() {
73 outs = new HashMap<String, List<Facet>>();
74 }
75
76 public void add(String out, List<Facet> facets) {
77 outs.put(out, facets);
78 }
79
80 public Map<String, List<Facet>> getOuts() {
81 return outs;
82 }
83
84
85 @Override
86 public int hashCode() {
87 if (getOuts() != null) {
88 return getOuts().hashCode();
89 }
90 return 0;
91 }
92
93
94 @Override
95 public boolean equals(Object other) {
96 if (!(other instanceof Filter) || other == null) {
97 return false;
98 }
99 Filter filter = (Filter) other;
100 return Recommendation.same(filter.getOuts(), this.getOuts());
101 }
102 } // class Filter
103
104 /** Factory to speak to when creating/cloning. */
105 protected String factory;
106 /** Sometimes database ids, sometimes other freeform text. */
107 protected String ids;
108 /** Artifacts uuid that should serve as master artifact. */
109 protected String masterArtifact;
110 /** Optional facet filter. */
111 protected Filter filter;
112 protected String displayName = null;
113
114 public Recommendation() {
115 }
116
117 public Recommendation(String factory, String ids) {
118 this(factory, ids, null, null);
119 }
120
121 public Recommendation(
122 String factory,
123 String ids,
124 String masterArtifact,
125 Filter filter
126 ) {
127 this.factory = factory;
128 this.ids = ids;
129 this.masterArtifact = masterArtifact;
130 this.filter = filter;
131 }
132
133 public String getFactory() {
134 return factory;
135 }
136
137 public void setFactory(String factory) {
138 this.factory = factory;
139 }
140
141 public void setDisplayName(String displayName) {
142 this.displayName = displayName;
143 }
144
145 public String getDisplayName() {
146 return this.displayName;
147 }
148
149 public String getIDs() {
150 return ids;
151 }
152
153 public String getMasterArtifact() {
154 return masterArtifact;
155 }
156
157 public void setMasterArtifact(String masterArtifact) {
158 this.masterArtifact = masterArtifact;
159 }
160
161 public Filter getFilter() {
162 return filter;
163 }
164
165 public void setFilter(Filter filter) {
166 this.filter = filter;
167 }
168
169
170 @Override
171 public int hashCode() {
172 int hash = 0;
173 hash += (getFactory() != null)
174 ? getFactory().hashCode()
175 : 0;
176 hash += (getIDs() != null)
177 ? getIDs().hashCode()
178 : 0;
179 hash += (getFilter() != null)
180 ? getFilter().hashCode()
181 : 0;
182 hash += (getMasterArtifact() != null)
183 ? getMasterArtifact().hashCode()
184 : 0;
185 return hash;
186 }
187
188
189 /**
190 * Null-pointer guarded equals.
191 * Two null's are assumed equal (returns true);
192 * @param a Object to compare against parameter b.
193 * @param b Object to compare against parameter a.
194 * @return true if either a and b are null or a.equals(b) returns true.
195 */
196 protected static boolean same(Object a, Object b) {
197 // Do null-check.
198 if (a == null) {
199 return b == null;
200 } else if (b == null) {
201 return false;
202 }
203 return a.equals(b);
204 }
205
206
207 @Override
208 public boolean equals(Object other) {
209 if (!(other instanceof Recommendation) || other == null) {
210 return false;
211 }
212 Recommendation rec = (Recommendation) other;
213 return (same(this.getFactory(), rec.getFactory()))
214 && (same(this.getIDs(), rec.getIDs()))
215 && (same(this.getFilter(), rec.getFilter()))
216 && (same(this.getMasterArtifact(), rec.getMasterArtifact()));
217 }
218 }
219 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org