01: package com.jamonapi.utils;
02:
03: import java.util.*;
04:
05: /** First-in, first-out buffer. When the BufferList is filled the first element is removed to
06: * make room for the newest value, then the second oldest etc. Used in BufferList and subsequently
07: * JAMonBufferListeners.
08: *
09: * @author steve souza
10: *
11: */
12: public class FIFOBufferHolder implements BufferHolder {
13:
14: private LinkedList bufferList = new LinkedList();
15:
16: public void add(Object replaceWithObj) {
17: bufferList.addLast(replaceWithObj);
18:
19: }
20:
21: public void remove(Object replaceWithObj) {
22: bufferList.removeFirst();
23:
24: }
25:
26: public boolean shouldReplaceWith(Object replaceWithObj) {
27: return true;
28: }
29:
30: public List getCollection() {
31: return bufferList;
32: }
33:
34: public List getOrderedCollection() {
35: return bufferList;
36:
37: }
38:
39: public void setCollection(List list) {
40: this .bufferList = (LinkedList) list;
41:
42: }
43:
44: public BufferHolder copy() {
45: return new FIFOBufferHolder();
46: }
47:
48: }
|