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.filter;
021
022
023import org.apache.directory.api.ldap.model.entry.Value;
024import org.apache.directory.api.ldap.model.schema.AttributeType;
025
026
027/**
028 * A assertion value node for Equality.
029 * 
030 * @param <T> The Value type
031 * 
032 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
033 */
034public class EqualityNode<T> extends SimpleNode<T>
035{
036    /**
037     * Creates a new Equality object.
038     * 
039     * @param attributeType the attributeType
040     * @param value the value to test for
041     */
042    public EqualityNode( AttributeType attributeType, Value<T> value )
043    {
044        super( attributeType, value, AssertionType.EQUALITY );
045    }
046
047
048    /**
049     * Creates a new Equality object.
050     * 
051     * @param attribute the attribute name
052     * @param value the value to test for
053     */
054    public EqualityNode( String attribute, Value<T> value )
055    {
056        super( attribute, value, AssertionType.EQUALITY );
057    }
058
059
060    /**
061     * @see Object#toString()
062     * @return A string representing the AndNode
063     */
064    @Override
065    public String toString()
066    {
067        StringBuilder buf = new StringBuilder();
068
069        buf.append( '(' );
070
071        if ( attributeType != null )
072        {
073            buf.append( attributeType.getName() );
074        }
075        else
076        {
077            buf.append( attribute );
078        }
079
080        buf.append( "=" );
081
082        Value<?> escapedValue = getEscapedValue();
083        if ( !escapedValue.isNull() )
084        {
085            buf.append( escapedValue );
086        }
087
088        buf.append( super.toString() );
089
090        buf.append( ')' );
091
092        return buf.toString();
093    }
094}