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 * The contents of entries (possibly a family member) which are restricted
029 * to those that have object class values that satisfy the predicate defined
030 * by Refinement (see 12.3.5), together (in the case of an ancestor or other
031 * family member) with the entry contents as a whole of each subordinate
032 * family member entry; it does not necessarily include the information in
033 * these entries.
034 * 
035 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
036 */
037public class ClassesItem extends ProtectedItem
038{
039    /** The classes refinement. */
040    private final ExprNode classes;
041
042    /**
043     * Creates a new instance.
044     * 
045     * @param classes refinement
046     */
047    public ClassesItem( ExprNode classes )
048    {
049        this.classes = classes;
050    }
051
052
053    /**
054     * Gets the classes refinement.
055     *
056     * @return the classes refinement
057     */
058    public ExprNode getClasses()
059    {
060        return classes;
061    }
062
063
064    /**
065     * {@inheritDoc}
066     */
067    @Override
068    public int hashCode()
069    {
070        int hash = 37;
071        
072        if ( classes != null )
073        {
074            hash = hash * 17 + classes.hashCode();
075        }
076        else
077        {
078            hash = hash * 17 + getClass().getName().hashCode();
079        }
080        
081        return hash;
082    }
083
084
085    /**
086     * {@inheritDoc}
087     */
088    @Override
089    public boolean equals( Object o )
090    {
091        if ( this == o )
092        {
093            return true;
094        }
095
096        if ( o instanceof ClassesItem )
097        {
098            ClassesItem that = ( ClassesItem ) o;
099            
100            if ( classes == null )
101            {
102                return that.classes == null;
103            }
104
105            return classes.equals( that.classes );
106        }
107
108        return false;
109    }
110
111
112    /**
113     * {@inheritDoc}
114     */
115    @Override
116    public String toString()
117    {
118        StringBuilder buf = new StringBuilder();
119
120        buf.append( "classes " );
121        
122        if ( classes != null )
123        {
124            classes.printRefinementToBuffer( buf );
125        }
126
127        return buf.toString();
128    }
129}