1 package org.apache.fulcrum.security.model.basic.entity.impl;
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.Set;
23
24 import org.apache.fulcrum.security.entity.User;
25 import org.apache.fulcrum.security.entity.impl.SecurityEntityImpl;
26 import org.apache.fulcrum.security.model.basic.entity.BasicGroup;
27 import org.apache.fulcrum.security.util.UserSet;
28
29 /**
30 * Represents the "basic" model where users are part of groups, but nothing
31 * else.
32 *
33 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
34 * @version $Id: BasicGroup.java 223057 2004-07-05 19:28:23Z epugh $
35 */
36 public class BasicGroupImpl extends SecurityEntityImpl implements BasicGroup
37 {
38 /**
39 * Serial version
40 */
41 private static final long serialVersionUID = 8754093174457116551L;
42
43 /** User set **/
44 private Set<? extends User> userSet = new UserSet<>();
45
46 /**
47 * Get the users that are part of this group
48 *
49 * @return a set of users
50 */
51 public UserSet<?> getUsers()
52 {
53 if (userSet instanceof UserSet)
54 {
55 return (UserSet<?>) userSet;
56 }
57 else
58 {
59 userSet = new UserSet<>(userSet);
60 return (UserSet<?>) userSet;
61 }
62 }
63
64 /**
65 * Set the users that are part of this group
66 *
67 * @param userSet
68 * a set of users
69 */
70 public void setUsers(UserSet userSet)
71 {
72 if (userSet != null)
73 {
74 this.userSet = userSet;
75 }
76 else
77 {
78 this.userSet = new UserSet<>();
79 }
80 }
81
82 /**
83 * Get the users that are part of this group as a Set
84 *
85 * @return a set of users
86 */
87 @SuppressWarnings("unchecked")
88 public <T extends User> Set<T> getUsersAsSet()
89 {
90 return (Set<T>) userSet;
91 }
92
93 /**
94 * Set the users that are part of this group as a Set
95 *
96 * @param users
97 * a set of users
98 */
99 public <T extends User> void setUsersAsSet(Set<T> users)
100 {
101 this.userSet = users;
102 }
103
104 /**
105 * Add a user to this group
106 *
107 * @param user
108 * the user to add
109 */
110 public void addUser(User user)
111 {
112 getUsers().add(user);
113 }
114
115 /**
116 * Remove a user from this group
117 *
118 * @param user
119 * the user to remove
120 */
121 public void removeUser(User user)
122 {
123 getUsers().remove(user);
124 }
125 }