James Moger
2011-12-22 e6935876b97a63bae2ec087b4fc390c832aef155
commit | author | age
fe24a0 1 /*
JM 2  * Copyright 2011 gitblit.com.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.gitblit.models;
17
18 import java.io.Serializable;
19 import java.util.Collection;
20 import java.util.HashSet;
0b9119 21 import java.util.List;
fe24a0 22 import java.util.Set;
JM 23
24 /**
25  * TeamModel is a serializable model class that represents a group of users and
26  * a list of accessible repositories.
27  * 
28  * @author James Moger
29  * 
30  */
31 public class TeamModel implements Serializable, Comparable<TeamModel> {
32
33     private static final long serialVersionUID = 1L;
34
35     // field names are reflectively mapped in EditTeam page
36     public String name;
37     public final Set<String> users = new HashSet<String>();
38     public final Set<String> repositories = new HashSet<String>();
0b9119 39     public final Set<String> mailingLists = new HashSet<String>();
fe24a0 40
JM 41     public TeamModel(String name) {
42         this.name = name;
43     }
44
45     public boolean hasRepository(String name) {
46         return repositories.contains(name.toLowerCase());
47     }
48
49     public void addRepository(String name) {
50         repositories.add(name.toLowerCase());
51     }
52     
53     public void addRepositories(Collection<String> names) {
54         for (String name:names) {
55             repositories.add(name.toLowerCase());
56         }
57     }    
58
59     public void removeRepository(String name) {
60         repositories.remove(name.toLowerCase());
61     }
62     
63     public boolean hasUser(String name) {
64         return users.contains(name.toLowerCase());
65     }
66
67     public void addUser(String name) {
68         users.add(name.toLowerCase());
69     }
70
71     public void addUsers(Collection<String> names) {
72         for (String name:names) {
73             users.add(name.toLowerCase());
74         }
75     }
76
77     public void removeUser(String name) {
78         users.remove(name.toLowerCase());
79     }
80
0b9119 81     public void addMailingLists(Collection<String> addresses) {
JM 82         for (String address:addresses) {
83             mailingLists.add(address.toLowerCase());
84         }
85     }
86
fe24a0 87     @Override
JM 88     public String toString() {
89         return name;
90     }
91
92     @Override
93     public int compareTo(TeamModel o) {
94         return name.compareTo(o.name);
95     }
96 }