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 025/** 026 * Datastructure to store the Attribute name, matching rule ID of the attribute<br> 027 * and the sort order. 028 * 029 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 030 */ 031public class SortKey 032{ 033 /** 034 * The name/OID of AttributeType we want to use as a key for the sort 035 */ 036 private String attributeTypeDesc; 037 038 /** 039 * The matching rule to use to order the result 040 */ 041 private String matchingRuleId; 042 043 /** 044 * A flag to set to true to get the result in reverse order 045 */ 046 private boolean reverseOrder; 047 048 049 /** 050 * Create a new instance of a SortKey for a give AttributeType 051 * 052 * @param attributeTypeDesc The AttributeType's name or OID to use 053 */ 054 public SortKey( String attributeTypeDesc ) 055 { 056 this( attributeTypeDesc, null ); 057 } 058 059 060 /** 061 * Create a new instance of a SortKey for a give AttributeType 062 * 063 * @param attributeTypeDesc The AttributeType's name or OID to use 064 * @param matchingRuleId The MatchingRule to use 065 */ 066 public SortKey( String attributeTypeDesc, String matchingRuleId ) 067 { 068 this( attributeTypeDesc, matchingRuleId, false ); 069 } 070 071 072 /** 073 * Create a new instance of a SortKey for a give AttributeType 074 * 075 * @param attributeTypeDesc The AttributeType OID to use 076 * @param matchingRuleId The MatchingRule to use 077 * @param reverseOrder The reverseOrder flag 078 */ 079 public SortKey( String attributeTypeDesc, String matchingRuleId, boolean reverseOrder ) 080 { 081 this.attributeTypeDesc = attributeTypeDesc; 082 this.matchingRuleId = matchingRuleId; 083 this.reverseOrder = reverseOrder; 084 } 085 086 087 /** 088 * @return the attributeType name or OID 089 */ 090 public String getAttributeTypeDesc() 091 { 092 return attributeTypeDesc; 093 } 094 095 096 /** 097 * @param attributeType the attributeType to set 098 */ 099 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}