001 /*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License"). You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at
010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012 * See the License for the specific language governing permissions
013 * and limitations under the License.
014 *
015 * When distributing Covered Code, include this CDDL HEADER in each
016 * file and include the License file at
017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
018 * add the following below this CDDL HEADER, with the fields enclosed
019 * by brackets "[]" replaced with your own identifying information:
020 * Portions Copyright [yyyy] [name of copyright owner]
021 *
022 * CDDL HEADER END
023 *
024 *
025 * Copyright 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.api;
028
029
030
031 import java.util.AbstractSet;
032 import java.util.Collection;
033 import java.util.HashSet;
034 import java.util.Iterator;
035
036 import org.opends.server.types.Entry;
037
038
039
040 /**
041 * This class implements the {@code Set} interface for
042 * {@link org.opends.server.api.SubtreeSpecification}s.
043 * <p>
044 * It is backed by a {@code HashSet} but provides additional
045 * functionality, {@link #isWithinScope(Entry)}, for determining
046 * whether or not an entry is within the scope of one or more
047 * contained {@code SubtreeSpecification}s.
048 */
049 @org.opends.server.types.PublicAPI(
050 stability=org.opends.server.types.StabilityLevel.VOLATILE,
051 mayInstantiate=true,
052 mayExtend=false,
053 mayInvoke=true)
054 public final class SubtreeSpecificationSet
055 extends AbstractSet<SubtreeSpecification>
056 {
057 // Underlying implementation is simply a set.
058 private HashSet<SubtreeSpecification> pimpl;
059
060
061
062 /**
063 * Constructs a new empty subtree specification set.
064 */
065 public SubtreeSpecificationSet()
066 {
067 this.pimpl = new HashSet<SubtreeSpecification>();
068 }
069
070
071
072 /**
073 * Constructs a new subtree specification set containing the
074 * elements in the specified collection.
075 *
076 * @param c The subtree specification collection whose elements
077 * are to be placed into this set.
078 */
079 public SubtreeSpecificationSet(
080 Collection<? extends SubtreeSpecification> c)
081 {
082 this.pimpl = new HashSet<SubtreeSpecification>(c);
083 }
084
085
086
087 /**
088 * Returns {@code true} if the specified entry is within the scope
089 * of a subtree specifications contained in the set.
090 *
091 * @param entry The entry to be checked for containment.
092 *
093 * @return Returns {@code true} if the set contains the specified
094 * entry.
095 */
096 public boolean isWithinScope(Entry entry)
097 {
098 for (SubtreeSpecification subtreeSpecification : pimpl)
099 {
100 if (subtreeSpecification.isWithinScope(entry))
101 {
102 return true;
103 }
104 }
105
106 return false;
107 }
108
109
110
111 /**
112 * Adds the provided subtree specification object to this set.
113 *
114 * @param e The subtree specification object to be added.
115 *
116 * @return {@code true} if the element was added to the set, or
117 * {@code false} if the element was already contained in
118 * the set.
119 */
120 @Override
121 public boolean add(SubtreeSpecification e)
122 {
123 return pimpl.add(e);
124 }
125
126
127
128 /**
129 * Retrieves an iterator that may be used to step through the values
130 * in this set.
131 *
132 * @return An iterator that may be used to step through the values
133 * in this set.
134 */
135 @Override
136 public Iterator<SubtreeSpecification> iterator()
137 {
138 return pimpl.iterator();
139 }
140
141
142
143 /**
144 * Indicates whether this set contains the provided object.
145 *
146 * @param o The object for which to make the determination.
147 *
148 * @return {@code true} if this set contains the provided object,
149 * or {@code false} if not.
150 */
151 @Override
152 public boolean contains(Object o)
153 {
154 return pimpl.contains(o);
155 }
156
157
158
159 /**
160 * Retrieves the number of elements contained in this set.
161 *
162 * @return The number of elements contained in this set.
163 */
164 @Override
165 public int size()
166 {
167 return pimpl.size();
168 }
169 }
170