James Moger
2012-10-22 87f6c3e6510986a6676872aa64aed66fe7f24b01
commit | author | age
822dfe 1 /*
JM 2  * Copyright 2012 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
20 import com.gitblit.Constants.AccessPermission;
21 import com.gitblit.Constants.RegistrantType;
22 import com.gitblit.utils.StringUtils;
23
24 /**
25  * Represents a Registrant-AccessPermission tuple.
26  * 
27  * @author James Moger
28  */
29 public class RegistrantAccessPermission implements Serializable, Comparable<RegistrantAccessPermission> {
30
31     private static final long serialVersionUID = 1L;
32
33     public String registrant;
34     public AccessPermission permission;
35     public RegistrantType type;
87f6c3 36     public boolean isExplicit;
822dfe 37
JM 38     public RegistrantAccessPermission() {
87f6c3 39         isExplicit = true;
822dfe 40     }
JM 41     
87f6c3 42     public RegistrantAccessPermission(String registrant, AccessPermission permission, boolean isExplicit, RegistrantType type) {
822dfe 43         this.registrant = registrant;
JM 44         this.permission = permission;
87f6c3 45         this.isExplicit = isExplicit;
822dfe 46         this.type = type;
JM 47     }
48     
49     @Override
50     public int compareTo(RegistrantAccessPermission p) {
51         switch (type) {
52         case REPOSITORY:
53             return StringUtils.compareRepositoryNames(registrant, p.registrant);
54         default:
55             return registrant.toLowerCase().compareTo(p.registrant.toLowerCase());        
56         }
57     }
58     
59     @Override
60     public String toString() {
61         return permission.asRole(registrant);
62     }
63 }