Source code: org/openscience/miniJmol/AtomTypeSet.java
1 /*
2 * AtomTypeSet.java
3 *
4 * Copyright (C) 1999 Bradley A. Smith
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20 package org.openscience.miniJmol;
21
22 import java.util.*;
23 import java.io.*;
24
25 /**
26 * Collection of AtomTypes. No duplicates are allowed. This class is
27 * implemented with Hashtable to allow compatability with Java 1.1.
28 */
29 public class AtomTypeSet extends Hashtable {
30
31 /**
32 * Adds the specified AtomType to this set if it is not already
33 * present.
34 *
35 * @param at AtomType to be added to the set.
36 * @returns true if the set did not already contain the AtomType.
37 */
38 boolean add(BaseAtomType at) {
39 if (contains(at)) {
40 return false;
41 } else {
42 put(at.getName(), at);
43 return true;
44 }
45 }
46
47 /**
48 * Loads AtomTypes from a Reader.
49 */
50 public void load(InputStream input) throws IOException {
51 BufferedReader br1 = new BufferedReader(new InputStreamReader(input), 1024);
52 clear();
53 String line = br1.readLine();
54 while (line != null) {
55 if (!line.startsWith("#")) {
56 add(BaseAtomType.parse(line));
57 }
58 line = br1.readLine();
59 }
60
61 }
62 }