View Javadoc

1   /*
2    * Copyright (C) 2011 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  
17  package com.atlassian.jira.rest.client.api.domain;
18  
19  import com.google.common.base.Objects;
20  
21  /**
22   * Represents visibility (access level) of selected element (comment, worklog, etc.)
23   *
24   * @since v0.2
25   */
26  public class Visibility {
27      public enum Type {
28          ROLE, GROUP
29      }
30  
31      private final Type type;
32      private final String value;
33  
34      public Visibility(Type type, String value) {
35          this.type = type;
36          this.value = value;
37      }
38  
39      public Type getType() {
40          return type;
41      }
42  
43      public String getValue() {
44          return value;
45      }
46  
47      public static Visibility role(String value) {
48          return new Visibility(Type.ROLE, value);
49      }
50  
51      public static Visibility group(String group) {
52          return new Visibility(Type.GROUP, group);
53      }
54  
55      @Override
56      public String toString() {
57          return Objects.toStringHelper(this).
58                  add("type", type).
59                  add("value", value).
60                  toString();
61      }
62  
63      @Override
64      public boolean equals(Object obj) {
65          if (obj instanceof Visibility) {
66              Visibility that = (Visibility) obj;
67              return Objects.equal(this.type, that.type) && Objects.equal(this.value, that.value);
68          }
69          return false;
70      }
71  
72      @Override
73      public int hashCode() {
74          return Objects.hashCode(type, value);
75      }
76  }