PageRenderTime 27ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/com.atlassian.connector.eclipse.model/src/com/atlassian/theplugin/commons/crucible/api/model/CrucibleFileInfo.java

https://github.com/spingel/mylyn-reviews
Java | 362 lines | 263 code | 65 blank | 34 comment | 81 complexity | 145e532a7543461b56f10be71b4bc801 MD5 | raw file
  1. /**
  2. * Copyright (C) 2008 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. package com.atlassian.theplugin.commons.crucible.api.model;
  17. import com.atlassian.theplugin.commons.VersionedFileInfo;
  18. import com.atlassian.theplugin.commons.VersionedVirtualFile;
  19. import org.jetbrains.annotations.NotNull;
  20. import org.jetbrains.annotations.Nullable;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;
  24. public class CrucibleFileInfo implements VersionedFileInfo {
  25. @Nullable
  26. private VersionedVirtualFile fileDescriptor;
  27. @Nullable
  28. private VersionedVirtualFile oldFileDescriptor;
  29. private String repositoryName;
  30. private FileType fileType;
  31. private String authorName;
  32. private Date commitDate;
  33. private CommitType commitType;
  34. private RepositoryType repositoryType;
  35. private PermId permId;
  36. private List<VersionedComment> versionedComments;
  37. private static final int HASH_NUMBER = 31;
  38. public CrucibleFileInfo() {
  39. versionedComments = new ArrayList<VersionedComment>();
  40. }
  41. public CrucibleFileInfo(@Nullable VersionedVirtualFile fileDescriptor,
  42. @Nullable VersionedVirtualFile oldFileDescriptor, @NotNull PermId permId) {
  43. this.fileDescriptor = fileDescriptor;
  44. this.oldFileDescriptor = oldFileDescriptor;
  45. this.permId = permId;
  46. versionedComments = new ArrayList<VersionedComment>();
  47. }
  48. public List<VersionedComment> getVersionedComments() {
  49. return versionedComments;
  50. }
  51. public void setVersionedComments(final List<VersionedComment> versionedComments) {
  52. this.versionedComments = versionedComments;
  53. }
  54. public int getNumberOfCommentsDefects() {
  55. if (versionedComments == null) {
  56. return 0;
  57. }
  58. int counter = 0;
  59. for (VersionedComment comment : versionedComments) {
  60. if (comment.isDefectRaised()) {
  61. ++counter;
  62. }
  63. for (Comment reply : comment.getReplies()) {
  64. if (reply.isDefectRaised()) {
  65. ++counter;
  66. }
  67. }
  68. }
  69. return counter;
  70. }
  71. public int getNumberOfCommentsDefects(final String userName) {
  72. if (versionedComments == null) {
  73. return 0;
  74. }
  75. int counter = 0;
  76. for (VersionedComment comment : versionedComments) {
  77. if (comment.isDefectRaised() && comment.getAuthor().getUsername().equals(userName)) {
  78. ++counter;
  79. }
  80. for (Comment reply : comment.getReplies()) {
  81. if (reply.isDefectRaised() && reply.getAuthor().getUsername().equals(userName)) {
  82. ++counter;
  83. }
  84. }
  85. }
  86. return counter;
  87. }
  88. public int getNumberOfCommentsDrafts() {
  89. if (versionedComments == null) {
  90. return 0;
  91. }
  92. int counter = 0;
  93. for (VersionedComment comment : versionedComments) {
  94. if (comment.isDraft()) {
  95. ++counter;
  96. }
  97. counter += comment.getNumberOfDraftReplies();
  98. }
  99. return counter;
  100. }
  101. public int getNumberOfCommentsDrafts(final String userName) {
  102. if (versionedComments == null) {
  103. return 0;
  104. }
  105. int counter = 0;
  106. for (VersionedComment comment : versionedComments) {
  107. if (comment.isDraft() && comment.getAuthor().getUsername().equals(userName)) {
  108. ++counter;
  109. }
  110. for (Comment reply : comment.getReplies()) {
  111. if (reply.isDraft() && reply.getAuthor().getUsername().equals(userName)) {
  112. ++counter;
  113. }
  114. }
  115. }
  116. return counter;
  117. }
  118. public int getNumberOfLineComments() {
  119. if (versionedComments == null) {
  120. return 0;
  121. }
  122. int counter = 0;
  123. for (VersionedComment comment : versionedComments) {
  124. if (comment.isFromLineInfo() || comment.isToLineInfo()) {
  125. ++counter;
  126. }
  127. }
  128. return counter;
  129. }
  130. public int getNumberOfUnreadComments() {
  131. if (versionedComments == null) {
  132. return 0;
  133. }
  134. int counter = 0;
  135. for (VersionedComment comment : versionedComments) {
  136. if (comment.isEffectivelyUnread()) {
  137. ++counter;
  138. }
  139. counter += comment.getNumberOfUnreadReplies();
  140. }
  141. return counter;
  142. }
  143. public int getNumberOfComments(final String userName) {
  144. if (versionedComments == null) {
  145. return 0;
  146. }
  147. int counter = 0;
  148. for (VersionedComment comment : versionedComments) {
  149. if (comment.getAuthor().getUsername().equals(userName)) {
  150. ++counter;
  151. }
  152. for (Comment reply : comment.getReplies()) {
  153. if (reply.getAuthor().getUsername().equals(userName)) {
  154. ++counter;
  155. }
  156. }
  157. }
  158. return counter;
  159. }
  160. public int getNumberOfComments() {
  161. if (versionedComments == null) {
  162. return 0;
  163. }
  164. int n = versionedComments.size();
  165. for (VersionedComment c : versionedComments) {
  166. n += c.getNumReplies();
  167. }
  168. return n;
  169. }
  170. // public CrucibleFileInfoImpl(PermId permId) {
  171. // this(null, null);
  172. // this.permId = permId;
  173. // }
  174. public VersionedVirtualFile getOldFileDescriptor() {
  175. return oldFileDescriptor;
  176. }
  177. public PermId getPermId() {
  178. return permId;
  179. }
  180. public void setOldFileDescriptor(VersionedVirtualFile oldFileDescriptor) {
  181. this.oldFileDescriptor = oldFileDescriptor;
  182. }
  183. public void setFileDescriptor(VersionedVirtualFile fileDescriptor) {
  184. this.fileDescriptor = fileDescriptor;
  185. }
  186. public VersionedVirtualFile getFileDescriptor() {
  187. return fileDescriptor;
  188. }
  189. @Override
  190. public String toString() {
  191. VersionedVirtualFile oldFile = getOldFileDescriptor();
  192. VersionedVirtualFile newFile = getFileDescriptor();
  193. if (oldFile != null && oldFile.getUrl().length() > 0 && newFile != null && newFile.getUrl().length() > 0) {
  194. return oldFile.getUrl() + " (mod)";
  195. } else if (oldFile != null && oldFile.getUrl().length() > 0) {
  196. return oldFile.getUrl() + " (del)";
  197. } else if (newFile != null && newFile.getUrl().length() > 0) {
  198. return newFile.getUrl() + " (new)";
  199. } else {
  200. return "(unknown state)";
  201. }
  202. }
  203. // public void setVersionedComments(List<VersionedComment> commentList) {
  204. // versionedComments = commentList;
  205. // }
  206. //
  207. // public void addVersionedComment(VersionedComment comment) {
  208. // versionedComments.add(comment);
  209. // }
  210. //
  211. //
  212. // public List<VersionedComment> getVersionedComments() throws ValueNotYetInitialized {
  213. // if (versionedComments == null) {
  214. // throw new ValueNotYetInitialized("Object trasferred only partially");
  215. // }
  216. // return versionedComments;
  217. // }
  218. public String getRepositoryName() {
  219. return repositoryName;
  220. }
  221. public void setRepositoryName(String repositoryName) {
  222. this.repositoryName = repositoryName;
  223. }
  224. public FileType getFileType() {
  225. return fileType;
  226. }
  227. public void setFileType(final FileType fileType) {
  228. this.fileType = fileType;
  229. }
  230. public String getAuthorName() {
  231. return authorName;
  232. }
  233. public void setAuthorName(final String authorName) {
  234. this.authorName = authorName;
  235. }
  236. public Date getCommitDate() {
  237. return commitDate;
  238. }
  239. public void setCommitDate(final Date commitDate) {
  240. this.commitDate = commitDate;
  241. }
  242. public CommitType getCommitType() {
  243. return commitType;
  244. }
  245. public void addComment(final VersionedComment comment) {
  246. this.versionedComments.add(comment);
  247. }
  248. public void setCommitType(final CommitType commitType) {
  249. this.commitType = commitType;
  250. }
  251. public void setFilePermId(final PermId aPermId) {
  252. this.permId = aPermId;
  253. }
  254. @Override
  255. public boolean equals(Object o) {
  256. if (this == o) {
  257. return true;
  258. }
  259. if (o == null || getClass() != o.getClass()) {
  260. return false;
  261. }
  262. CrucibleFileInfo that = (CrucibleFileInfo) o;
  263. if (fileType != that.fileType) {
  264. return false;
  265. }
  266. if (!permId.equals(that.permId)) {
  267. return false;
  268. }
  269. if (repositoryName != null ? !repositoryName.equals(that.repositoryName) : that.repositoryName != null) {
  270. return false;
  271. }
  272. if (oldFileDescriptor != null ? !oldFileDescriptor.equals(that.oldFileDescriptor)
  273. : that.oldFileDescriptor != null) {
  274. return false;
  275. }
  276. if (fileDescriptor != null ? !fileDescriptor.equals(that.fileDescriptor) : that.fileDescriptor != null) {
  277. return false;
  278. }
  279. return true;
  280. }
  281. @Override
  282. public int hashCode() {
  283. int result;
  284. result = (repositoryName != null ? repositoryName.hashCode() : 0);
  285. result = HASH_NUMBER * result + (fileDescriptor != null ? fileDescriptor.hashCode() : 0);
  286. result = HASH_NUMBER * result + (oldFileDescriptor != null ? oldFileDescriptor.hashCode() : 0);
  287. result = HASH_NUMBER * result + (fileType != null ? fileType.hashCode() : 0);
  288. result = HASH_NUMBER * result + permId.hashCode();
  289. return result;
  290. }
  291. public RepositoryType getRepositoryType() {
  292. return repositoryType;
  293. }
  294. public void setRepositoryType(final RepositoryType repositoryType) {
  295. this.repositoryType = repositoryType;
  296. }
  297. }