1 package org.apache.fulcrum.security.util;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.util.Collection;
23
24 import org.apache.fulcrum.security.entity.Group;
25
26 /**
27 * This class represents a set of Groups. It's useful for building
28 * administration UI. It enforces that only Group objects are allowed in the set
29 * and only relevant methods are available.
30 *
31 * @author <a href="mailto:john.mcnally@clearink.com">John D. McNally</a>
32 * @author <a href="mailto:bmclaugh@algx.net">Brett McLaughlin</a>
33 * @author <a href="mailto:marco@intermeta.de">Marco Knüttel</a>
34 * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
35 * @version $Id$
36 */
37 public class GroupSet extends SecuritySet<Group>
38 {
39 /**
40 * Serial number
41 */
42 private static final long serialVersionUID = 6882240173053961011L;
43
44 /**
45 * Constructs an empty GroupSet
46 */
47 public GroupSet()
48 {
49 super();
50 }
51
52 /**
53 * Constructs a new GroupSet with specified contents.
54 *
55 * If the given collection contains multiple objects that are identical WRT
56 * equals() method, some objects will be overwritten.
57 *
58 * @param groups
59 * A collection of groups to be contained in the set.
60 */
61 public GroupSet(Collection<? extends Group> groups)
62 {
63 this();
64 addAll(groups);
65 }
66
67 /**
68 * Returns a Group with the given name, if it is contained in this GroupSet.
69 *
70 * @param groupName
71 * Name of Group.
72 * @return Group if argument matched a Group in this GroupSet; null if no
73 * match.
74 * @deprecated Use getByName()
75 */
76 @Deprecated
77 public Group getGroupByName(String groupName)
78 {
79 return getByName(groupName);
80 }
81
82 /**
83 * Returns a Group with the given id, if it is contained in this GroupSet.
84 *
85 * @param groupId
86 * Id of the group
87 * @return Group if argument matched a Group in this GroupSet; null if no
88 * match.
89 * @deprecated Use getById()
90 */
91 @Deprecated
92 public Group getGroupById(Object groupId)
93 {
94 return getById(groupId);
95 }
96
97 /**
98 * Print out a GroupSet as a String
99 *
100 * @return The Group Set as String
101 *
102 */
103 @Override
104 public String toString()
105 {
106 StringBuilder sb = new StringBuilder();
107 sb.append("GroupSet: ");
108 sb.append(super.toString());
109
110 return sb.toString();
111 }
112 }