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.aci.protectedItem;
021
022
023import org.apache.directory.api.ldap.aci.ProtectedItem;
024import org.apache.directory.api.ldap.model.filter.ExprNode;
025
026
027/**
028 * Any attribute value which matches the specified filter, i.e. for which
029 * the specified filter evaluated on that attribute value would return TRUE.
030 */
031public class RangeOfValuesItem extends ProtectedItem
032{
033
034    /** The filter. */
035    private final ExprNode filter;
036
037
038    /**
039     * Creates a new instance.
040     * 
041     * @param filter the expression
042     */
043    public RangeOfValuesItem( ExprNode filter )
044    {
045        if ( filter == null )
046        {
047            throw new IllegalArgumentException( "filter" );
048        }
049
050        this.filter = filter;
051    }
052
053
054    /**
055     * Gets the filter.
056     * 
057     * TODO: rename to getFilter()
058     *
059     * @return the filter
060     */
061    public ExprNode getRefinement()
062    {
063        return filter;
064    }
065
066
067    /**
068     * {@inheritDoc}
069     */
070    @Override
071    public int hashCode()
072    {
073        int hash = 37;
074        hash = hash * 17 + filter.hashCode();
075        return hash;
076    }
077
078
079    /**
080     * {@inheritDoc}
081     */
082    @Override
083    public boolean equals( Object o )
084    {
085        if ( this == o )
086        {
087            return true;
088        }
089
090        if ( o instanceof RangeOfValuesItem )
091        {
092            RangeOfValuesItem that = ( RangeOfValuesItem ) o;
093            return this.filter.equals( that.filter );
094        }
095
096        return false;
097    }
098
099
100    /**
101     * @see Object#toString()
102     */
103    public String toString()
104    {
105        StringBuilder buf = new StringBuilder();
106
107        buf.append( "rangeOfValues " );
108        buf.append( filter.toString() );
109
110        return buf.toString();
111    }
112}