/** * Returns an empty BoundedFifoBuffer that won't overflow. * * @return an empty BoundedFifoBuffer */ public Collection makeCollection() { return new BoundedFifoBuffer(100); }
/** * Returns a BoundedFifoBuffer that's filled to capacity. * Any attempt to add to the returned buffer will result in a * BufferOverflowException. * * @return a full BoundedFifoBuffer */ public Collection makeFullCollection() { return new BoundedFifoBuffer(Arrays.asList(getFullElements())); }
/** * Tests that the constructor correctly throws an exception. */ public void testConstructorException2() { try { new BoundedFifoBuffer(-20); } catch (IllegalArgumentException ex) { return; } fail(); }
/** * Tests that the constructor correctly throws an exception. */ public void testConstructorException3() { try { new BoundedFifoBuffer(null); } catch (NullPointerException ex) { return; } fail(); }
/** * Tests that the constructor correctly throws an exception. */ public void testConstructorException1() { try { new BoundedFifoBuffer(0); } catch (IllegalArgumentException ex) { return; } fail(); }
public void testShift() { BoundedFifoBuffer fifo = new BoundedFifoBuffer(3); fifo.add("a"); fifo.add("b"); fifo.add("c"); fifo.remove(); fifo.add("e"); fifo.remove("c"); }
public void testIsFull() { Set set = new HashSet(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.isFull(null); fail(); } catch (NullPointerException ex) {} assertEquals(false, CollectionUtils.isFull(set)); BoundedFifoBuffer buf = new BoundedFifoBuffer(set); assertEquals(true, CollectionUtils.isFull(buf)); buf.remove("2"); assertEquals(false, CollectionUtils.isFull(buf)); buf.add("2"); assertEquals(true, CollectionUtils.isFull(buf)); Buffer buf2 = BufferUtils.synchronizedBuffer(buf); assertEquals(true, CollectionUtils.isFull(buf2)); buf2.remove("2"); assertEquals(false, CollectionUtils.isFull(buf2)); buf2.add("2"); assertEquals(true, CollectionUtils.isFull(buf2)); }
public void testMaxSize() { Set set = new HashSet(); set.add("1"); set.add("2"); set.add("3"); try { CollectionUtils.maxSize(null); fail(); } catch (NullPointerException ex) {} assertEquals(-1, CollectionUtils.maxSize(set)); BoundedFifoBuffer buf = new BoundedFifoBuffer(set); assertEquals(3, CollectionUtils.maxSize(buf)); buf.remove("2"); assertEquals(3, CollectionUtils.maxSize(buf)); buf.add("2"); assertEquals(3, CollectionUtils.maxSize(buf)); Buffer buf2 = BufferUtils.synchronizedBuffer(buf); assertEquals(3, CollectionUtils.maxSize(buf2)); buf2.remove("2"); assertEquals(3, CollectionUtils.maxSize(buf2)); buf2.add("2"); assertEquals(3, CollectionUtils.maxSize(buf2)); }
BoundedFifoBuffer apiCallHistory = new BoundedFifoBuffer(20); for(int i =1 ; i < 25; i++){ if(apiCallHistory.isFull()){ System.out.println("removing :: "+apiCallHistory.remove()); } apiCallHistory.add(i); }