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