Project

General

Profile

Download (7.48 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 collector = null;
29
    public String collectorsNumber = null;
30
    public String accessionNumber = null;
31
    public String herbarium = null;
32
    public String country = null;
33
    public String locality = null;
34
    public Calendar dateFrom = null;
35
    public Calendar dateTo = null;
36

    
37

    
38

    
39
    public OccurenceQuery(Set<String[]> tripleIds) {
40

    
41
        this(tripleIds, null, null, null, null, null, null, null, null, null);
42
    }
43

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

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

    
76
    /**
77
     * @param unitID
78
     */
79
    public OccurenceQuery(String unitID) {
80
        this.accessionNumber = unitID;
81
    }
82

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

    
103

    
104

    
105

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

    
194

    
195

    
196

    
197
    /* (non-Javadoc)
198
     * @see java.lang.Object#toString()
199
     */
200
    @Override
201
    public String toString() {
202
        String string = "";
203
        if(tripleIds!=null ){
204
            string += " unitId=" ;
205
            for (String[] unitId: tripleIds){
206
                string += unitId + ", ";
207
            }
208
        }
209
        if(taxonName!=null && !taxonName.trim().isEmpty()){
210
            string += " taxonName=" + taxonName;
211
        }
212
        if(collector!=null && !collector.trim().isEmpty()){
213
            string += " collector=" + collector;
214
        }
215
        if(collectorsNumber!=null && !collectorsNumber.trim().isEmpty()){
216
            string += " collectorsNumber=" + collectorsNumber;
217
        }
218
        if(accessionNumber!=null && !accessionNumber.trim().isEmpty()){
219
            string += " accessionNumber=" + accessionNumber;
220
        }
221
        if(herbarium!=null && !herbarium.trim().isEmpty()){
222
            string += " herbarium=" + herbarium;
223
        }
224
        if(country!=null && !country.trim().isEmpty()){
225
            string += " country=" + country;
226
        }
227
        if(locality!=null && !locality.trim().isEmpty()){
228
            string += " locality=" + locality;
229
        }
230
        if(dateFrom!=null){
231
            string += " dateFrom=" + DATE_FORMAT.format(dateFrom.getTime());
232
        }
233
        if(dateTo!=null){
234
            string += " dateTo=" + DATE_FORMAT.format(dateTo.getTime());
235
        }
236
        return string;
237
    }
238
}
(2-2/2)