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