/** Return the underlying Collection that holds the BufferList */ public List getCollection() { return bufferHolder.getCollection(); }
private void resetBuffer(LinkedList list) { bufferHolder.setCollection(list); }
public synchronized void addRow(Object obj) { if (!enabled || bufferSize<=0) return; // remove the oldest element if the buffer is to capacity. if (getRowCount()>=bufferSize && bufferHolder.shouldReplaceWith(obj)) { bufferHolder.remove(obj); } if (getRowCount()<bufferSize) { bufferHolder.add(obj); } }
/** Reduce size of buffer while not losing current elements beyond what the size reduction would cause. If the size is increased then no loss * of data occurs. * */ private LinkedList reduceBuffer(int newSize) { LinkedList newBuffer=new LinkedList(); List original=bufferHolder.getOrderedCollection(); Collections.reverse(original);// reverse to save the most recent values Iterator iter=original.iterator(); int i=0; while (iter.hasNext() && i<newSize) { newBuffer.add(iter.next()); i++; } return newBuffer; }
public synchronized BufferList copy() { return new BufferList(header, bufferSize, enabled, bufferHolder.copy()); }
/** Return the rows in the BufferList */ public int getRowCount() { return (bufferHolder==null) ? 0 : bufferHolder.getCollection().size(); }
/** Reset BufferList. It will empty the buffer and leave its size at the current value */ public synchronized void reset() { bufferHolder.setCollection(new LinkedList()); }