View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.core.persistence.api.dao.search;
20  
21  import java.io.Serializable;
22  import java.util.Optional;
23  import org.apache.commons.lang3.builder.EqualsBuilder;
24  import org.apache.commons.lang3.builder.HashCodeBuilder;
25  import org.apache.commons.lang3.builder.ToStringBuilder;
26  
27  public class OrderByClause implements Serializable {
28  
29      private static final long serialVersionUID = -1741826744085524716L;
30  
31      public enum Direction {
32  
33          ASC,
34          DESC
35  
36      }
37  
38      private String field;
39  
40      private Direction direction;
41  
42      public String getField() {
43          return field;
44      }
45  
46      public void setField(final String field) {
47          this.field = field;
48      }
49  
50      public Direction getDirection() {
51          return Optional.ofNullable(direction).orElse(Direction.ASC);
52      }
53  
54      public void setDirection(final Direction direction) {
55          this.direction = direction;
56      }
57  
58      @Override
59      public int hashCode() {
60          return new HashCodeBuilder().
61                  append(field).
62                  append(direction).
63                  build();
64      }
65  
66      @Override
67      public boolean equals(final Object obj) {
68          if (this == obj) {
69              return true;
70          }
71          if (obj == null) {
72              return false;
73          }
74          if (getClass() != obj.getClass()) {
75              return false;
76          }
77          final OrderByClause other = (OrderByClause) obj;
78          return new EqualsBuilder().
79                  append(field, other.field).
80                  append(direction, other.direction).
81                  build();
82      }
83  
84      @Override
85      public String toString() {
86          return new ToStringBuilder(this).
87                  append(field).
88                  append(direction).
89                  build();
90      }
91  }