View Javadoc

1   /* Copyright (C) 2003 Internet Archive.
2    *
3    * This file is part of the Heritrix web crawler (crawler.archive.org).
4    *
5    * Heritrix is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU Lesser Public License as published by
7    * the Free Software Foundation; either version 2.1 of the License, or
8    * any later version.
9    *
10   * Heritrix is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU Lesser Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser Public License
16   * along with Heritrix; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   *
19   * MemQueue.java
20   * Created on Oct 14, 2003
21   *
22   * $Header$
23   */
24  package org.archive.queue;
25  
26  import java.util.Iterator;
27  import java.util.LinkedList;
28  
29  import org.apache.commons.collections.Predicate;
30  
31  /*** An in-memory implementation of a {@link Queue}.
32   *
33   * @author Gordon Mohr
34   *
35   */
36  public class MemQueue<T> extends LinkedList<T> implements Queue<T> {
37  
38      private static final long serialVersionUID = -9077824759011044247L;
39  
40      /*** Create a new, empty MemQueue
41       */
42      public MemQueue() {
43          super();
44      }
45  
46      /***
47       * @see org.archive.queue.Queue#enqueue(Object)
48       */
49      public void enqueue(T o) {
50          add(o);
51      }
52  
53      /***
54       * @see org.archive.queue.Queue#dequeue()
55       */
56      public T dequeue() {
57          return removeFirst();
58      }
59  
60      /***
61       * @see org.archive.queue.Queue#length()
62       */
63      public long length() {
64          return size();
65      }
66  
67      /***
68       * @see org.archive.queue.Queue#release()
69       */
70      public void release() {
71          // nothing to release
72      }
73  
74      /***
75       * @see org.archive.queue.Queue#peek()
76       */
77      public T peek() {
78          return getFirst();
79      }
80  
81  
82      /***
83       * @see org.archive.queue.Queue#getIterator(boolean)
84       */
85      public Iterator<T> getIterator(boolean inCacheOnly) {
86          return listIterator();
87      }
88  
89      /***
90       * @see org.archive.queue.Queue#deleteMatchedItems(org.apache.commons.collections.Predicate)
91       */
92      public long deleteMatchedItems(Predicate matcher) {
93          Iterator<T> it = listIterator();
94          long numberOfDeletes = 0;
95          while(it.hasNext()){
96              if(matcher.evaluate(it.next())){
97                  it.remove();
98                  numberOfDeletes++;
99              }
100         }
101         return numberOfDeletes;
102     }
103 
104     /* (non-Javadoc)
105      * @see org.archive.queue.Queue#unpeek()
106      */
107     public void unpeek() {
108         // nothing necessary
109     }
110 
111 
112 
113 }