001: /**
002: * Copyright (C) 2006, 2007 David Bulmore, Software Sensation Inc.
003: * All Rights Reserved.
004: *
005: * This file is part of jCommonTk.
006: *
007: * jCommonTk is free software; you can redistribute it and/or modify it under
008: * the terms of the GNU General Public License (Version 2) as published by
009: * the Free Software Foundation.
010: *
011: * jCommonTk is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with jCommonTk; if not, write to the Free Software Foundation,
018: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
019: */package jcommontk.utils;
020:
021: import java.util.Collection;
022: import java.util.Vector;
023:
024: @SuppressWarnings("unchecked")
025: // working to complete a Java 1.5 version
026: public class Queue extends Vector {
027: private static final long serialVersionUID = 100L;
028: int max_capacity = 0;
029:
030: public Queue() {
031: super ();
032: }
033:
034: public Queue(Collection c) {
035: super (c);
036: }
037:
038: public Queue(int initialCapacity) {
039: super (initialCapacity);
040: }
041:
042: public Queue(int initialCapacity, int capacityIncrement) {
043: super (initialCapacity, capacityIncrement);
044: }
045:
046: public void setMaximumCapacity(int max) {
047: max_capacity = max;
048: }
049:
050: public boolean empty() {
051: return size() == 0 ? true : false;
052: }
053:
054: public void push(Object obj) {
055: add(obj);
056:
057: if (max_capacity > 0 && size() > max_capacity)
058: pop();
059: }
060:
061: public Object pop() {
062: if (size() > 0)
063: return remove(0);
064:
065: return null;
066: }
067:
068: public Object peek() {
069: if (size() > 0)
070: return get(0);
071:
072: return null;
073: }
074:
075: public int search() {
076: return 0;
077: }
078:
079: public void pushTop(Object obj) {
080: insertElementAt(obj, 0);
081:
082: if (max_capacity > 0 && size() > max_capacity)
083: popBottom();
084: }
085:
086: public Object popBottom() {
087: if (size() > 0)
088: return remove(size() - 1);
089:
090: return null;
091: }
092:
093: public Object peekBottom() {
094: if (size() > 0)
095: return get(size() - 1);
096:
097: return null;
098: }
099:
100: public int searchBottom() {
101: return 0;
102: }
103: }
|