View Javadoc

1   /**
2    * Copyright 2005-2012 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.core.api.search;
17  
18  import org.apache.commons.lang.StringUtils;
19  
20  /**
21   * Represents a search range
22   */
23  public class Range {
24      private String lowerBoundValue;
25      private String upperBoundValue;
26      private boolean lowerBoundInclusive = true;
27      private boolean upperBoundInclusive = true;
28  
29      public String getLowerBoundValue() {
30          return lowerBoundValue;
31      }
32  
33      public void setLowerBoundValue(String lowerBoundValue) {
34          this.lowerBoundValue = lowerBoundValue;
35      }
36  
37      public String getUpperBoundValue() {
38          return upperBoundValue;
39      }
40  
41      public void setUpperBoundValue(String upperBoundValue) {
42          this.upperBoundValue = upperBoundValue;
43      }
44  
45      public boolean isLowerBoundInclusive() {
46          return lowerBoundInclusive;
47      }
48  
49      public void setLowerBoundInclusive(boolean lowerBoundInclusive) {
50          this.lowerBoundInclusive = lowerBoundInclusive;
51      }
52  
53      public boolean isUpperBoundInclusive() {
54          return upperBoundInclusive;
55      }
56  
57      public void setUpperBoundInclusive(boolean upperBoundInclusive) {
58          this.upperBoundInclusive = upperBoundInclusive;
59      }
60  
61      public String toString() {
62          if (StringUtils.isNotEmpty(lowerBoundValue) && StringUtils.isNotEmpty(upperBoundValue)) {
63              SearchOperator op;
64              if (lowerBoundInclusive && upperBoundInclusive) {
65                  op = SearchOperator.BETWEEN;
66              } else if (lowerBoundInclusive && !upperBoundInclusive) {
67                  op = SearchOperator.BETWEEN_EXCLUSIVE_UPPER2;
68              } else if (!lowerBoundInclusive && upperBoundInclusive) {
69                  op = SearchOperator.BETWEEN_EXCLUSIVE_LOWER;
70              } else {
71                  op = SearchOperator.BETWEEN_EXCLUSIVE;
72              }
73              return lowerBoundValue + op.op() + upperBoundValue;
74          } else if (StringUtils.isNotEmpty(lowerBoundValue) && StringUtils.isEmpty(upperBoundValue)) {
75              SearchOperator op = lowerBoundInclusive ? SearchOperator.GREATER_THAN_EQUAL : SearchOperator.GREATER_THAN;
76              return op.op() + lowerBoundValue;
77          } else if (StringUtils.isNotEmpty(upperBoundValue) && StringUtils.isEmpty(lowerBoundValue)) {
78              SearchOperator op = upperBoundInclusive ? SearchOperator.LESS_THAN_EQUAL : SearchOperator.LESS_THAN;
79              return op.op() + upperBoundValue;
80          } else { // both are empty
81              return "";
82          }
83      }
84  }