001: package net.matuschek.spider;
002:
003: /*********************************************
004: Copyright (c) 2001 by Daniel Matuschek
005: *********************************************/
006:
007: import java.util.Vector;
008:
009: /**
010: * Memory based implementation of the TaskList interface. Uses an
011: * Vector to store the tasks.
012: * To be thread safe, all methods are synchronized.
013: *
014: * @author Daniel Matuschek
015: * @version $Id: MemoryTaskList.java,v 1.4 2001/07/31 12:18:52 matuschd Exp $
016: * @deprecated Use the new HashedMemoryTaskList for better performance (but
017: * requires more memory)
018: */
019: public class MemoryTaskList implements TaskList {
020:
021: /**
022: * Task store
023: *
024: * @link aggregation
025: * @associates <{RobotTask}>
026: */
027: private Vector list = new Vector();
028:
029: /**
030: * Simple constructor, does nothing special
031: */
032: public MemoryTaskList() {
033: }
034:
035: /**
036: * Add a task to the end of the list
037: * @param task a RobotTask object to store in the queue
038: */
039: public synchronized void add(RobotTask task) {
040: list.add(task);
041: }
042:
043: /**
044: * Add a task at the beginning of list
045: * @param task a RobotTask object to store in the queue
046: */
047: public synchronized void addAtStart(RobotTask task) {
048: list.add(0, task);
049: }
050:
051: /**
052: * Clean up the list, remove all objects
053: */
054: public synchronized void clear() {
055: list.clear();
056: }
057:
058: /**
059: * Is this robot task stored in the list ?
060: */
061: public synchronized boolean contains(RobotTask task) {
062: return list.contains(task);
063: }
064:
065: /**
066: * Remove this object from the list
067: */
068: public synchronized boolean remove(RobotTask task) {
069: return list.remove(task);
070: }
071:
072: /**
073: * Get and remove the first element.
074: * @return the first task in the list. This object will also be removed
075: * from the list.
076: * @exception ArrayIndexOutOfBoundsException if the list is empty
077: */
078: public synchronized RobotTask removeFirst()
079: throws ArrayIndexOutOfBoundsException {
080: RobotTask task = (RobotTask) list.elementAt(0);
081: list.removeElementAt(0);
082: return task;
083: }
084:
085: /**
086: * Returns the number of elements in this list
087: */
088: public synchronized int size() {
089: return list.size();
090: }
091:
092: /**
093: * Get the n-th element in the list. Elements are numbered form 0 to
094: * size-1.
095: * @param position
096: * @exception ArrayIndexOutOfBoundsException if the given position doesn't
097: * exist
098: */
099: public synchronized RobotTask elementAt(int position)
100: throws ArrayIndexOutOfBoundsException {
101: return (RobotTask) (list.elementAt(position));
102: }
103:
104: }
|