View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.common.search.dto;
17  
18  import java.io.Serializable;
19  import java.util.ArrayList;
20  import java.util.List;
21  
22  import javax.xml.bind.annotation.XmlAccessType;
23  import javax.xml.bind.annotation.XmlAccessorType;
24  
25  @XmlAccessorType(XmlAccessType.FIELD)
26  public class SearchRequest implements Serializable {
27  	private static final long serialVersionUID = 1L;
28  	private String searchKey;
29  	private List<SearchParam> params;
30  	private String sortColumn;
31  	private SortDirection sortDirection;
32  	private Integer startAt;
33  	private Integer maxResults;
34  	private Boolean neededTotalResults;
35  	
36  	public SearchRequest() {
37  		super();
38  	}
39  
40  	public SearchRequest(String searchKey){
41  		this();
42  		this.searchKey = searchKey;
43  	}
44  
45  	public void addParam(String key, String value){
46  		getParams().add(new SearchParam(key, value));
47  	}
48  	
49  	public void addParam(String key, List<String> value){
50  		getParams().add(new SearchParam(key, value));
51  	}
52  
53  	public String getSearchKey() {
54  		return searchKey;
55  	}
56  	public void setSearchKey(String searchKey) {
57  		this.searchKey = searchKey;
58  	}
59  	public List<SearchParam> getParams() {
60  		if(params == null){
61  			params = new ArrayList<SearchParam>();
62  		}
63  		return params;
64  	}
65  	public void setParams(List<SearchParam> params) {
66  		this.params = params;
67  	}
68  	public String getSortColumn() {
69  		return sortColumn;
70  	}
71  	public void setSortColumn(String sortColumn) {
72  		this.sortColumn = sortColumn;
73  	}
74  	public SortDirection getSortDirection() {
75  		return sortDirection;
76  	}
77  	public void setSortDirection(SortDirection sortDirection) {
78  		this.sortDirection = sortDirection;
79  	}
80  	public Integer getStartAt() {
81  		return startAt;
82  	}
83  	public void setStartAt(Integer startAt) {
84  		this.startAt = startAt;
85  	}
86  	public Integer getMaxResults() {
87  		return maxResults;
88  	}
89  	public void setMaxResults(Integer maxResults) {
90  		this.maxResults = maxResults;
91  	}
92  	public Boolean getNeededTotalResults() {
93  		return neededTotalResults;
94  	}
95  	public void setNeededTotalResults(Boolean neededTotalResults) {
96  		this.neededTotalResults = neededTotalResults;
97  	}
98  	@Override
99  	public String toString() {
100 		return "SearchRequest [searchKey=" + searchKey + ", params=" + params
101 				+ ", sortColumn=" + sortColumn + ", sortDirection="
102 				+ sortDirection + ", startAt=" + startAt + ", maxResults="
103 				+ maxResults + ", neededTotalResults=" + neededTotalResults
104 				+ "]";
105 	}
106 
107     @Override
108     public boolean equals(Object o) {
109         if (this == o) return true;
110         if (o == null || getClass() != o.getClass()) return false;
111 
112         SearchRequest that = (SearchRequest) o;
113 
114         if (maxResults != null ? !maxResults.equals(that.maxResults) : that.maxResults != null) return false;
115         if (neededTotalResults != null ? !neededTotalResults.equals(that.neededTotalResults) : that.neededTotalResults != null)
116             return false;
117         if (params != null ? !params.equals(that.params) : that.params != null) return false;
118         if (searchKey != null ? !searchKey.equals(that.searchKey) : that.searchKey != null) return false;
119         if (sortColumn != null ? !sortColumn.equals(that.sortColumn) : that.sortColumn != null) return false;
120         if (sortDirection != that.sortDirection) return false;
121         if (startAt != null ? !startAt.equals(that.startAt) : that.startAt != null) return false;
122 
123         return true;
124     }
125 
126     @Override
127     public int hashCode() {
128         int result = searchKey != null ? searchKey.hashCode() : 0;
129         result = 31 * result + (params != null ? params.hashCode() : 0);
130         result = 31 * result + (sortColumn != null ? sortColumn.hashCode() : 0);
131         result = 31 * result + (sortDirection != null ? sortDirection.hashCode() : 0);
132         result = 31 * result + (startAt != null ? startAt.hashCode() : 0);
133         result = 31 * result + (maxResults != null ? maxResults.hashCode() : 0);
134         result = 31 * result + (neededTotalResults != null ? neededTotalResults.hashCode() : 0);
135         return result;
136     }
137 }