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.ldap.client.api.search; 21 22 23 import org.apache.directory.api.ldap.model.filter.FilterEncoder; 24 25 26 /** 27 * A class to represent the various filters that take a value, like =, <=, >= or ~=. 28 * 29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 30 */ 31 /* No qualifier*/final class AttributeValueAssertionFilter extends AbstractFilter 32 { 33 /** The associated attribute */ 34 private String attribute; 35 36 /** The filter value */ 37 private String value; 38 39 /** The Filter operator */ 40 private FilterOperator operator; 41 42 43 /** 44 * Creates a new instance of AttributeValueAssertionFilter. 45 */ 46 private AttributeValueAssertionFilter( String attribute, String value, FilterOperator operator ) 47 { 48 this.attribute = attribute; 49 this.value = value; 50 this.operator = operator; 51 } 52 53 54 /** 55 * Creates an Approximate Filter : ( <attribute> ~= <value> ) 56 * 57 * @param attribute The AttributeType 58 * @param value The Value 59 * @return An instance of the Approximate Filter 60 */ 61 public static AttributeValueAssertionFilter approximatelyEqual( String attribute, String value ) 62 { 63 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.APPROXIMATELY_EQUAL ); 64 } 65 66 67 /** 68 * Creates an equal Filter : ( <attribute> = <value> ) 69 * 70 * @param attribute The AttributeType 71 * @param value The Value 72 * @return An instance of the Equal Filter 73 */ 74 public static AttributeValueAssertionFilter equal( String attribute, String value ) 75 { 76 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.EQUAL ); 77 } 78 79 80 /** 81 * Creates a Greater Than Or Equal Filter : ( <attribute> >= <value> ) 82 * 83 * @param attribute The AttributeType 84 * @param value The Value 85 * @return An instance of the Greater Than Or Equal Filter 86 */ 87 public static AttributeValueAssertionFilter greaterThanOrEqual( String attribute, String value ) 88 { 89 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.GREATER_THAN_OR_EQUAL ); 90 } 91 92 93 /** 94 * Creates a Less Than Or Equal Filter : ( <attribute> <= <value> ) 95 * 96 * @param attribute The AttributeType 97 * @param value The Value 98 * @return An instance of the Less Than Or Equal Filter 99 */ 100 public static AttributeValueAssertionFilter lessThanOrEqual( String attribute, String value ) 101 { 102 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.LESS_THAN_OR_EQUAL ); 103 } 104 105 106 /** 107 * {@inheritDoc} 108 */ 109 @Override 110 public StringBuilder build( StringBuilder builder ) 111 { 112 return builder.append( "(" ).append( attribute ) 113 .append( operator.operator() ) 114 .append( FilterEncoder.encodeFilterValue( value ) ).append( ")" ); 115 } 116 }