001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security.impl;
018:
019: import java.util.Collection;
020: import java.util.HashSet;
021: import java.util.Iterator;
022: import java.util.LinkedList;
023: import java.util.List;
024: import java.util.Set;
025:
026: /**
027: * PrincipalsSet - provides an ordered 'set' of principals required
028: * for some profiling rules that are dependent on order of insert.
029: *
030: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
031: * @version $Id: $
032: */
033:
034: public class PrincipalsSet implements Set {
035: List principals = new LinkedList();
036: Set set = new HashSet();
037:
038: public PrincipalsSet() {
039: }
040:
041: /* (non-Javadoc)
042: * @see java.util.Collection#size()
043: */
044: public int size() {
045: return principals.size();
046: }
047:
048: /* (non-Javadoc)
049: * @see java.util.Collection#clear()
050: */
051: public void clear() {
052: set.clear();
053: principals.clear();
054: }
055:
056: /* (non-Javadoc)
057: * @see java.util.Collection#isEmpty()
058: */
059: public boolean isEmpty() {
060: return principals.isEmpty();
061: }
062:
063: /* (non-Javadoc)
064: * @see java.util.Collection#toArray()
065: */
066: public Object[] toArray() {
067: return principals.toArray();
068: }
069:
070: /* (non-Javadoc)
071: * @see java.util.Collection#add(java.lang.Object)
072: */
073: public boolean add(Object o) {
074: if (set.add(o)) {
075: principals.add(o);
076: return true;
077: }
078: return false;
079: }
080:
081: /* (non-Javadoc)
082: * @see java.util.Collection#contains(java.lang.Object)
083: */
084: public boolean contains(Object o) {
085: return set.contains(o);
086: }
087:
088: /* (non-Javadoc)
089: * @see java.util.Collection#remove(java.lang.Object)
090: */
091: public boolean remove(Object o) {
092: set.remove(o);
093: return principals.remove(o);
094: }
095:
096: /* (non-Javadoc)
097: * @see java.util.Collection#addAll(java.util.Collection)
098: */
099: public boolean addAll(Collection c) {
100: set.addAll(c);
101: return principals.addAll(c);
102: }
103:
104: /* (non-Javadoc)
105: * @see java.util.Collection#containsAll(java.util.Collection)
106: */
107: public boolean containsAll(Collection c) {
108: return set.containsAll(c);
109: }
110:
111: /* (non-Javadoc)
112: * @see java.util.Collection#removeAll(java.util.Collection)
113: */
114: public boolean removeAll(Collection c) {
115: set.removeAll(c);
116: return principals.removeAll(c);
117: }
118:
119: /* (non-Javadoc)
120: * @see java.util.Collection#retainAll(java.util.Collection)
121: */
122: public boolean retainAll(Collection c) {
123: set.retainAll(c);
124: return principals.retainAll(c);
125: }
126:
127: /* (non-Javadoc)
128: * @see java.util.Collection#iterator()
129: */
130: public Iterator iterator() {
131: return principals.iterator();
132: }
133:
134: /* (non-Javadoc)
135: * @see java.util.Collection#toArray(java.lang.Object[])
136: */
137: public Object[] toArray(Object[] a) {
138: return principals.toArray(a);
139: }
140:
141: }
|