Source code: com/phoenixst/plexus/SimpleObjectEdge.java
1 /*
2 * $Id: SimpleObjectEdge.java,v 1.1 2003/11/04 22:33:09 rconner Exp $
3 *
4 * Copyright (C) 1994-2003 by Phoenix Software Technologists,
5 * Inc. and others. All rights reserved.
6 *
7 * THIS PROGRAM AND DOCUMENTATION IS PROVIDED UNDER THE TERMS OF THE
8 * COMMON PUBLIC LICENSE ("AGREEMENT") WHICH ACCOMPANIES IT. ANY
9 * USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
10 * RECIPIENT'S ACCEPTANCE OF THE AGREEMENT.
11 *
12 * The license text can also be found at
13 * http://opensource.org/licenses/cpl.php
14 */
15
16 package com.phoenixst.plexus;
17
18 import com.phoenixst.plexus.*;
19
20
21 /**
22 * A <code>SimpleEdge</code> which can contain a user-defined object.
23 * Because of how {@link #equals(Object) equals( Object )} is
24 * defined, instances of this class may only be used by multigraphs
25 * when the endpoints and contained user-defined object are
26 * sufficient to distinguish distinct edges.
27 *
28 * @version $Revision: 1.1 $
29 * @author Ray A. Conner
30 *
31 * @since 1.0
32 */
33 public class SimpleObjectEdge extends SimpleEdge
34 {
35
36 /**
37 * The object contained by this <code>Edge</code>.
38 */
39 private Object object;
40
41
42 ////////////////////////////////////////
43 // Constructor
44 ////////////////////////////////////////
45
46
47 /**
48 * Creates a new <code>SimpleObjectEdge</code>.
49 */
50 public SimpleObjectEdge( Graph graph,
51 Object object,
52 Object tail, Object head,
53 boolean isDirected )
54 {
55 super( graph, tail, head, isDirected );
56 this.object = object;
57 }
58
59
60 ////////////////////////////////////////
61 // Edge methods
62 ////////////////////////////////////////
63
64
65 public Object getUserObject()
66 {
67 return object;
68 }
69
70
71 public void setUserObject( Object object )
72 {
73 this.object = object;
74 }
75
76
77 ////////////////////////////////////////
78 // Other methods
79 ////////////////////////////////////////
80
81
82 /**
83 * Two <code>SimpleObjectEdges</code> are equal if they have the
84 * same directedness, are from the exact same graph (using
85 * <code>==</code>), have equal endpoints, and contain the same
86 * user-defined object.
87 */
88 public boolean equals( Object object )
89 {
90 return (object instanceof SimpleObjectEdge)
91 && equals( (SimpleObjectEdge) object );
92 }
93
94
95 /**
96 * Two <code>SimpleObjectEdges</code> are equal if they have the
97 * same directedness, are from the exact same graph (using
98 * <code>==</code>), have equal endpoints, and contain the same
99 * user-defined object.
100 */
101 public boolean equals( SimpleEdge edge )
102 {
103 return (edge instanceof SimpleObjectEdge)
104 && super.equals( edge )
105 && equals( object, edge.getUserObject() );
106 }
107
108
109 public int hashCode()
110 {
111 return super.hashCode() ^ ((object == null) ? 0 : object.hashCode());
112 }
113
114
115 public String toString()
116 {
117 StringBuffer s = new StringBuffer();
118 s.append( getTail() );
119 s.append( " -- (" );
120 s.append( object );
121 s.append( isDirected() ? ") -> " : ") -- " );
122 s.append( getHead() );
123 return s.toString();
124 }
125
126 }