3
* $Date: 2007-08-28 11:21:42 +0200 (Tue, 28 Aug 2007) $
6
* Copyright (C) 1997-2007 Christoph Steinbeck <steinbeck@users.sf.net>
8
* Contact: cdk-devel@lists.sourceforge.net
10
* This program is free software; you can redistribute it and/or
11
* modify it under the terms of the GNU Lesser General Public License
12
* as published by the Free Software Foundation; either version 2.1
13
* of the License, or (at your option) any later version.
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU Lesser General Public License for more details.
20
* You should have received a copy of the GNU Lesser General Public License
21
* along with this program; if not, write to the Free Software
22
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
25
package org.openscience.cdk;
27
import java.io.Serializable;
28
import java.util.ArrayList;
29
import java.util.List;
31
import org.openscience.cdk.interfaces.IAtom;
32
import org.openscience.cdk.interfaces.IAtomContainer;
33
import org.openscience.cdk.interfaces.IRing;
34
import org.openscience.cdk.interfaces.IRingSet;
37
* Maintains a set of Ring objects.
41
* @cdk.keyword ring, set of
43
public class RingSet extends AtomContainerSet implements Serializable, IRingSet, Cloneable {
45
private static final long serialVersionUID = 7168431521057961434L;
47
/** Flag to denote that the set is order with the largest ring first? */
48
public final static int LARGE_FIRST = 1;
49
/** Flag to denote that the set is order with the smallest ring first? */
50
public final static int SMALL_FIRST = 2;
63
* Returns a vector of all rings that this bond is part of.
65
* @param bond The bond to be checked
66
* @return A vector of all rings that this bond is part of
69
public List getRings(org.openscience.cdk.interfaces.IBond bond)
71
List rings = new ArrayList();
73
for (int i = 0; i < getAtomContainerCount(); i++)
75
ring = (Ring)getAtomContainer(i);
76
if (ring.contains(bond))
85
* Returns a vector of all rings that this atom is part of.
87
* @param atom The atom to be checked
88
* @return A vector of all rings that this bond is part of
91
public IRingSet getRings(IAtom atom)
93
IRingSet rings = new RingSet();
95
for (int i = 0; i < getAtomContainerCount();i++)
97
ring = (Ring)getAtomContainer(i);
98
if (ring.contains(atom))
100
rings.addAtomContainer(ring);
107
* Returns all the rings in the RingSet that share
108
* one or more atoms with a given ring.
110
* @param ring A ring with which all return rings must share one or more atoms
111
* @return All the rings that share one or more atoms with a given ring.
114
public List getConnectedRings(IRing ring)
116
List connectedRings = new ArrayList();
119
for (int i = 0; i < ring.getAtomCount(); i++)
121
atom = ring.getAtom(i);
122
for (int j = 0; j < getAtomContainerCount(); j++)
124
tempRing = (IRing)getAtomContainer(j);
125
if (tempRing != ring && !connectedRings.contains(tempRing) && tempRing.contains(atom))
127
connectedRings.add(tempRing);
131
return connectedRings;
135
* Adds all rings of another RingSet if they are not allready part of this ring set.
137
* @param ringSet the ring set to be united with this one.
139
public void add(IRingSet ringSet)
141
for (int f = 0; f < ringSet.getAtomContainerCount(); f++)
143
if (!contains((IRing)ringSet.getAtomContainer(f)))
145
addAtomContainer(ringSet.getAtomContainer(f));
151
* True, if at least one of the rings in the ringset cotains
154
* @param atom Atom to check
155
* @return true, if the ringset contains the atom
157
public boolean contains(IAtom atom) {
158
for (int i = 0; i < getAtomContainerCount(); i++) {
159
if (((IRing)getAtomContainer(i)).contains(atom)) {
167
* Checks for presence of a ring in this RingSet.
169
* @param ring The ring to check
170
* @return true if ring is part of RingSet
173
public boolean contains(IAtomContainer ring) {
174
for (int i = 0; i < getAtomContainerCount(); i++) {
175
if (ring == getAtomContainer(i)) {
183
* Clones this <code>RingSet</code> including the Rings.
185
* @return The cloned object
187
public Object clone() throws CloneNotSupportedException {
188
RingSet clone = (RingSet)super.clone();
189
java.util.Iterator result = atomContainers();
190
while (result.hasNext()) {
191
clone.addAtomContainer((IAtomContainer) ((IAtomContainer)result.next()).clone());
197
* Returns the String representation of this RingSet.
199
* @return The String representation of this RingSet
201
public String toString() {
202
StringBuffer buffer = new StringBuffer(32);
203
buffer.append("RingSet(");
204
buffer.append(this.hashCode());
205
buffer.append(", R=").append(getAtomContainerCount()).append(", ");
206
for (int i = 0; i < atomContainerCount; i++) {
207
IRing possibleRing = (IRing)atomContainers[i];
208
buffer.append(possibleRing.toString());
209
if (i+1 < atomContainerCount) {
214
return buffer.toString();