001package org.apache.fulcrum.security.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.util.Collection;
023
024import org.apache.fulcrum.security.entity.User;
025
026/**
027 * This class represents a set of Users. It is based on UserSet. Hibernate
028 * doesn't return the right kind of set, so this is used to force the type of
029 * set.
030 * 
031 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
032 * @version $Id$
033 */
034public class UserSet<T extends User> extends SecuritySet<User>
035{
036    /**
037     * Serial number
038     */
039    private static final long serialVersionUID = 4415634631270197073L;
040
041    /**
042     * Constructs an empty UserSet
043     */
044    public UserSet()
045    {
046        super();
047    }
048
049    /**
050     * Constructs a new UserSet with specified contents.
051     * 
052     * If the given collection contains multiple objects that are identical WRT
053     * equals() method, some objects will be overwritten.
054     * 
055     * @param users
056     *            A collection of users to be contained in the set.
057     */
058    public UserSet(Collection<? extends User> users)
059    {
060        this();
061        addAll(users);
062    }
063
064    /**
065     * Returns a User with the given name, if it is contained in this UserSet.
066     * 
067     * @param userName
068     *            Name of User.
069     * @return User if argument matched a User in this UserSet; null if no
070     *         match.
071     * @deprecated use getByName()
072     */
073    @Deprecated
074    public User getUserByName(String userName)
075    {
076        return getByName(userName);
077    }
078
079    /**
080     * Returns a User with the given id, if it is contained in this UserSet.
081     * 
082     * @param userId
083     *            id of the User.
084     * @return User if argument matched a User in this UserSet; null if no
085     *         match.
086     * @deprecated use getById()
087     */
088    @Deprecated
089    public User getUserById(Object userId)
090    {
091        return getById(userId);
092    }
093
094    /**
095     * Print out a UserSet as a String
096     * 
097     * @return The User Set as String
098     * 
099     */
100    @Override
101    public String toString()
102    {
103        StringBuilder sb = new StringBuilder();
104        sb.append("UserSet: ");
105        sb.append(super.toString());
106
107        return sb.toString();
108    }
109}