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