Project

General

Profile

Download (7.35 KB) Statistics
| Branch: | Tag: | Revision:
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.io.Serializable;
13
import java.text.SimpleDateFormat;
14
import java.util.Calendar;
15
import java.util.Set;
16

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

    
26
    public final Set<String[]> tripleIds;
27

    
28
    public final String taxonName;
29
    public final String collector;
30
    public final String collectorsNumber;
31
    public final String accessionNumber;
32
    public final String herbarium;
33
    public final String country;
34
    public final String locality;
35
    public final Calendar dateFrom;
36
    public final Calendar dateTo;
37

    
38

    
39

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

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

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

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

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

    
97

    
98

    
99

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

    
188

    
189

    
190

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