~ubuntu-branches/ubuntu/maverick/cdk/maverick

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/Association.java

  • Committer: Bazaar Package Importer
  • Author(s): Paul Cager
  • Date: 2008-04-09 21:17:53 UTC
  • Revision ID: james.westby@ubuntu.com-20080409211753-46lmjw5z8mx5pd8d
Tags: upstream-1.0.2
ImportĀ upstreamĀ versionĀ 1.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Revision: 7636 $ $Author: egonw $ $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
2
 *
 
3
 * Copyright (C) 2004-2007  Egon Willighagen <egonw@users.sf.net>
 
4
 * 
 
5
 * Contact: cdk-devel@lists.sourceforge.net
 
6
 *
 
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.
 
11
 * 
 
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.
 
16
 * 
 
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. 
 
20
 */
 
21
package org.openscience.cdk;
 
22
 
 
23
/**
 
24
 * Base class for storing interactions like hydrogen bonds and ionic interactions.
 
25
 * The ElectronContainer contains zero electrons by default.
 
26
 *
 
27
 * @cdk.module experimental
 
28
 *
 
29
 * @cdk.keyword orbital
 
30
 * @cdk.keyword association
 
31
 * @cdk.keyword bond
 
32
 */
 
33
public class Association extends ElectronContainer implements java.io.Serializable, Cloneable {
 
34
 
 
35
    /**
 
36
     * Determines if a de-serialized object is compatible with this class.
 
37
     *
 
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>.
 
42
         */
 
43
        private static final long serialVersionUID = -9138919895942850167L;
 
44
 
 
45
        /** Number of electrons in the association. */
 
46
    protected final int electronCount = 0;
 
47
 
 
48
    /** The atoms which take part in the association. */
 
49
    protected Atom[] atoms;
 
50
    protected int atomCount;
 
51
 
 
52
    /**
 
53
     * Constructs an association between two Atom's.
 
54
     *
 
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
 
58
     */
 
59
    public Association(Atom atom1, Atom atom2) {
 
60
        atoms = new Atom[2];
 
61
        atoms[0] = atom1;
 
62
        atoms[1] = atom2;
 
63
        atomCount = 2;
 
64
    }
 
65
 
 
66
    /**
 
67
     * Constructs an empty association.
 
68
     *
 
69
     * @see org.openscience.cdk.Atom
 
70
     */
 
71
    public Association() {
 
72
        atoms = new Atom[2];
 
73
        atomCount = 0;
 
74
    }
 
75
 
 
76
        /**
 
77
         * Returns the array of atoms making up this Association.
 
78
         *
 
79
         * @return An array of atoms participating in this Association
 
80
     *
 
81
     * @see    #setAtoms
 
82
         */
 
83
    public Atom[] getAtoms() {
 
84
        Atom[] returnAtoms = new Atom[atomCount];
 
85
        System.arraycopy(this.atoms, 0, returnAtoms, 0, returnAtoms.length);
 
86
        return returnAtoms;
 
87
    }
 
88
        
 
89
        /**
 
90
         * Sets the array of atoms making up this Association.
 
91
         *
 
92
         * @param   atoms An array of atoms that forms this Association
 
93
     *
 
94
     * @see    #getAtoms
 
95
         */
 
96
        public void setAtoms(Atom[] atoms) {
 
97
                this.atoms = atoms;
 
98
                notifyChanged();
 
99
        }
 
100
 
 
101
 
 
102
        /**
 
103
         * Returns the number of Atoms in this Association.
 
104
         *
 
105
         * @return The number of Atoms in this Association    
 
106
         */
 
107
        public int getAtomCount() {
 
108
                return atomCount;
 
109
        }
 
110
 
 
111
    /**
 
112
     * Returns the number of electrons in a Association.
 
113
     *
 
114
     * @return The number of electrons in a Association.
 
115
     */
 
116
    public int getElectronCount() {
 
117
        return 0;
 
118
    }
 
119
 
 
120
        /**
 
121
         * Returns an Atom from this Association.
 
122
         *
 
123
         * @param   position  The position in this bond where the atom is
 
124
     * @return            The atom at the specified position
 
125
     *
 
126
     * @see     #setAtomAt
 
127
         */
 
128
        public Atom getAtomAt(int position) {
 
129
                return atoms[position];
 
130
        }
 
131
 
 
132
        /**
 
133
         * Returns true if the given atom participates in this Association.
 
134
         *
 
135
         * @param   atom  The atom to be tested if it participates in this Association
 
136
         * @return     true if the atom participates in this Association
 
137
         */
 
138
        public boolean contains(Atom atom) {
 
139
        for (int i=0; i<atoms.length; i++) {
 
140
            if (atoms[i] == atom) {
 
141
                return true;
 
142
            }
 
143
        }
 
144
                return false;
 
145
        }
 
146
 
 
147
        /**
 
148
         * Sets an Atom in this Association.
 
149
         *
 
150
         * @param   atom  The atom to be set
 
151
         * @param   position  The position in this Association where the atom is to be inserted
 
152
     *
 
153
     * @see     #getAtomAt
 
154
         */
 
155
        public void setAtomAt(Atom atom, int position) {
 
156
                atoms[position] = atom;
 
157
                notifyChanged();
 
158
        }
 
159
 
 
160
    /**
 
161
     * Returns a one line string representation of this Container.
 
162
     * This method is conform RFC #9.
 
163
     *
 
164
     * @return    The string representation of this Container
 
165
     */
 
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());
 
172
        }
 
173
        s.append(")");
 
174
        return s.toString();
 
175
    }
 
176
}
 
177
 
 
178