View Javadoc

1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.model;
20  
21  import org.apache.commons.lang.builder.ToStringBuilder;
22  
23  /**
24   * A relation between issues.
25   * 
26   * @author ready
27   */
28  public class IssueRelation extends AbstractEntity {
29  
30  	/**
31  	 * 
32  	 */
33  	private static final long serialVersionUID = 1L;
34  
35  	private Issue issue;
36  
37  	private Issue relatedIssue;
38  
39  	/** Indicates the kind of relation that exists between the 2 issues. */
40  	private int type;
41  
42  	private Integer matchingRelationId;
43  
44  	/**
45  	 * Default constructor (required by Hibernate).
46  	 * 
47  	 * <p>
48  	 * PENDING: should be <code>private</code> so that it can only be used by
49  	 * Hibernate, to ensure that the fields which form an instance's identity
50  	 * are always initialized/never <tt>null</tt>.
51  	 * </p>
52  	 */
53  	public IssueRelation() {
54  	}
55  
56  	public IssueRelation(Issue issue, Issue relatedIssue, int relationType) {
57  		setIssue(issue);
58  		setRelatedIssue(relatedIssue);
59  		setRelationType(relationType);
60  	}
61  
62  	public Issue getIssue() {
63  		return issue;
64  	}
65  
66  	public void setIssue(Issue issue) {
67  		if (issue == null) {
68  			throw new IllegalArgumentException("null issue");
69  		}
70  		this.issue = issue;
71  	}
72  
73  	public Issue getRelatedIssue() {
74  		return relatedIssue;
75  	}
76  
77  	public void setRelatedIssue(Issue relatedIssue) {
78  		if (relatedIssue == null) {
79  			throw new IllegalArgumentException("null relatedIssue");
80  		}
81  		this.relatedIssue = relatedIssue;
82  	}
83  
84  	public int getRelationType() {
85  		return type;
86  	}
87  
88  	public void setRelationType(int type) {
89  		this.type = type;
90  	}
91  
92  	public Integer getMatchingRelationId() {
93  		return matchingRelationId;
94  	}
95  
96  	public void setMatchingRelationId(Integer matchingRelationId) {
97  		this.matchingRelationId = matchingRelationId;
98  	}
99  
100 
101 	@Override
102 	public String toString() {
103 		return new ToStringBuilder(this).append("id", getId())
104 				.append("issue", getIssue()).append("relatedIssue", getRelatedIssue())
105 				.append("type", getRelationType()).toString();
106 	}
107 
108 	public static enum Type {
109 
110 		/** Defines a related issue. Sample text: related to */
111 		RELATED_P(1),
112 
113 		/** Defines a related issue. Sample text: related to */
114 		RELATED_C(2),
115 
116 		/** Defines a duplicate issue. Sample text: duplicates */
117 		DUPLICATE_P(3),
118 
119 		/** Defines a duplicate issue. Sample text: duplicate of */
120 		DUPLICATE_C(4),
121 
122 		/** Defines a cloned issue. Sample text: cloned to */
123 		CLONED_P(5),
124 
125 		/** Defines a cloned issue. Sample text: cloned from */
126 		CLONED_C(6),
127 
128 		/** Defines a split issue. Sample text: split to */
129 		SPLIT_P(7),
130 
131 		/** Defines a split issue. Sample text: split from */
132 		SPLIT_C(8),
133 
134 		/** Defines a dependent issue. Sample text: dependents */
135 		DEPENDENT_P(9),
136 
137 		/** Defines a dependent issue. Sample text: depends on */
138 		DEPENDENT_C(10);
139 
140 		@SuppressWarnings("unused")
141 		private final int code;
142 
143 		private Type(int code) {
144 			this.code = code;
145 		}
146 
147 	}
148 
149 }