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.google.common.base.Objects;
21  import org.joda.time.DateTime;
22  
23  import javax.annotation.Nullable;
24  import java.net.URI;
25  
26  /**
27   * A JIRA comment
28   *
29   * @since v0.1
30   */
31  public class Comment implements AddressableEntity {
32      private final URI self;
33      @Nullable
34      private final Long id;
35      @Nullable
36      private final BasicUser author;
37      @Nullable
38      private final BasicUser updateAuthor;
39      private final DateTime creationDate;
40      private final DateTime updateDate;
41      private final String body;
42      @Nullable
43      private final Visibility visibility;
44  
45      public Comment(URI self, String body, @Nullable BasicUser author, @Nullable BasicUser updateAuthor, DateTime creationDate, DateTime updateDate, Visibility visibility, @Nullable Long id) {
46          this.author = author;
47          this.updateAuthor = updateAuthor;
48          this.creationDate = creationDate;
49          this.updateDate = updateDate;
50          this.body = body;
51          this.self = self;
52          this.visibility = visibility;
53          this.id = id;
54      }
55  
56      public static Comment valueOf(String body) {
57          return new Comment(null, body, null, null, null, null, null, null);
58      }
59  
60      public static Comment createWithRoleLevel(String body, String roleLevel) {
61          return new Comment(null, body, null, null, null, null, Visibility.role(roleLevel), null);
62      }
63  
64      public static Comment createWithGroupLevel(String body, String groupLevel) {
65          return new Comment(null, body, null, null, null, null, Visibility.group(groupLevel), null);
66      }
67  
68      public boolean wasUpdated() {
69          return updateDate.isAfter(creationDate);
70      }
71  
72      public String getBody() {
73          return body;
74      }
75  
76      @Nullable
77      public Long getId() {
78          return id;
79      }
80  
81      @Override
82      public URI getSelf() {
83          return self;
84      }
85  
86      @Nullable
87      public BasicUser getAuthor() {
88          return author;
89      }
90  
91      @Nullable
92      public BasicUser getUpdateAuthor() {
93          return updateAuthor;
94      }
95  
96      public DateTime getCreationDate() {
97          return creationDate;
98      }
99  
100     public DateTime getUpdateDate() {
101         return updateDate;
102     }
103 
104     @Nullable
105     public Visibility getVisibility() {
106         return visibility;
107     }
108 
109     @Override
110     public String toString() {
111         return Objects.toStringHelper(this)
112                 .add("self", self)
113                 .add("id", id)
114                 .add("body", body)
115                 .add("author", author)
116                 .add("updateAuthor", updateAuthor)
117                 .add("creationDate", creationDate)
118                 .add("visibility", visibility)
119                 .add("updateDate", updateDate).toString();
120     }
121 
122     @Override
123     public boolean equals(Object obj) {
124         if (obj instanceof Comment) {
125             Comment that = (Comment) obj;
126             return Objects.equal(this.self, that.self)
127                     && Objects.equal(this.id, that.id)
128                     && Objects.equal(this.body, that.body)
129                     && Objects.equal(this.author, that.author)
130                     && Objects.equal(this.updateAuthor, that.updateAuthor)
131                     && Objects.equal(this.creationDate, that.creationDate)
132                     && Objects.equal(this.updateDate, that.updateDate)
133                     && Objects.equal(this.visibility, that.visibility)
134                     && Objects.equal(this.body, that.body);
135         }
136         return false;
137     }
138 
139     @Override
140     public int hashCode() {
141         return Objects.hashCode(self, id, body, author, updateAuthor, creationDate, updateDate, visibility);
142     }
143 
144 }