001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.directory.api.ldap.model.message.controls;
021
022
023/**
024 * Datastructure to store the Attribute name, matching rule ID of the attribute<br>
025 * and the sort order.
026 * 
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public class SortKey
030{
031    /**
032     * The name/OID of AttributeType we want to use as a key for the sort
033     */
034    private String attributeTypeDesc;
035
036    /**
037     * The matching rule to use to order the result
038     */
039    private String matchingRuleId;
040
041    /**
042     * A flag to set to true to get the result in reverse order. Default to false
043     */
044    private boolean reverseOrder = false;
045
046
047    /**
048     * Create a new instance of a SortKey for a give AttributeType
049     * 
050     * @param attributeTypeDesc The AttributeType's name or OID to use
051     */
052    public SortKey( String attributeTypeDesc )
053    {
054        this( attributeTypeDesc, null );
055    }
056
057
058    /**
059     * Create a new instance of a SortKey for a give AttributeType
060     * 
061     * @param attributeTypeDesc The AttributeType's name or OID to use
062     * @param matchingRuleId The MatchingRule to use
063     */
064    public SortKey( String attributeTypeDesc, String matchingRuleId )
065    {
066        this( attributeTypeDesc, matchingRuleId, false );
067    }
068
069
070    /**
071     * Create a new instance of a SortKey for a give AttributeType
072     * 
073     * @param attributeTypeDesc The AttributeType OID to use
074     * @param matchingRuleId The MatchingRule to use
075     * @param reverseOrder The reverseOrder flag
076     */
077    public SortKey( String attributeTypeDesc, String matchingRuleId, boolean reverseOrder )
078    {
079        this.attributeTypeDesc = attributeTypeDesc;
080        this.matchingRuleId = matchingRuleId;
081        this.reverseOrder = reverseOrder;
082    }
083
084
085    /**
086     * @return the attributeType name or OID
087     */
088    public String getAttributeTypeDesc()
089    {
090        return attributeTypeDesc;
091    }
092
093
094    /**
095     * @param attributeTypeDesc the attributeType to set
096     */
097    public void setAttributeTypeDesc( String attributeTypeDesc )
098    {
099        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    @Override
143    public String toString()
144    {
145        StringBuilder sb = new StringBuilder();
146
147        sb.append( "SortKey : [" );
148
149        sb.append( attributeTypeDesc );
150
151        if ( matchingRuleId != null )
152        {
153            sb.append( ", " ).append( matchingRuleId );
154        }
155
156        if ( reverseOrder )
157        {
158            sb.append( ", reverse" );
159        }
160
161        sb.append( ']' );
162        return sb.toString();
163    }
164}