2 * Copyright (C) 2013 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.ext
.occurrence
;
11 import java
.io
.Serializable
;
12 import java
.text
.SimpleDateFormat
;
13 import java
.util
.Calendar
;
17 * Holds query parameters for a query to an occurrence provider.
22 public class OccurenceQuery
implements Serializable
{
23 public static SimpleDateFormat DATE_FORMAT
= new SimpleDateFormat("yyyy-MM-dd");
25 public Set
<String
[]> tripleIds
= null;
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;
41 public OccurenceQuery(Set
<String
[]> tripleIds
) {
43 this(tripleIds
, null, null, null, null, null, null, null, null, null, null, false);
49 * @param collectorsNumber
50 * @param accessionNumber
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
);
63 * Constructor to initially set the parameters
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
;
76 this.hasImage
= hasImage
;
82 public OccurenceQuery(String unitID
) {
83 this.accessionNumber
= unitID
;
87 * @see java.lang.Object#hashCode()
90 public int hashCode() {
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());
111 * @see java.lang.Object#equals(java.lang.Object)
114 public boolean equals(Object obj
) {
121 if (getClass() != obj
.getClass()) {
124 OccurenceQuery other
= (OccurenceQuery
) obj
;
125 if (accessionNumber
== null) {
126 if (other
.accessionNumber
!= null) {
129 } else if (!accessionNumber
.equals(other
.accessionNumber
)) {
132 if (collector
== null) {
133 if (other
.collector
!= null) {
136 } else if (!collector
.equals(other
.collector
)) {
139 if (collectorsNumber
== null) {
140 if (other
.collectorsNumber
!= null) {
143 } else if (!collectorsNumber
.equals(other
.collectorsNumber
)) {
146 if (country
== null) {
147 if (other
.country
!= null) {
150 } else if (!country
.equals(other
.country
)) {
153 if (dateFrom
== null) {
154 if (other
.dateFrom
!= null) {
157 } else if (!dateFrom
.equals(other
.dateFrom
)) {
160 if (dateTo
== null) {
161 if (other
.dateTo
!= null) {
164 } else if (!dateTo
.equals(other
.dateTo
)) {
167 if (herbarium
== null) {
168 if (other
.herbarium
!= null) {
171 } else if (!herbarium
.equals(other
.herbarium
)) {
174 if (locality
== null) {
175 if (other
.locality
!= null) {
178 } else if (!locality
.equals(other
.locality
)) {
181 if (taxonName
== null) {
182 if (other
.taxonName
!= null) {
185 } else if (!taxonName
.equals(other
.taxonName
)) {
188 if (hasImage
!= other
.hasImage
) {
191 if (higherTaxon
== null) {
192 if (other
.higherTaxon
!= null) {
195 } else if (!higherTaxon
.equals(other
.higherTaxon
)) {
198 if (tripleIds
== null) {
199 if (other
.tripleIds
!= null) {
202 } else if (!tripleIds
.equals(other
.tripleIds
)) {
212 * @see java.lang.Object#toString()
215 public String
toString() {
217 if(tripleIds
!=null ){
218 string
+= " unitId=" ;
219 for (String
[] unitId
: tripleIds
){
220 string
+= unitId
.toString() + ", ";
223 if(taxonName
!=null && !taxonName
.trim().isEmpty()){
224 string
+= " taxonName=" + taxonName
;
226 if(collector
!=null && !collector
.trim().isEmpty()){
227 string
+= " collector=" + collector
;
229 if(collectorsNumber
!=null && !collectorsNumber
.trim().isEmpty()){
230 string
+= " collectorsNumber=" + collectorsNumber
;
232 if(accessionNumber
!=null && !accessionNumber
.trim().isEmpty()){
233 string
+= " accessionNumber=" + accessionNumber
;
235 if(herbarium
!=null && !herbarium
.trim().isEmpty()){
236 string
+= " herbarium=" + herbarium
;
238 if(country
!=null && !country
.trim().isEmpty()){
239 string
+= " country=" + country
;
241 if(locality
!=null && !locality
.trim().isEmpty()){
242 string
+= " locality=" + locality
;
245 string
+= " dateFrom=" + DATE_FORMAT
.format(dateFrom
.getTime());
248 string
+= " dateTo=" + DATE_FORMAT
.format(dateTo
.getTime());
251 string
+= " hasImage=" + hasImage
;