View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif.util;
17  
18  import org.apache.commons.lang.builder.EqualsBuilder;
19  import org.apache.commons.lang.builder.HashCodeBuilder;
20  
21  /**
22   * Holds the information for sorting a table by a column.
23   *
24   * <ul>
25   *     <li>column index</li>
26   *     <li>direction</li>
27   *     <li>sort type</li>
28   * </ul>
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class ColumnSort {
33  
34      /**
35       * Sort direction, either ASCending or DESCending.
36       */
37      public enum Direction { ASC, DESC };
38  
39      private final int columnIndex;
40      private final Direction direction;
41      private final String sortType;
42  
43      /**
44       * Constructs a ColumnSort instance.
45       *
46       * @param columnIndex the index of the column to sort on
47       * @param direction the direction of the sort
48       * @param sortType the type of the sort -- see {@link org.kuali.rice.krad.uif.UifConstants.TableToolsValues}.
49       */
50      public ColumnSort(int columnIndex, Direction direction, String sortType) {
51          this.columnIndex = columnIndex;
52          this.direction = direction;
53          this.sortType = sortType;
54      }
55  
56      /**
57       * Get the column index.
58       *
59       * @return the column index
60       */
61      public int getColumnIndex() {
62          return columnIndex;
63      }
64  
65      /**
66       * Get the sort direction.
67       *
68       * @return the sort direction
69       */
70      public Direction getDirection() {
71          return direction;
72      }
73  
74      /**
75       * Get the sort type.
76       *
77       * @return the sort type
78       */
79      public String getSortType() {
80          return sortType;
81      }
82  
83      @Override
84      public boolean equals(Object o) {
85          if (this == o) {
86              return true;
87          }
88          if (o == null || getClass() != o.getClass()) {
89              return false;
90          }
91  
92          return EqualsBuilder.reflectionEquals(this, o);
93      }
94  
95      @Override
96      public int hashCode() {
97          return HashCodeBuilder.reflectionHashCode(this);
98      }
99  }