$darkmode
DENOPTIM
ZMatrixBond.java
Go to the documentation of this file.
1package denoptim.molecularmodeling.zmatrix;
2
6public class ZMatrixBond
7{
10
11//--------------------------------------------------------------------------
12
19 {
20 this.atm1 = atm1;
21 this.atm2 = atm2;
22 }
23
24//--------------------------------------------------------------------------
25
31 {
32 return atm1;
33 }
34
35//--------------------------------------------------------------------------
36
42 {
43 return atm2;
44 }
45
46//--------------------------------------------------------------------------
47
53 {
54 this.atm1 = atm1;
55 }
56
57//--------------------------------------------------------------------------
58
64 {
65 this.atm2 = atm2;
66 }
67
68//--------------------------------------------------------------------------
69
70 @Override
71 public boolean equals(Object o)
72 {
73 if (o == null)
74 return false;
75
76 if (o == this)
77 return true;
78
79 if (o.getClass() != getClass())
80 return false;
81
82 ZMatrixBond other = (ZMatrixBond) o;
83 return (this.atm1.equals(other.atm1) && this.atm2.equals(other.atm2)) ||
84 (this.atm2.equals(other.atm1) && this.atm1.equals(other.atm2));
85 }
86
87//--------------------------------------------------------------------------
88
89 @Override
90 public int hashCode()
91 {
92 int atm1Id = (atm1 != null) ? atm1.getId() : 0;
93 int atm2Id = (atm2 != null) ? atm2.getId() : 0;
94 // Use symmetric hash code for undirected bonds
95 // Sort IDs to ensure (a1, a2) and (a2, a1) have same hash
96 int minId = Math.min(atm1Id, atm2Id);
97 int maxId = Math.max(atm1Id, atm2Id);
98 return 31 * minId + maxId;
99 }
100
101//--------------------------------------------------------------------------
102
103 @Override
104 public String toString()
105 {
106 return atm1.getId() + " " + atm2.getId();
107 }
108
109//--------------------------------------------------------------------------
110}
111
Representation of an atom in the ZMatrix.
Definition: ZMatrixAtom.java:9
boolean equals(Object o)
Get the string representation of the atom.
Representation of a bond in the ZMatrix.
Definition: ZMatrixBond.java:7
ZMatrixAtom getAtm2()
Get the second atom in the bond.
ZMatrixAtom getAtm1()
Get the first atom in the bond.
ZMatrixBond(ZMatrixAtom atm1, ZMatrixAtom atm2)
Constructor for ZMatrixBond.
void setAtm1(ZMatrixAtom atm1)
Set the first atom in the bond.
void setAtm2(ZMatrixAtom atm2)
Set the second atom in the bond.