View Javadoc

1   /*
2    * Copyright (C) 2010 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.atlassian.jira.rest.client.api.AddressableEntity;
20  import com.atlassian.jira.rest.client.api.NamedEntity;
21  import com.google.common.base.Objects;
22  
23  import javax.annotation.Nullable;
24  import java.net.URI;
25  
26  /**
27   * Basic information about a JIRA project
28   *
29   * @since v0.1
30   */
31  public class BasicProject implements AddressableEntity, NamedEntity {
32      private final URI self;
33      private final String key;
34      @Nullable
35      private final Long id;
36      @Nullable
37      private final String name;
38  
39      public BasicProject(final URI self, final String key, @Nullable final Long id, final @Nullable String name) {
40          this.self = self;
41          this.key = key;
42          this.id = id;
43          this.name = name;
44      }
45  
46      @Override
47      public URI getSelf() {
48          return self;
49      }
50  
51      public String getKey() {
52          return key;
53      }
54  
55      @Nullable
56      public String getName() {
57          return name;
58      }
59  
60      @Nullable
61      public Long getId() {
62          return id;
63      }
64  
65      @Override
66      public String toString() {
67          return getToStringHelper().toString();
68      }
69  
70      protected Objects.ToStringHelper getToStringHelper() {
71          return Objects.toStringHelper(this).
72                  add("self", self).
73                  add("key", key).
74                  add("id", id).
75                  add("name", name);
76      }
77  
78      @Override
79      public boolean equals(Object obj) {
80          if (obj instanceof BasicProject) {
81              BasicProject that = (BasicProject) obj;
82              return Objects.equal(this.self, that.self)
83                      && Objects.equal(this.name, that.name)
84                      && Objects.equal(this.id, that.id)
85                      && Objects.equal(this.key, that.key);
86          }
87          return false;
88      }
89  
90      @Override
91      public int hashCode() {
92          return Objects.hashCode(self, name, id, key);
93      }
94  
95  }