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.atlassian.jira.rest.client.api.AddressableEntity;
20  import com.atlassian.jira.rest.client.api.IdentifiableEntity;
21  import com.google.common.base.Objects;
22  
23  import java.net.URI;
24  
25  /**
26   * Very basic (key and link only) representation of a JIRA issue.
27   *
28   * @since v0.2
29   */
30  public class BasicIssue implements AddressableEntity, IdentifiableEntity<Long> {
31      private final URI self;
32  
33      private final String key;
34      private final Long id;
35  
36      public BasicIssue(URI self, String key, Long id) {
37          this.self = self;
38          this.key = key;
39          this.id = id;
40      }
41  
42      /**
43       * @return URI of this issue
44       */
45      @Override
46      public URI getSelf() {
47          return self;
48      }
49  
50      /**
51       * @return issue key
52       */
53      public String getKey() {
54          return key;
55      }
56  
57      /**
58       * @return issue id
59       */
60      @Override
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      }
76  
77      @Override
78      public boolean equals(Object obj) {
79          if (obj instanceof BasicIssue) {
80              BasicIssue that = (BasicIssue) obj;
81              return Objects.equal(this.self, that.self)
82                      && Objects.equal(this.key, that.key)
83                      && Objects.equal(this.id, that.id);
84          }
85          return false;
86      }
87  
88      @Override
89      public int hashCode() {
90          return Objects.hashCode(self, key, id);
91      }
92  
93  }