9566
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.client.shared.model; |
|
10 |
|
11 import java.io.Serializable; |
|
12 import java.util.HashMap; |
|
13 import java.util.List; |
|
14 import java.util.Map; |
|
15 |
|
16 /** |
|
17 * Information bundle to let client create/clone an artifact with facets. |
|
18 * |
|
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
|
20 */ |
|
21 public class Recommendation implements Serializable { |
|
22 |
|
23 private static final long serialVersionUID = 1L; |
|
24 |
|
25 /** Index and name of a facet. */ |
|
26 public static class Facet implements Serializable { |
|
27 |
|
28 private static final long serialVersionUID = 1L; |
|
29 |
|
30 /** Facet name. */ |
|
31 protected String name; |
|
32 |
|
33 /** Facet index. */ |
|
34 protected String index; |
|
35 |
|
36 public Facet() { |
|
37 } |
|
38 |
|
39 public Facet(final String name, final String index) { |
|
40 this.name = name; |
|
41 this.index = index; |
|
42 } |
|
43 |
|
44 public String getName() { |
|
45 return this.name; |
|
46 } |
|
47 |
|
48 public String getIndex() { |
|
49 return this.index; |
|
50 } |
|
51 |
|
52 @Override |
|
53 public int hashCode() { |
|
54 int hash = 0; |
|
55 if (getName() != null) { |
|
56 hash += getName().hashCode(); |
|
57 } |
|
58 if (getIndex() != null) { |
|
59 hash += getIndex().hashCode(); |
|
60 } |
|
61 return hash; |
|
62 } |
|
63 |
|
64 @Override |
|
65 public boolean equals(final Object other) { |
|
66 if (!(other instanceof Facet) || other == null) { |
|
67 return false; |
|
68 } |
|
69 final Facet facet = (Facet) other; |
|
70 return (same(facet.getIndex(), this.getIndex())) && (same(facet.getName(), this.getName())); |
|
71 } |
|
72 } // class Facet |
|
73 |
|
74 /** Mapping of outnames to Facet-Lists. */ |
|
75 public static class Filter implements Serializable { |
|
76 |
|
77 protected Map<String, List<Facet>> outs; |
|
78 |
|
79 public Filter() { |
|
80 this.outs = new HashMap<String, List<Facet>>(); |
|
81 } |
|
82 |
|
83 public void add(final String out, final List<Facet> facets) { |
|
84 this.outs.put(out, facets); |
|
85 } |
|
86 |
|
87 public Map<String, List<Facet>> getOuts() { |
|
88 return this.outs; |
|
89 } |
|
90 |
|
91 @Override |
|
92 public int hashCode() { |
|
93 if (getOuts() != null) { |
|
94 return getOuts().hashCode(); |
|
95 } |
|
96 return 0; |
|
97 } |
|
98 |
|
99 @Override |
|
100 public boolean equals(final Object other) { |
|
101 if (!(other instanceof Filter) || other == null) { |
|
102 return false; |
|
103 } |
|
104 final Filter filter = (Filter) other; |
|
105 return Recommendation.same(filter.getOuts(), this.getOuts()); |
|
106 } |
|
107 } // class Filter |
|
108 |
|
109 /** Factory to speak to when creating/cloning. */ |
|
110 protected String factory; |
|
111 /** Sometimes database ids, sometimes other freeform text. */ |
|
112 protected String ids; |
|
113 /** Artifacts uuid that should serve as master artifact. */ |
|
114 protected String masterArtifact; |
|
115 /** Optional facet filter. */ |
|
116 protected Filter filter; |
|
117 /** The out this Artifact should be added to **/ |
|
118 protected String targetOut; |
|
119 |
|
120 protected String displayName = null; |
|
121 |
|
122 public Recommendation() { |
|
123 } |
|
124 |
|
125 public Recommendation(final String factory, final String ids) { |
|
126 this(factory, ids, null, null); |
|
127 } |
|
128 |
|
129 public Recommendation(final String factory, final String ids, final String targetOut) { |
|
130 this(factory, ids, null, null, targetOut); |
|
131 } |
|
132 |
|
133 public Recommendation(final String factory, final String ids, final String masterArtifact, final Filter filter) { |
|
134 this(factory, ids, masterArtifact, filter, null); |
|
135 } |
|
136 |
|
137 public Recommendation(final String factory, final String ids, final String masterArtifact, final Filter filter, final String targetOut) { |
|
138 this.factory = factory; |
|
139 this.ids = ids; |
|
140 this.masterArtifact = masterArtifact; |
|
141 this.filter = filter; |
|
142 this.targetOut = targetOut; |
|
143 } |
|
144 |
|
145 public String getTargetOut() { |
|
146 return this.targetOut; |
|
147 } |
|
148 |
|
149 public void setTargetOut(final String value) { |
|
150 this.targetOut = value; |
|
151 } |
|
152 |
|
153 public String getFactory() { |
|
154 return this.factory; |
|
155 } |
|
156 |
|
157 public void setFactory(final String factory) { |
|
158 this.factory = factory; |
|
159 } |
|
160 |
|
161 public void setDisplayName(final String displayName) { |
|
162 this.displayName = displayName; |
|
163 } |
|
164 |
|
165 public String getDisplayName() { |
|
166 return this.displayName; |
|
167 } |
|
168 |
|
169 public String getIDs() { |
|
170 return this.ids; |
|
171 } |
|
172 |
|
173 public String getMasterArtifact() { |
|
174 return this.masterArtifact; |
|
175 } |
|
176 |
|
177 public void setMasterArtifact(final String masterArtifact) { |
|
178 this.masterArtifact = masterArtifact; |
|
179 } |
|
180 |
|
181 public Filter getFilter() { |
|
182 return this.filter; |
|
183 } |
|
184 |
|
185 public void setFilter(final Filter filter) { |
|
186 this.filter = filter; |
|
187 } |
|
188 |
|
189 @Override |
|
190 public int hashCode() { |
|
191 int hash = 0; |
|
192 hash += (getFactory() != null) ? getFactory().hashCode() : 0; |
|
193 hash += (getIDs() != null) ? getIDs().hashCode() : 0; |
|
194 hash += (getFilter() != null) ? getFilter().hashCode() : 0; |
|
195 hash += (getMasterArtifact() != null) ? getMasterArtifact().hashCode() : 0; |
|
196 hash += (getTargetOut() != null) ? getTargetOut().hashCode() : 0; |
|
197 return hash; |
|
198 } |
|
199 |
|
200 /** |
|
201 * Null-pointer guarded equals. |
|
202 * Two null's are assumed equal (returns true); |
|
203 * |
|
204 * @param a |
|
205 * Object to compare against parameter b. |
|
206 * @param b |
|
207 * Object to compare against parameter a. |
|
208 * @return true if either a and b are null or a.equals(b) returns true. |
|
209 */ |
|
210 protected static boolean same(final Object a, final Object b) { |
|
211 // Do null-check. |
|
212 if (a == null) { |
|
213 return b == null; |
|
214 } else if (b == null) { |
|
215 return false; |
|
216 } |
|
217 return a.equals(b); |
|
218 } |
|
219 |
|
220 @Override |
|
221 public boolean equals(final Object other) { |
|
222 if (!(other instanceof Recommendation) || other == null) { |
|
223 return false; |
|
224 } |
|
225 final Recommendation rec = (Recommendation) other; |
|
226 return (same(this.getFactory(), rec.getFactory())) && (same(this.getIDs(), rec.getIDs())) && (same(this.getFilter(), rec.getFilter())) |
|
227 && (same(this.getMasterArtifact(), rec.getMasterArtifact())) && (same(this.getTargetOut(), rec.getTargetOut())); |
|
228 } |
|
229 } |