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 * https://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 * @param attribute The Attribute 47 * @param value The value 48 * @param operator The operator 49 */ 50 private AttributeValueAssertionFilter( String attribute, String value, FilterOperator operator ) 51 { 52 this.attribute = attribute; 53 this.value = value; 54 this.operator = operator; 55 } 56 57 58 /** 59 * Creates an Approximate Filter : ( <attribute> ~= <value> ) 60 * 61 * @param attribute The AttributeType 62 * @param value The Value 63 * @return An instance of the Approximate Filter 64 */ 65 public static AttributeValueAssertionFilter approximatelyEqual( String attribute, String value ) 66 { 67 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.APPROXIMATELY_EQUAL ); 68 } 69 70 71 /** 72 * Creates an equal Filter : ( <attribute> = <value> ) 73 * 74 * @param attribute The AttributeType 75 * @param value The Value 76 * @return An instance of the Equal Filter 77 */ 78 public static AttributeValueAssertionFilter equal( String attribute, String value ) 79 { 80 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.EQUAL ); 81 } 82 83 84 /** 85 * Creates a Greater Than Or Equal Filter : ( <attribute> >= <value> ) 86 * 87 * @param attribute The AttributeType 88 * @param value The Value 89 * @return An instance of the Greater Than Or Equal Filter 90 */ 91 public static AttributeValueAssertionFilter greaterThanOrEqual( String attribute, String value ) 92 { 93 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.GREATER_THAN_OR_EQUAL ); 94 } 95 96 97 /** 98 * Creates a Less Than Or Equal Filter : ( <attribute> <= <value> ) 99 * 100 * @param attribute The AttributeType 101 * @param value The Value 102 * @return An instance of the Less Than Or Equal Filter 103 */ 104 public static AttributeValueAssertionFilter lessThanOrEqual( String attribute, String value ) 105 { 106 return new AttributeValueAssertionFilter( attribute, value, FilterOperator.LESS_THAN_OR_EQUAL ); 107 } 108 109 110 /** 111 * {@inheritDoc} 112 */ 113 @Override 114 public StringBuilder build( StringBuilder builder ) 115 { 116 return builder.append( "(" ).append( attribute ) 117 .append( operator.operator() ) 118 .append( FilterEncoder.encodeFilterValue( value ) ).append( ")" ); 119 } 120 }