View Javadoc

1   /*
2    * Copyright (C) 2014 Atlassian
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.atlassian.jira.rest.client.api.domain;
17  
18  import com.atlassian.jira.rest.client.api.IdentifiableEntity;
19  import com.atlassian.jira.rest.client.api.NamedEntity;
20  import com.google.common.base.Function;
21  import com.google.common.base.Objects;
22  
23  import javax.annotation.Nullable;
24  
25  public class Permission implements NamedEntity, IdentifiableEntity<Integer> {
26      private final Integer id;
27      private final String key;
28      private final String name;
29      @Nullable
30      private final String description;
31      private final boolean havePermission;
32  
33      public Permission(final int id, final String key, final String name, @Nullable final String description,
34                        final boolean havePermission) {
35          this.id = id;
36          this.key = key;
37          this.name = name;
38          this.description = description;
39          this.havePermission = havePermission;
40      }
41  
42      @Override
43      public Integer getId() {
44          return id;
45      }
46  
47      public String getKey() {
48          return key;
49      }
50  
51      @Override
52      public String getName() {
53          return name;
54      }
55  
56      @Nullable
57      public String getDescription() {
58          return description;
59      }
60  
61      public boolean havePermission() {
62          return havePermission;
63      }
64  
65      protected Objects.ToStringHelper getToStringHelper() {
66          return Objects.toStringHelper(this)
67                  .add("id", id)
68                  .add("key", key)
69                  .add("name", name)
70                  .add("description", description)
71                  .add("havePermission", havePermission);
72      }
73  
74      @Override
75      public String toString() {
76          return getToStringHelper().toString();
77      }
78  
79      @Override
80      public boolean equals(Object o) {
81          if (o instanceof Permission) {
82              Permission that = (Permission) o;
83              return id == that.id
84                      && Objects.equal(key, that.key)
85                      && Objects.equal(name, that.name)
86                      && Objects.equal(description, that.description)
87                      && havePermission == that.havePermission;
88          }
89          return false;
90      }
91  
92      @Override
93      public int hashCode() {
94          return Objects.hashCode(id, key, name, description, havePermission);
95      }
96  
97      public static final Function<Permission, String> TO_KEY = new Function<Permission, String>() {
98          @Override
99          public String apply(final Permission input) {
100             return input.getKey();
101         }
102     };
103 }