Users.java 1.22 KB
Newer Older
Luca Arrotta's avatar
Luca Arrotta committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
package REST.beans;
/**
 * Created by civi on 26/04/16.
 */
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@XmlAccessorType (XmlAccessType.FIELD)
public class Users {

17
    @XmlElement(name="my_users")
Luca Arrotta's avatar
Luca Arrotta committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
    private List<User> userslist;

    private static Users instance;

    private Users() {
        userslist = new ArrayList<User>();
    }

    //singleton
    public synchronized static Users getInstance(){
        if(instance==null)
            instance = new Users();
        return instance;
    }

    public synchronized List<User> getUserslist() {

        return new ArrayList<>(userslist);

    }

    public synchronized void setUserslist(List<User> userslist) {
        this.userslist = userslist;
    }

    public synchronized void add(User u){
        userslist.add(u);
    }


48
    public User getByName(String name){
Luca Arrotta's avatar
Luca Arrotta committed
49 50 51 52 53 54 55 56
        List<User> usersCopy = getUserslist();
        for(User u: usersCopy)
            if(u.getName().toLowerCase().equals(name.toLowerCase()))
                return u;
        return null;
    }

}