/
Orbit.java
191 lines (168 loc) · 4.91 KB
/
Orbit.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/* Copyright (C) 2009-2010 maclean {gilleain.torrance@gmail.com}
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package org.openscience.cdk.signature;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
/**
* A list of atom indices, and the label of the orbit.
*
* @cdk.module signature
* @author maclean
*
*/
@TestClass("org.openscience.cdk.signature.OrbitTest")
public class Orbit implements Iterable<Integer>, Cloneable {
/**
* The atom indices in this orbit
*/
private List<Integer> atomIndices;
/**
* The label that all the atoms in the orbit share
*/
private String label;
/**
* The maximum height of the signature string
*/
private int height;
/**
* @param label
* @param height
*/
public Orbit(String label, int height) {
this.label = label;
this.atomIndices = new ArrayList<Integer>();
this.height = height;
}
/* (non-Javadoc)
* @see java.lang.Iterable#iterator()
*/
public Iterator<Integer> iterator() {
return this.atomIndices.iterator();
}
/* (non-Javadoc)
* @see java.lang.Object#clone()
*/
@TestMethod("testClone")
public Object clone() {
Orbit o = new Orbit(this.label, this.height);
for (Integer i : this.atomIndices) {
o.atomIndices.add(new Integer(i));
}
return o;
}
/**
* Sorts the atom indices in this orbit
*/
public void sort() {
// TODO : change the list to a sorted set?
Collections.sort(this.atomIndices);
}
/**
* Gets the height of the signature label.
*
* @return the height of the signature of this orbit
*/
public int getHeight() {
return this.height;
}
/**
* Gets all the atom indices as a list.
*
* @return the atom indices
*/
public List<Integer> getAtomIndices() {
return this.atomIndices;
}
/**
* Adds an atom index to the orbit.
*
* @param atomIndex the atom index
*/
public void addAtom(int atomIndex) {
this.atomIndices.add(atomIndex);
}
/**
* Checks to see if the orbit has this string as a label.
*
* @param otherLabel the label to compare with
* @return true if it has this label
*/
public boolean hasLabel(String otherLabel) {
return this.label.equals(otherLabel);
}
/**
* Checks to see if the orbit is empty.
*
* @return true if there are no atom indices in the orbit
*/
@TestMethod("isEmptyTest")
public boolean isEmpty() {
return this.atomIndices.isEmpty();
}
/**
* Gets the first atom index of the orbit.
*
* @return the first atom index
*/
public int getFirstAtom() {
return this.atomIndices.get(0);
}
/**
* Removes an atom index from the orbit.
*
* @param atomIndex the atom index to remove
*/
public void remove(int atomIndex) {
this.atomIndices.remove(this.atomIndices.indexOf(atomIndex));
}
/**
* Gets the label of the orbit.
*
* @return the orbit's string label
*/
public String getLabel() {
return this.label;
}
/**
* Checks to see if the orbit contains this atom index.
*
* @param atomIndex the atom index to look for
* @return true if the orbit contains this atom index
*/
@TestMethod("containsTest")
public boolean contains(int atomIndex) {
return this.atomIndices.contains(atomIndex);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
return label + " " +
Arrays.deepToString(atomIndices.toArray());
}
}