001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Nuxeo - initial API and implementation
011 *
012 * $Id$
013 */
014
015package org.nuxeo.ecm.core.api.impl;
016
017import java.util.ArrayList;
018import java.util.List;
019
020import org.nuxeo.ecm.core.api.NuxeoGroup;
021
022/**
023 * @author <a href="mailto:glefter@nuxeo.com">George Lefter</a>
024 */
025public class NuxeoGroupImpl implements NuxeoGroup {
026
027    private static final long serialVersionUID = -69828664399387083L;
028
029    private final List<String> users;
030
031    private final List<String> groups;
032
033    private final List<String> parentGroups;
034
035    private String name;
036
037    private String label;
038
039    public NuxeoGroupImpl(String name) {
040        if (name == null) {
041            throw new IllegalArgumentException("group name cannot be null");
042        }
043        this.name = name.trim();
044        label = name.trim();
045        users = new ArrayList<String>();
046        groups = new ArrayList<String>();
047        parentGroups = new ArrayList<String>();
048    }
049
050    public NuxeoGroupImpl(String name, String label) {
051        this(name);
052        this.label = label;
053    }
054
055    @Override
056    public List<String> getMemberUsers() {
057        return users;
058    }
059
060    @Override
061    public List<String> getMemberGroups() {
062        return groups;
063    }
064
065    @Override
066    public List<String> getParentGroups() {
067        return parentGroups;
068    }
069
070    @Override
071    public void setMemberUsers(List<String> users) {
072        if (users == null) {
073            throw new IllegalArgumentException("member users list cannot be null");
074        }
075        this.users.clear();
076        this.users.addAll(users);
077    }
078
079    @Override
080    public void setMemberGroups(List<String> groups) {
081        if (groups == null) {
082            throw new IllegalArgumentException("member groups list cannot be null");
083        }
084        this.groups.clear();
085        this.groups.addAll(groups);
086    }
087
088    @Override
089    public void setParentGroups(List<String> groups) {
090        if (groups == null) {
091            throw new IllegalArgumentException("parent groups list cannot be null");
092        }
093        parentGroups.clear();
094        parentGroups.addAll(groups);
095    }
096
097    @Override
098    public String getName() {
099        return name;
100    }
101
102    @Override
103    public void setName(String name) {
104        this.name = name;
105    }
106
107    @Override
108    public String getLabel() {
109        return this.label;
110    }
111
112    @Override
113    public void setLabel(String label) {
114        this.label = label;
115    }
116
117    @Override
118    public boolean equals(Object other) {
119        if (other == this) {
120            return true;
121        }
122        if (other instanceof NuxeoGroupImpl) {
123            return name.equals(((NuxeoGroupImpl) other).name);
124        }
125        return false;
126    }
127
128    @Override
129    public int hashCode() {
130        return name.hashCode();
131    }
132
133    @Override
134    public String toString() {
135        return name;
136    }
137
138}