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.domain;
18  
19  import com.atlassian.jira.rest.client.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 BasicUser author;
35  	@Nullable
36  	private final BasicUser updateAuthor;
37  	private final DateTime creationDate;
38  	private final DateTime updateDate;
39  	private final String body;
40  	@Nullable
41  	private final Visibility visibility;
42  
43  	public Comment(URI self, String body, @Nullable BasicUser author, @Nullable BasicUser updateAuthor, DateTime creationDate, DateTime updateDate, Visibility visibility) {
44  		this.author = author;
45  		this.updateAuthor = updateAuthor;
46  		this.creationDate = creationDate;
47  		this.updateDate = updateDate;
48  		this.body = body;
49  		this.self = self;
50  		this.visibility = visibility;
51  	}
52  
53  	public static Comment valueOf(String body) {
54  		return new Comment(null, body, null, null, null, null, null);
55  	}
56  
57  	public static Comment createWithRoleLevel(String body, String roleLevel) {
58  		return new Comment(null, body, null, null, null, null, Visibility.role(roleLevel));
59  	}
60  
61  	public static Comment createWithGroupLevel(String body, String groupLevel) {
62  		return new Comment(null, body, null, null, null, null, Visibility.group(groupLevel));
63  	}
64  
65  	public boolean wasUpdated() {
66  		return updateDate.isAfter(creationDate);
67  	}
68  
69  	public String getBody() {
70  		return body;
71  	}
72  
73  	@Override
74  	public URI getSelf() {
75  		return self;
76  	}
77  
78  	@Nullable
79  	public BasicUser getAuthor() {
80  		return author;
81  	}
82  
83  	@Nullable
84  	public BasicUser getUpdateAuthor() {
85  		return updateAuthor;
86  	}
87  
88  	public DateTime getCreationDate() {
89  		return creationDate;
90  	}
91  
92  	public DateTime getUpdateDate() {
93  		return updateDate;
94  	}
95  
96  	@Nullable
97  	public Visibility getVisibility() {
98  		return visibility;
99  	}
100 
101 	@Override
102 	public String toString() {
103 		return Objects.toStringHelper(this)
104 				.add("self", self)
105 				.add("body", body)
106 				.add("author", author)
107 				.add("updateAuthor", updateAuthor)
108 				.add("creationDate", creationDate)
109 				.add("visibility", visibility)
110 				.add("updateDate", updateDate).toString();
111 	}
112 
113 	@Override
114 	public boolean equals(Object obj) {
115 		if (obj instanceof Comment) {
116 			Comment that = (Comment) obj;
117 			return Objects.equal(this.self, that.self)
118 					&& Objects.equal(this.body, that.body)
119 					&& Objects.equal(this.author, that.author)
120 					&& Objects.equal(this.updateAuthor, that.updateAuthor)
121 					&& Objects.equal(this.creationDate, that.creationDate)
122 					&& Objects.equal(this.updateDate, that.updateDate)
123 					&& Objects.equal(this.visibility, that.visibility)
124 					&& Objects.equal(this.body, that.body);
125 		}
126 		return false;
127 	}
128 
129 	@Override
130 	public int hashCode() {
131 		return Objects.hashCode(self, body, author, updateAuthor, creationDate, updateDate, visibility);
132 	}
133 
134 }