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   */
20  package org.apache.directory.api.ldap.model.message.controls;
21  
22  
23  /**
24   * Datastructure to store the Attribute name, matching rule ID of the attribute<br>
25   * and the sort order.
26   * 
27   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
28   */
29  public class SortKey
30  {
31      /**
32       * The name/OID of AttributeType we want to use as a key for the sort
33       */
34      private String attributeTypeDesc;
35  
36      /**
37       * The matching rule to use to order the result
38       */
39      private String matchingRuleId;
40  
41      /**
42       * A flag to set to true to get the result in reverse order. Default to false
43       */
44      private boolean reverseOrder = false;
45  
46  
47      /**
48       * Create a new instance of a SortKey for a give AttributeType
49       * 
50       * @param attributeTypeDesc The AttributeType's name or OID to use
51       */
52      public SortKey( String attributeTypeDesc )
53      {
54          this( attributeTypeDesc, null );
55      }
56  
57  
58      /**
59       * Create a new instance of a SortKey for a give AttributeType
60       * 
61       * @param attributeTypeDesc The AttributeType's name or OID to use
62       * @param matchingRuleId The MatchingRule to use
63       */
64      public SortKey( String attributeTypeDesc, String matchingRuleId )
65      {
66          this( attributeTypeDesc, matchingRuleId, false );
67      }
68  
69  
70      /**
71       * Create a new instance of a SortKey for a give AttributeType
72       * 
73       * @param attributeTypeDesc The AttributeType OID to use
74       * @param matchingRuleId The MatchingRule to use
75       * @param reverseOrder The reverseOrder flag
76       */
77      public SortKey( String attributeTypeDesc, String matchingRuleId, boolean reverseOrder )
78      {
79          this.attributeTypeDesc = attributeTypeDesc;
80          this.matchingRuleId = matchingRuleId;
81          this.reverseOrder = reverseOrder;
82      }
83  
84  
85      /**
86       * @return the attributeType name or OID
87       */
88      public String getAttributeTypeDesc()
89      {
90          return attributeTypeDesc;
91      }
92  
93  
94      /**
95       * @param attributeType the attributeType to set
96       */
97      public void setAttributeTypeDesc( String attributeTypeDesc )
98      {
99          this.attributeTypeDesc = attributeTypeDesc;
100     }
101 
102 
103     /**
104      * @return the matchingRuleId
105      */
106     public String getMatchingRuleId()
107     {
108         return matchingRuleId;
109     }
110 
111 
112     /**
113      * @param matchingRuleId the matchingRuleId to set
114      */
115     public void setMatchingRuleId( String matchingRuleId )
116     {
117         this.matchingRuleId = matchingRuleId;
118     }
119 
120 
121     /**
122      * @return the reverseOrder
123      */
124     public boolean isReverseOrder()
125     {
126         return reverseOrder;
127     }
128 
129 
130     /**
131      * @param reverseOrder the reverseOrder to set
132      */
133     public void setReverseOrder( boolean reverseOrder )
134     {
135         this.reverseOrder = reverseOrder;
136     }
137 
138 
139     /**
140      * @see String#toString()
141      */
142     public String toString()
143     {
144         StringBuilder sb = new StringBuilder();
145 
146         sb.append( "SortKey : [" );
147 
148         sb.append( attributeTypeDesc );
149 
150         if ( matchingRuleId != null )
151         {
152             sb.append( ", " ).append( matchingRuleId );
153         }
154 
155         if ( reverseOrder )
156         {
157             sb.append( ", reverse" );
158         }
159 
160         sb.append( ']' );
161         return sb.toString();
162     }
163 }