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

« back to all changes in this revision

Viewing changes to src/org/openscience/cdk/tools/FixedSizeStack.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
/*
 
2
 * $RCSfile$
 
3
 * $Author: egonw $
 
4
 * $Date: 2007-01-04 18:46:10 +0100 (Thu, 04 Jan 2007) $
 
5
 * $Revision: 7636 $
 
6
 *
 
7
 * Copyright (C) 1997-2007  The Chemistry Development Kit (CDK) project
 
8
 *
 
9
 * Contact: cdk-devel@lists.sourceforge.net
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU Lesser General Public License
 
13
 * as published by the Free Software Foundation; either version 2.1
 
14
 * of the License, or (at your option) any later version.
 
15
 * All we ask is that proper credit is given for our work, which includes
 
16
 * - but is not limited to - adding the above copyright notice to the beginning
 
17
 * of your source code files, and to any copyright notice that you may distribute
 
18
 * with programs based on this work.
 
19
 *
 
20
 * This program is distributed in the hope that it will be useful,
 
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
 * GNU Lesser General Public License for more details.
 
24
 *
 
25
 * You should have received a copy of the GNU Lesser General Public License
 
26
 * along with this program; if not, write to the Free Software
 
27
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
28
 *
 
29
 */
 
30
 
 
31
package org.openscience.cdk.tools;
 
32
 
 
33
/**
 
34
 *  A LIFO queue for result structures. The Size is fixed so that one can use
 
35
 *  this to hold the 10 best structures, e. g.
 
36
 *
 
37
 *@author     steinbeck
 
38
 *@cdk.created    2001-06-05
 
39
 */
 
40
public class FixedSizeStack extends java.util.Vector implements java.io.Serializable {
 
41
 
 
42
    private static final long serialVersionUID = 7820949609007415936L;
 
43
    
 
44
    private int size;
 
45
 
 
46
        /**
 
47
         *  Creates a fixed size stack
 
48
         *
 
49
         *@param  size  The size of this stack
 
50
         */
 
51
        public FixedSizeStack(int size) {
 
52
                super();
 
53
                this.size = size;
 
54
        }
 
55
 
 
56
 
 
57
        /**
 
58
         * Pushes an object onto the stack. If the new size then exceeds the 
 
59
         * standard size of this stack, the oldest elements in the stack are discarded. 
 
60
         *
 
61
         *@param  O  The object to be pushed onto the stack
 
62
         */
 
63
        public void push(Object O) {
 
64
                insertElementAt(O, 0);
 
65
                if (size() > size) {
 
66
                        setSize(size);
 
67
                }
 
68
        }
 
69
 
 
70
 
 
71
        /**
 
72
         *  Returns the last object that was pushed onto the stack
 
73
         *
 
74
         *@return    the last object that was pushed onto the stack
 
75
         */
 
76
        public Object pop() {
 
77
                Object O = elementAt(0);
 
78
                removeElementAt(0);
 
79
                return O;
 
80
        }
 
81
}
 
82