1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
3
* Copyright (C) 2004-2007 Egon Willighagen <egonw@users.sf.net>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
package org.openscience.cdk;
24
* Base class for storing interactions like hydrogen bonds and ionic interactions.
25
* The ElectronContainer contains zero electrons by default.
27
* @cdk.module experimental
29
* @cdk.keyword orbital
30
* @cdk.keyword association
33
public class Association extends ElectronContainer implements java.io.Serializable, Cloneable {
36
* Determines if a de-serialized object is compatible with this class.
38
* This value must only be changed if and only if the new version
39
* of this class is imcompatible with the old version. See Sun docs
40
* for <a href=http://java.sun.com/products/jdk/1.1/docs/guide
41
* /serialization/spec/version.doc.html>details</a>.
43
private static final long serialVersionUID = -9138919895942850167L;
45
/** Number of electrons in the association. */
46
protected final int electronCount = 0;
48
/** The atoms which take part in the association. */
49
protected Atom[] atoms;
50
protected int atomCount;
53
* Constructs an association between two Atom's.
55
* @param atom1 An atom to be associated with another atom
56
* @param atom2 An atom to be associated with another atom
57
* @see org.openscience.cdk.Atom
59
public Association(Atom atom1, Atom atom2) {
67
* Constructs an empty association.
69
* @see org.openscience.cdk.Atom
71
public Association() {
77
* Returns the array of atoms making up this Association.
79
* @return An array of atoms participating in this Association
83
public Atom[] getAtoms() {
84
Atom[] returnAtoms = new Atom[atomCount];
85
System.arraycopy(this.atoms, 0, returnAtoms, 0, returnAtoms.length);
90
* Sets the array of atoms making up this Association.
92
* @param atoms An array of atoms that forms this Association
96
public void setAtoms(Atom[] atoms) {
103
* Returns the number of Atoms in this Association.
105
* @return The number of Atoms in this Association
107
public int getAtomCount() {
112
* Returns the number of electrons in a Association.
114
* @return The number of electrons in a Association.
116
public int getElectronCount() {
121
* Returns an Atom from this Association.
123
* @param position The position in this bond where the atom is
124
* @return The atom at the specified position
128
public Atom getAtomAt(int position) {
129
return atoms[position];
133
* Returns true if the given atom participates in this Association.
135
* @param atom The atom to be tested if it participates in this Association
136
* @return true if the atom participates in this Association
138
public boolean contains(Atom atom) {
139
for (int i=0; i<atoms.length; i++) {
140
if (atoms[i] == atom) {
148
* Sets an Atom in this Association.
150
* @param atom The atom to be set
151
* @param position The position in this Association where the atom is to be inserted
155
public void setAtomAt(Atom atom, int position) {
156
atoms[position] = atom;
161
* Returns a one line string representation of this Container.
162
* This method is conform RFC #9.
164
* @return The string representation of this Container
166
public String toString() {
167
StringBuffer s = new StringBuffer();
168
s.append("Association(");
169
s.append(this.hashCode());
170
for (int i=0; i<atomCount; i++) {
171
s.append(atoms[i].toString());