KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > matuschek > spider > MemoryTaskList


1 package net.matuschek.spider;
2
3 /*********************************************
4     Copyright (c) 2001 by Daniel Matuschek
5  *********************************************/

6
7
8 import java.util.Vector JavaDoc;
9
10 /**
11  * Memory based implementation of the TaskList interface. Uses an
12  * Vector to store the tasks.
13  * To be thread safe, all methods are synchronized.
14  *
15  * @author Daniel Matuschek
16  * @version $Id: MemoryTaskList.java,v 1.4 2001/07/31 12:18:52 matuschd Exp $
17  * @deprecated Use the new HashedMemoryTaskList for better performance (but
18  * requires more memory)
19  */

20 public class MemoryTaskList
21   implements TaskList
22 {
23
24
25   /**
26    * Task store
27    *
28    * @link aggregation
29    * @associates <{RobotTask}>
30    */

31   private Vector JavaDoc list = new Vector JavaDoc();
32
33
34   /**
35    * Simple constructor, does nothing special
36    */

37   public MemoryTaskList() {
38   }
39
40
41   /**
42    * Add a task to the end of the list
43    * @param task a RobotTask object to store in the queue
44    */

45   public synchronized void add(RobotTask task) {
46     list.add(task);
47   }
48
49
50   /**
51    * Add a task at the beginning of list
52    * @param task a RobotTask object to store in the queue
53    */

54   public synchronized void addAtStart(RobotTask task) {
55     list.add(0,task);
56   }
57
58
59   /**
60    * Clean up the list, remove all objects
61    */

62   public synchronized void clear() {
63     list.clear();
64   }
65
66
67   /**
68    * Is this robot task stored in the list ?
69    */

70   public synchronized boolean contains(RobotTask task) {
71     return list.contains(task);
72   }
73
74
75   /**
76    * Remove this object from the list
77    */

78   public synchronized boolean remove(RobotTask task) {
79     return list.remove(task);
80   }
81
82   
83   /**
84    * Get and remove the first element.
85    * @return the first task in the list. This object will also be removed
86    * from the list.
87    * @exception ArrayIndexOutOfBoundsException if the list is empty
88    */

89   public synchronized RobotTask removeFirst()
90     throws ArrayIndexOutOfBoundsException JavaDoc
91   {
92     RobotTask task = (RobotTask)list.elementAt(0);
93     list.removeElementAt(0);
94     return task;
95   }
96
97
98   /**
99    * Returns the number of elements in this list
100    */

101   public synchronized int size() {
102     return list.size();
103   }
104
105
106   /**
107    * Get the n-th element in the list. Elements are numbered form 0 to
108    * size-1.
109    * @param position
110    * @exception ArrayIndexOutOfBoundsException if the given position doesn't
111    * exist
112    */

113   public synchronized RobotTask elementAt(int position)
114     throws ArrayIndexOutOfBoundsException JavaDoc
115   {
116     return (RobotTask)(list.elementAt(position));
117   }
118
119 }
120
Popular Tags