1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2013 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.ext.occurrence;
|
11
|
|
12
|
import java.text.SimpleDateFormat;
|
13
|
import java.util.Calendar;
|
14
|
|
15
|
/**
|
16
|
* Holds query parameters for a query to an occurrence provider.
|
17
|
* @author pplitzner
|
18
|
* @date 17.09.2013
|
19
|
*
|
20
|
*/
|
21
|
public class OccurenceQuery {
|
22
|
public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
|
23
|
|
24
|
public final String unitId;
|
25
|
|
26
|
public final String taxonName;
|
27
|
public final String collector;
|
28
|
public final String collectorsNumber;
|
29
|
public final String accessionNumber;
|
30
|
public final String herbarium;
|
31
|
public final String country;
|
32
|
public final String locality;
|
33
|
public final Calendar dateFrom;
|
34
|
public final Calendar dateTo;
|
35
|
|
36
|
|
37
|
|
38
|
public OccurenceQuery(String unitId) {
|
39
|
this(unitId, null, null, null, null, null, null, null, null, null);
|
40
|
}
|
41
|
|
42
|
/**
|
43
|
* @param taxonName
|
44
|
* @param collector
|
45
|
* @param collectorsNumber
|
46
|
* @param accessionNumber
|
47
|
* @param herbarium
|
48
|
* @param country
|
49
|
* @param locality
|
50
|
* @param dateFrom
|
51
|
* @param dateTo
|
52
|
*/
|
53
|
public OccurenceQuery(String taxonName, String collector, String collectorsNumber, String accessionNumber,
|
54
|
String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo) {
|
55
|
this(null, taxonName, collector, collectorsNumber, accessionNumber, herbarium, country, locality, dateFrom, dateTo);
|
56
|
}
|
57
|
|
58
|
/**
|
59
|
* Constructor to initially set the parameters
|
60
|
*/
|
61
|
private OccurenceQuery(String unitId, String taxonName, String collector, String collectorsNumber, String accessionNumber, String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo) {
|
62
|
this.unitId = unitId;
|
63
|
this.taxonName = taxonName;
|
64
|
this.collector = collector;
|
65
|
this.collectorsNumber = collectorsNumber;
|
66
|
this.accessionNumber = accessionNumber;
|
67
|
this.herbarium = herbarium;
|
68
|
this.country = country;
|
69
|
this.locality = locality;
|
70
|
this.dateFrom = dateFrom;
|
71
|
this.dateTo = dateTo;
|
72
|
}
|
73
|
|
74
|
/* (non-Javadoc)
|
75
|
* @see java.lang.Object#hashCode()
|
76
|
*/
|
77
|
@Override
|
78
|
public int hashCode() {
|
79
|
final int prime = 31;
|
80
|
int result = 1;
|
81
|
result = prime * result + ((accessionNumber == null) ? 0 : accessionNumber.hashCode());
|
82
|
result = prime * result + ((collector == null) ? 0 : collector.hashCode());
|
83
|
result = prime * result + ((collectorsNumber == null) ? 0 : collectorsNumber.hashCode());
|
84
|
result = prime * result + ((country == null) ? 0 : country.hashCode());
|
85
|
result = prime * result + ((dateFrom == null) ? 0 : dateFrom.hashCode());
|
86
|
result = prime * result + ((dateTo == null) ? 0 : dateTo.hashCode());
|
87
|
result = prime * result + ((herbarium == null) ? 0 : herbarium.hashCode());
|
88
|
result = prime * result + ((locality == null) ? 0 : locality.hashCode());
|
89
|
result = prime * result + ((taxonName == null) ? 0 : taxonName.hashCode());
|
90
|
result = prime * result + ((unitId == null) ? 0 : unitId.hashCode());
|
91
|
return result;
|
92
|
}
|
93
|
|
94
|
|
95
|
|
96
|
|
97
|
/* (non-Javadoc)
|
98
|
* @see java.lang.Object#equals(java.lang.Object)
|
99
|
*/
|
100
|
@Override
|
101
|
public boolean equals(Object obj) {
|
102
|
if (this == obj) {
|
103
|
return true;
|
104
|
}
|
105
|
if (obj == null) {
|
106
|
return false;
|
107
|
}
|
108
|
if (getClass() != obj.getClass()) {
|
109
|
return false;
|
110
|
}
|
111
|
OccurenceQuery other = (OccurenceQuery) obj;
|
112
|
if (accessionNumber == null) {
|
113
|
if (other.accessionNumber != null) {
|
114
|
return false;
|
115
|
}
|
116
|
} else if (!accessionNumber.equals(other.accessionNumber)) {
|
117
|
return false;
|
118
|
}
|
119
|
if (collector == null) {
|
120
|
if (other.collector != null) {
|
121
|
return false;
|
122
|
}
|
123
|
} else if (!collector.equals(other.collector)) {
|
124
|
return false;
|
125
|
}
|
126
|
if (collectorsNumber == null) {
|
127
|
if (other.collectorsNumber != null) {
|
128
|
return false;
|
129
|
}
|
130
|
} else if (!collectorsNumber.equals(other.collectorsNumber)) {
|
131
|
return false;
|
132
|
}
|
133
|
if (country == null) {
|
134
|
if (other.country != null) {
|
135
|
return false;
|
136
|
}
|
137
|
} else if (!country.equals(other.country)) {
|
138
|
return false;
|
139
|
}
|
140
|
if (dateFrom == null) {
|
141
|
if (other.dateFrom != null) {
|
142
|
return false;
|
143
|
}
|
144
|
} else if (!dateFrom.equals(other.dateFrom)) {
|
145
|
return false;
|
146
|
}
|
147
|
if (dateTo == null) {
|
148
|
if (other.dateTo != null) {
|
149
|
return false;
|
150
|
}
|
151
|
} else if (!dateTo.equals(other.dateTo)) {
|
152
|
return false;
|
153
|
}
|
154
|
if (herbarium == null) {
|
155
|
if (other.herbarium != null) {
|
156
|
return false;
|
157
|
}
|
158
|
} else if (!herbarium.equals(other.herbarium)) {
|
159
|
return false;
|
160
|
}
|
161
|
if (locality == null) {
|
162
|
if (other.locality != null) {
|
163
|
return false;
|
164
|
}
|
165
|
} else if (!locality.equals(other.locality)) {
|
166
|
return false;
|
167
|
}
|
168
|
if (taxonName == null) {
|
169
|
if (other.taxonName != null) {
|
170
|
return false;
|
171
|
}
|
172
|
} else if (!taxonName.equals(other.taxonName)) {
|
173
|
return false;
|
174
|
}
|
175
|
if (unitId == null) {
|
176
|
if (other.unitId != null) {
|
177
|
return false;
|
178
|
}
|
179
|
} else if (!unitId.equals(other.unitId)) {
|
180
|
return false;
|
181
|
}
|
182
|
return true;
|
183
|
}
|
184
|
|
185
|
|
186
|
|
187
|
|
188
|
/* (non-Javadoc)
|
189
|
* @see java.lang.Object#toString()
|
190
|
*/
|
191
|
@Override
|
192
|
public String toString() {
|
193
|
String string = "";
|
194
|
if(unitId!=null && !unitId.trim().isEmpty()){
|
195
|
string += " unitId=" + unitId;
|
196
|
}
|
197
|
if(taxonName!=null && !taxonName.trim().isEmpty()){
|
198
|
string += " taxonName=" + taxonName;
|
199
|
}
|
200
|
if(collector!=null && !collector.trim().isEmpty()){
|
201
|
string += " collector=" + collector;
|
202
|
}
|
203
|
if(collectorsNumber!=null && !collectorsNumber.trim().isEmpty()){
|
204
|
string += " collectorsNumber=" + collectorsNumber;
|
205
|
}
|
206
|
if(accessionNumber!=null && !accessionNumber.trim().isEmpty()){
|
207
|
string += " accessionNumber=" + accessionNumber;
|
208
|
}
|
209
|
if(herbarium!=null && !herbarium.trim().isEmpty()){
|
210
|
string += " herbarium=" + herbarium;
|
211
|
}
|
212
|
if(country!=null && !country.trim().isEmpty()){
|
213
|
string += " country=" + country;
|
214
|
}
|
215
|
if(locality!=null && !locality.trim().isEmpty()){
|
216
|
string += " locality=" + locality;
|
217
|
}
|
218
|
if(dateFrom!=null){
|
219
|
string += " dateFrom=" + DATE_FORMAT.format(dateFrom.getTime());
|
220
|
}
|
221
|
if(dateTo!=null){
|
222
|
string += " dateTo=" + DATE_FORMAT.format(dateTo.getTime());
|
223
|
}
|
224
|
return string;
|
225
|
}
|
226
|
}
|