View Javadoc

1   /*
2   * Licensed to the Apache Software Foundation (ASF) under one or more
3   * contributor license agreements.  See the NOTICE file distributed with
4   * this work for additional information regarding copyright ownership.
5   * The ASF licenses this file to You under the Apache License, Version 2.0
6   * (the "License"); you may not use this file except in compliance with
7   * the License.  You may obtain a copy of the License at
8   *
9   *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17  package org.apache.jetspeed.security.impl;
18  
19  import java.util.Collection;
20  import java.util.HashSet;
21  import java.util.Iterator;
22  import java.util.LinkedList;
23  import java.util.List;
24  import java.util.Set;
25  
26  
27  /***
28   * PrincipalsSet - provides an ordered 'set' of principals required
29   * for some profiling rules that are dependent on order of insert.
30   * 
31   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
32   * @version $Id: $
33   */
34  
35  public class PrincipalsSet implements Set
36  {
37      List principals = new LinkedList();
38      Set set = new HashSet();
39  
40      public PrincipalsSet()
41      {}
42      
43      /* (non-Javadoc)
44       * @see java.util.Collection#size()
45       */
46      public int size()
47      {
48          return principals.size();
49      }
50  
51      /* (non-Javadoc)
52       * @see java.util.Collection#clear()
53       */
54      public void clear()
55      {
56          set.clear();
57          principals.clear();
58      }
59  
60      /* (non-Javadoc)
61       * @see java.util.Collection#isEmpty()
62       */
63      public boolean isEmpty()
64      {
65          return principals.isEmpty();
66      }
67  
68      /* (non-Javadoc)
69       * @see java.util.Collection#toArray()
70       */
71      public Object[] toArray()
72      {
73          return principals.toArray();
74      }
75  
76      /* (non-Javadoc)
77       * @see java.util.Collection#add(java.lang.Object)
78       */
79      public boolean add(Object o)
80      {
81          if (set.add(o))
82          {
83              principals.add(o);
84              return true;
85          }
86          return false;
87      }
88  
89      /* (non-Javadoc)
90       * @see java.util.Collection#contains(java.lang.Object)
91       */
92      public boolean contains(Object o)
93      {
94          return set.contains(o);
95      }
96  
97      /* (non-Javadoc)
98       * @see java.util.Collection#remove(java.lang.Object)
99       */
100     public boolean remove(Object o)
101     {
102         set.remove(o);
103         return principals.remove(o);
104     }
105 
106     /* (non-Javadoc)
107      * @see java.util.Collection#addAll(java.util.Collection)
108      */
109     public boolean addAll(Collection c)
110     {
111         set.addAll(c);
112         return principals.addAll(c);
113     }
114 
115     /* (non-Javadoc)
116      * @see java.util.Collection#containsAll(java.util.Collection)
117      */
118     public boolean containsAll(Collection c)
119     {
120         return set.containsAll(c);
121     }
122 
123     /* (non-Javadoc)
124      * @see java.util.Collection#removeAll(java.util.Collection)
125      */
126     public boolean removeAll(Collection c)
127     {
128         set.removeAll(c);
129         return principals.removeAll(c);
130     }
131 
132     /* (non-Javadoc)
133      * @see java.util.Collection#retainAll(java.util.Collection)
134      */
135     public boolean retainAll(Collection c)
136     {
137         set.retainAll(c);
138         return principals.retainAll(c);
139     }
140 
141     /* (non-Javadoc)
142      * @see java.util.Collection#iterator()
143      */
144     public Iterator iterator()
145     {
146         return principals.iterator();
147     }
148 
149     /* (non-Javadoc)
150      * @see java.util.Collection#toArray(java.lang.Object[])
151      */
152     public Object[] toArray(Object[] a)
153     {
154         return principals.toArray(a);
155     }
156 
157 }