View Javadoc

1   /*
2    * This file is a part of CAST project.
3    * (c) Copyright 2007, AGH University of Science & Technology
4    * https://caribou.iisg.agh.edu.pl/trac/cast
5    *
6    * Licensed under the Eclipse Public License, Version 1.0 (the "License").
7    * You may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    * http://www.eclipse.org/legal/epl-v10.html
10   */
11  /*
12   * File: Connection.java
13   * Created: 2007-00-00
14   * Author: awos
15   * $Id: Connection.java 2770 2009-04-21 19:17:34Z kpietak $
16   */
17  
18  package pl.edu.agh.cast.model.visual.backward;
19  
20  import java.io.Serializable;
21  import java.util.Date;
22  
23  import com.thoughtworks.xstream.annotations.XStreamAlias;
24  
25  /**
26   * A visual representation of a {@link pl.edu.agh.cast.model.base.IRelation}.
27   *
28   * @author AGH CAST Team
29   */
30  @XStreamAlias("connection")
31  public class Connection implements Serializable {
32  
33  	/*
34  	 * TODO: remove _startDate from this class?
35  	 */
36  
37  	private static final long serialVersionUID = -6068688858953611564L;
38  
39  	@XStreamAlias("sourceNode")
40  	private Node sourceNode;
41  
42  	@XStreamAlias("targetNode")
43  	private Node targetNode;
44  
45  	@XStreamAlias("startDate")
46  	private Date startDate;
47  
48  	/**
49  	 * Default constructor.
50  	 */
51  	public Connection() {
52  	}
53  
54  	/**
55  	 * Constructor.
56  	 *
57  	 * @param source
58  	 *            source node
59  	 * @param target
60  	 *            target node
61  	 * @param connectionStart
62  	 *            time of connection
63  	 */
64  	public Connection(Node source, Node target, Date connectionStart) {
65  		sourceNode = source;
66  		targetNode = target;
67  		startDate = connectionStart;
68  	}
69  
70  	public Node getSourceNode() {
71  		return sourceNode;
72  	}
73  
74  	public void setSourceNode(Node sourceNode) {
75  		this.sourceNode = sourceNode;
76  	}
77  
78  	public Node getTargetNode() {
79  		return targetNode;
80  	}
81  
82  	public void setTargetNode(Node targetNode) {
83  		this.targetNode = targetNode;
84  	}
85  
86  	public Date getStartDate() {
87  		return startDate;
88  	}
89  
90  	public void setStartDate(Date startDate) {
91  		this.startDate = startDate;
92  	}
93  
94  	/**
95  	 * Copies all fields of this {@link Connection} instance to <code>that</code> instance.
96  	 *
97  	 * @param that
98  	 *            instance of {@link Connection} to copy this instance to
99  	 */
100 	public void copyTo(Connection that) {
101 		// do not copy source and target - these are handled differently
102 		that.setStartDate(this.getStartDate());
103 		// XXX: add new fields here
104 	}
105 
106 	/**
107 	 * {@inheritDoc}
108 	 *
109 	 * @see java.lang.Object#toString()
110 	 */
111 	@Override
112 	public String toString() {
113 		// for easier debugging
114 		return sourceNode.getLabel() + "->" + targetNode.getLabel(); //$NON-NLS-1$
115 	}
116 
117 	/**
118 	 * {@inheritDoc}
119 	 *
120 	 * @see java.lang.Object#equals(java.lang.Object)
121 	 */
122 	@Override
123 	public boolean equals(Object obj) {
124 		if (obj == this) {
125 			return true;
126 		}
127 		if (!(obj instanceof Connection)) {
128 			return false;
129 		}
130 		Connection that = (Connection)obj;
131 
132 		if (sourceNode == null) {
133 			if (that.sourceNode != null) {
134 				return false;
135 			}
136 		} else if (!sourceNode.equals(that.sourceNode)) {
137 			return false;
138 		}
139 		if (targetNode == null) {
140 			if (that.targetNode != null) {
141 				return false;
142 			}
143 		} else if (!targetNode.equals(that.targetNode)) {
144 			return false;
145 		}
146 		if (startDate == null) {
147 			if (that.startDate != null) {
148 				return false;
149 			}
150 		} else if (!startDate.equals(that.startDate)) {
151 			return false;
152 		}
153 		return true;
154 	}
155 
156 	/**
157 	 * {@inheritDoc}
158 	 *
159 	 * @see java.lang.Object#hashCode()
160 	 */
161 	@Override
162 	public int hashCode() {
163 		int result = 0;
164         int prime = 31;
165         result = sourceNode == null ? 0 : sourceNode.hashCode();
166         result = result * prime + (targetNode == null ? 0 : targetNode.hashCode());
167         result = result * prime + (startDate == null ? 0 : startDate.hashCode());
168         return result;
169 	}
170 
171 }