-
Notifications
You must be signed in to change notification settings - Fork 0
/
RotamerPair.java
67 lines (60 loc) · 1.72 KB
/
RotamerPair.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.io.*;
import java.util.*;
/**
* This represents a pair of rotamers. Obeys (a,b).equals(b,a).
*/
public class RotamerPair implements Immutable
{
/** one rotamer */
public final Rotamer rotamer1;
/** the other rotamer */
public final Rotamer rotamer2;
/**
* Constructs a pair of rotamers.
*/
public RotamerPair(Rotamer rotamer1, Rotamer rotamer2)
{
//if ( rotamer1 == null || rotamer2 == null )
// throw new NullPointerException("nulls not allowed");
//if ( rotamer1.equals(rotamer2) )
// System.out.println("duplicate");
this.rotamer1 = rotamer1;
this.rotamer2 = rotamer2;
}
@Override
public String toString()
{
return "=======RotamerPair========\n" + rotamer1.toString() + "\n" + rotamer2.toString() + "\n======";
}
/**
* Returns the hash code for this pair.
* @return the hash code
*/
@Override
public int hashCode()
{
if ( rotamer1.hashCode() < rotamer2.hashCode() )
return Objects.hash(rotamer1, rotamer2);
return Objects.hash(rotamer2, rotamer1);
}
/**
* Tests for object equality.
* @return true if the pairs are equal
*/
@Override
public boolean equals(Object obj)
{
if ( obj == null )
return false;
if ( obj == this )
return true;
if ( !(obj instanceof RotamerPair) )
return false;
RotamerPair p = (RotamerPair)obj;
if ( rotamer1.equals(p.rotamer1) && rotamer2.equals(p.rotamer2) )
return true;
else if ( rotamer1.equals(p.rotamer2) && rotamer2.equals(p.rotamer1) )
return true;
return false;
}
}