View Javadoc
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.api.ldap.aci.protectedItem;
21  
22  
23  import org.apache.directory.api.i18n.I18n;
24  import org.apache.directory.api.ldap.aci.ProtectedItem;
25  import org.apache.directory.api.ldap.model.filter.ExprNode;
26  
27  
28  /**
29   * Any attribute value which matches the specified filter, i.e. for which
30   * the specified filter evaluated on that attribute value would return TRUE.
31   * 
32   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
33   */
34  public class RangeOfValuesItem extends ProtectedItem
35  {
36      /** The filter. */
37      private final ExprNode filter;
38  
39      /**
40       * Creates a new instance.
41       * 
42       * @param filter the expression
43       */
44      public RangeOfValuesItem( ExprNode filter )
45      {
46          if ( filter == null )
47          {
48              throw new IllegalArgumentException( I18n.err( I18n.ERR_07000_FILTER ) );
49          }
50  
51          this.filter = filter;
52      }
53  
54  
55      /**
56       * Gets the refinement.
57       *
58       * @return the refinement
59       */
60      public ExprNode getRefinement()
61      {
62          return filter;
63      }
64  
65  
66      /**
67       * {@inheritDoc}
68       */
69      @Override
70      public int hashCode()
71      {
72          int hash = 37;
73          
74          if ( filter != null )
75          {
76              hash = hash * 17 + filter.hashCode();
77          }
78  
79          return hash;
80      }
81  
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      public boolean equals( Object o )
88      {
89          if ( this == o )
90          {
91              return true;
92          }
93  
94          if ( o instanceof RangeOfValuesItem )
95          {
96              RangeOfValuesItem that = ( RangeOfValuesItem ) o;
97              
98              return filter.equals( that.filter );
99          }
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 }