001 /** GroupClass
002 * A class that handles a single user group.
003 * @author Daniel Fredriksson
004 * @version 0.1
005 *
006 */
007
008 package sharpster.daemon.groupmanagement;
009
010 import java.util.LinkedList;
011
012 public class GroupClass {
013
014 /** The name of the group. */
015 private String name;
016 /** A list containing the users of the group. */
017 private LinkedList users;
018
019 /** Creates the class and initialize the user list. */
020 public GroupClass() {
021 users = new LinkedList();
022 }
023
024 /** Sets the group's name.
025 * @param name The name that is to be assigned to the group.
026 */
027 public void setName(String name) {
028 this.name = name;
029 }
030
031 /** Gets the group's name.
032 * @return The name of the group.
033 */
034 public String getName() {
035 return name;
036 }
037
038 /** Returns a, somewhat, nice string-representation of the group.
039 * @return The group name and its users.
040 */
041 public String toString() {
042 return getName()+":"+users.toString();
043 }
044
045 /** Checks if a given user is a memeber of the group.
046 * @param user A username.
047 * @return True if user is in the group, otherwise false.
048 */
049 public boolean isUserInGroup(String user) {
050 return users.contains(user);
051 }
052
053 /** Removes a given user from the group.
054 * @param user A username.
055 * @return True if user was removed from the group, otherwise false.
056 */
057 public boolean removeUser(String user) {
058 if(!isUserInGroup(user))
059 return false;
060 users.remove(user);
061 return true;
062 }
063
064 /** Adds a given user to the group.
065 * @param A username.
066 * @return True if user was added to the group, otherwise false.
067 */
068 public boolean addUser(String user) {
069 if(isUserInGroup(user))
070 return false;
071 users.add(user);
072 return true;
073 }
074
075 /** Returns a list containing the users in the group.
076 * @return A list containing all the users in the group.
077 */
078 public LinkedList getUsers() {
079 return users;
080 }
081 };