Project

General

Profile

Download (8.1 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2013 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.ext.occurrence;
10

    
11
import java.io.Serializable;
12
import java.text.SimpleDateFormat;
13
import java.util.Calendar;
14
import java.util.Set;
15

    
16
/**
17
 * Holds query parameters for a query to an occurrence provider.
18
 * @author pplitzner
19
 * @since 17.09.2013
20
 *
21
 */
22
public class OccurenceQuery implements Serializable{
23
    public static  SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
24

    
25
    public  Set<String[]> tripleIds = null;
26

    
27
    public String taxonName = null;
28
    public String higherTaxon = null;
29
    public String collector = null;
30
    public String collectorsNumber = null;
31
    public String accessionNumber = null;
32
    public String herbarium = null;
33
    public String country = null;
34
    public String locality = null;
35
    public Calendar dateFrom = null;
36
    public Calendar dateTo = null;
37
    public boolean hasImage = false;
38

    
39

    
40

    
41
    public OccurenceQuery(Set<String[]> tripleIds) {
42

    
43
        this(tripleIds, null, null, null, null, null, null, null, null, null, null, false);
44
    }
45

    
46
    /**
47
     * @param taxonName
48
     * @param collector
49
     * @param collectorsNumber
50
     * @param accessionNumber
51
     * @param herbarium
52
     * @param country
53
     * @param locality
54
     * @param dateFrom
55
     * @param dateTo
56
     */
57
    public OccurenceQuery(String taxonName, String collector, String collectorsNumber, String accessionNumber,
58
            String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo, boolean hasImage) {
59
        this(null, taxonName, null, collector, collectorsNumber, accessionNumber, herbarium, country, locality, dateFrom, dateTo, hasImage);
60
    }
61

    
62
    /**
63
     * Constructor to initially set the parameters
64
     */
65
    private OccurenceQuery(Set<String[]> tripleIds, String taxonName, String higherTaxon, String collector, String collectorsNumber, String accessionNumber, String herbarium, String country, String locality, Calendar dateFrom, Calendar dateTo, boolean hasImage) {
66
        this.tripleIds = tripleIds;
67
        this.taxonName = taxonName;
68
        this.collector = collector;
69
        this.collectorsNumber = collectorsNumber;
70
        this.accessionNumber = accessionNumber;
71
        this.herbarium = herbarium;
72
        this.country = country;
73
        this.locality = locality;
74
        this.dateFrom = dateFrom;
75
        this.dateTo = dateTo;
76
        this.hasImage = hasImage;
77
    }
78

    
79
    /**
80
     * @param unitID
81
     */
82
    public OccurenceQuery(String unitID) {
83
        this.accessionNumber = unitID;
84
    }
85

    
86
    /* (non-Javadoc)
87
     * @see java.lang.Object#hashCode()
88
     */
89
    @Override
90
    public int hashCode() {
91
        final int prime = 31;
92
        int result = 1;
93
        result = prime * result + ((accessionNumber == null) ? 0 : accessionNumber.hashCode());
94
        result = prime * result + ((collector == null) ? 0 : collector.hashCode());
95
        result = prime * result + ((collectorsNumber == null) ? 0 : collectorsNumber.hashCode());
96
        result = prime * result + ((country == null) ? 0 : country.hashCode());
97
        result = prime * result + ((dateFrom == null) ? 0 : dateFrom.hashCode());
98
        result = prime * result + ((dateTo == null) ? 0 : dateTo.hashCode());
99
        result = prime * result + ((herbarium == null) ? 0 : herbarium.hashCode());
100
        result = prime * result + ((locality == null) ? 0 : locality.hashCode());
101
        result = prime * result + ((taxonName == null) ? 0 : taxonName.hashCode());
102
        result = prime * result + ((higherTaxon == null) ? 0 : higherTaxon.hashCode());
103
        result = prime * result + ((tripleIds == null) ? 0 : tripleIds.hashCode());
104
        return result;
105
    }
106

    
107

    
108

    
109

    
110
    /* (non-Javadoc)
111
     * @see java.lang.Object#equals(java.lang.Object)
112
     */
113
    @Override
114
    public boolean equals(Object obj) {
115
        if (this == obj) {
116
            return true;
117
        }
118
        if (obj == null) {
119
            return false;
120
        }
121
        if (getClass() != obj.getClass()) {
122
            return false;
123
        }
124
        OccurenceQuery other = (OccurenceQuery) obj;
125
        if (accessionNumber == null) {
126
            if (other.accessionNumber != null) {
127
                return false;
128
            }
129
        } else if (!accessionNumber.equals(other.accessionNumber)) {
130
            return false;
131
        }
132
        if (collector == null) {
133
            if (other.collector != null) {
134
                return false;
135
            }
136
        } else if (!collector.equals(other.collector)) {
137
            return false;
138
        }
139
        if (collectorsNumber == null) {
140
            if (other.collectorsNumber != null) {
141
                return false;
142
            }
143
        } else if (!collectorsNumber.equals(other.collectorsNumber)) {
144
            return false;
145
        }
146
        if (country == null) {
147
            if (other.country != null) {
148
                return false;
149
            }
150
        } else if (!country.equals(other.country)) {
151
            return false;
152
        }
153
        if (dateFrom == null) {
154
            if (other.dateFrom != null) {
155
                return false;
156
            }
157
        } else if (!dateFrom.equals(other.dateFrom)) {
158
            return false;
159
        }
160
        if (dateTo == null) {
161
            if (other.dateTo != null) {
162
                return false;
163
            }
164
        } else if (!dateTo.equals(other.dateTo)) {
165
            return false;
166
        }
167
        if (herbarium == null) {
168
            if (other.herbarium != null) {
169
                return false;
170
            }
171
        } else if (!herbarium.equals(other.herbarium)) {
172
            return false;
173
        }
174
        if (locality == null) {
175
            if (other.locality != null) {
176
                return false;
177
            }
178
        } else if (!locality.equals(other.locality)) {
179
            return false;
180
        }
181
        if (taxonName == null) {
182
            if (other.taxonName != null) {
183
                return false;
184
            }
185
        } else if (!taxonName.equals(other.taxonName)) {
186
            return false;
187
        }
188
        if (hasImage != other.hasImage) {
189
            return false;
190
        }
191
        if (higherTaxon == null) {
192
            if (other.higherTaxon != null) {
193
                return false;
194
            }
195
        } else if (!higherTaxon.equals(other.higherTaxon)) {
196
            return false;
197
        }
198
        if (tripleIds == null) {
199
            if (other.tripleIds != null) {
200
                return false;
201
            }
202
        } else if (!tripleIds.equals(other.tripleIds)) {
203
            return false;
204
        }
205
        return true;
206
    }
207

    
208

    
209

    
210

    
211
    /* (non-Javadoc)
212
     * @see java.lang.Object#toString()
213
     */
214
    @Override
215
    public String toString() {
216
        String string = "";
217
        if(tripleIds!=null ){
218
            string += " unitId=" ;
219
            for (String[] unitId: tripleIds){
220
                string += unitId.toString() + ", ";
221
            }
222
        }
223
        if(taxonName!=null && !taxonName.trim().isEmpty()){
224
            string += " taxonName=" + taxonName;
225
        }
226
        if(collector!=null && !collector.trim().isEmpty()){
227
            string += " collector=" + collector;
228
        }
229
        if(collectorsNumber!=null && !collectorsNumber.trim().isEmpty()){
230
            string += " collectorsNumber=" + collectorsNumber;
231
        }
232
        if(accessionNumber!=null && !accessionNumber.trim().isEmpty()){
233
            string += " accessionNumber=" + accessionNumber;
234
        }
235
        if(herbarium!=null && !herbarium.trim().isEmpty()){
236
            string += " herbarium=" + herbarium;
237
        }
238
        if(country!=null && !country.trim().isEmpty()){
239
            string += " country=" + country;
240
        }
241
        if(locality!=null && !locality.trim().isEmpty()){
242
            string += " locality=" + locality;
243
        }
244
        if(dateFrom!=null){
245
            string += " dateFrom=" + DATE_FORMAT.format(dateFrom.getTime());
246
        }
247
        if(dateTo!=null){
248
            string += " dateTo=" + DATE_FORMAT.format(dateTo.getTime());
249
        }
250

    
251
        string += " hasImage=" + hasImage;
252

    
253
        return string;
254
    }
255
}
(2-2/2)