Skip to content

Method: Link(long, UserObject, Object)

1: package de.fhdw.wtf.persistence.meta;
2:
3: /**
4: * A class to represent a connection between two objects in the database. The UnidirectionalLink itself is an instance
5: * of an association.
6: *
7: */
8: public abstract class Link extends InstanceItem {
9:         
10:         /**
11:          * The identity of the link in the database. This Id is unique.
12:          */
13:         private final long id;
14:         
15:         /**
16:          * The owning User Object of the link.
17:          */
18:         private final UserObject owner;
19:         
20:         /**
21:          * The targeted Object.
22:          */
23:         private final Object target;
24:         
25:         /**
26:          * Provides the Type of this UnidirectionalLink.
27:          *
28:          * @return Provides the association for which this link is an instance.
29:          */
30:         public abstract Association getInstanceOf();
31:         
32:         /**
33:          * Getter for the Owner of this UnidirectionalLink.
34:          *
35:          * @return Provides the User Object, which is the owner of this link.
36:          */
37:         public UserObject getOwner() {
38:                 return this.owner;
39:         }
40:         
41:         /**
42:          * Getter for the target of this UnidirectionalLink.
43:          *
44:          * @return Provides an Object, which is the target of this link.
45:          */
46:         public Object getTarget() {
47:                 return this.target;
48:         }
49:         
50:         /**
51:          * Constructor for a new UnidirectionalLink, it should only be called by the Object Facade or Junit Test to
52:          * guarantee a valid consistency with the database.
53:          *
54:          * @param id
55:          * The Id of the UnidirectionalLink, determined by the database.
56:          * @param owner
57:          * The owner of the this UnidirectionalLink. A User Object.
58:          * @param target
59:          * The target of this link. An Object.
60:          */
61:         public Link(final long id, final UserObject owner, final Object target) {
62:                 super();
63:                 this.id = id;
64:                 this.owner = owner;
65:                 this.target = target;
66:         }
67:         
68:         @Override
69:         public long getId() {
70:                 return this.id;
71:         }
72:         
73:         @Override
74:         public boolean equals(final java.lang.Object obj) {
75:                 if (!(obj instanceof Link)) {
76:                         return false;
77:                 }
78:                 
79:                 final Link link = (Link) obj;
80:                 return this.getOwner().equals(link.getOwner()) && this.getTarget().equals(link.getTarget());
81:         }
82:         
83:         @Override
84:         public int hashCode() {
85:                 return this.owner.hashCode() ^ this.target.hashCode();
86:         }
87:         
88:         @Override
89:         public String toString() {
90:                 return "UnidirectionalLink<" + this.getId() + ">";
91:         }
92:         
93:         @Override
94:         public boolean isTheSameAs(final java.lang.Object other) {
95:                 if (!(other instanceof Link)) {
96:                         return false;
97:                 }
98:                 
99:                 return this.getId() == ((Link) other).getId();
100:         }
101:         
102: }