/** * Adds an item to the end of the queue, which is the front of the list. * <p> * @param object */ public void add( T object ) { if ( list.size() >= maxSize ) { list.removeLast(); } list.addFirst( new DoubleLinkedListNode<T>( object ) ); }
/** * Returns the size of the list. * <p> * @return int */ private int dumpCacheSize() { return list.size(); }
/** * Makes the item the last in the list. * <p> * @param me */ @Override protected void adjustListForGet( MemoryElementDescriptor<K, V> me ) { list.makeLast( me ); } }
/** verify that it's added last. */ public void testMakeLast_wasAlone() { // SETUP DoubleLinkedList<DoubleLinkedListNode<String>> list = new DoubleLinkedList<DoubleLinkedListNode<String>>(); String payload1 = "payload1"; DoubleLinkedListNode<String> node1 = new DoubleLinkedListNode<String>( payload1 ); list.addFirst( node1 ); // DO WORK list.makeLast( node1 ); // VERIFY assertEquals( "Wrong size", 1, list.size() ); assertEquals( "Wrong last", node1, list.getLast() ); assertEquals( "Wrong first", node1, list.getFirst() ); }
/** verify that the last is added when the list is empty. */ public void testAddLast_Empty() { // SETUP DoubleLinkedList<DoubleLinkedListNode<String>> list = new DoubleLinkedList<DoubleLinkedListNode<String>>(); String payload1 = "payload1"; DoubleLinkedListNode<String> node1 = new DoubleLinkedListNode<String>( payload1 ); // WO WORK list.addLast( node1 ); // VERIFY assertEquals( "Wrong last", node1, list.getLast() ); }
/** * Verify null returned for empty. */ public void testTakeLastEmpty() { // SETUP int maxSize = 10; BoundedQueue<Object> queue = new BoundedQueue<Object>( maxSize ); // DO WORK Object result = queue.take(); // VERIFY assertNull( "Result should be null", result ); }
/** * Call remove on an empty map * */ public void testRemoveEmpty() { int size = 10; Map<String, String> cache = new LRUMap<String, String>( size ); Object returned = cache.remove( "key:" + 1 ); assertNull( "Shouldn't hvae anything.", returned ); }
/** * Verify that we get a null and that there are no exceptions. */ public void testTakeFromEmptyList() { // SETUP SingleLinkedList<Object> list = new SingleLinkedList<Object>(); // DO WORK Object result = list.takeFirst(); // VERIFY assertNull( "Shouldn't have anything.", result ); }
@Override public void runTest() throws Exception { this.runConcurrentRangeTests( map2, 0, 9999 ); } } );
/** * @return Returns the number of empty blocks. */ protected int getEmptyBlocks() { return this.emptyBlocks.size(); }
/** * Returns the size of the recyclebin in number of elements. * <p> * @return The number of items in the bin. */ protected int getRecyleBinSize() { return this.recycle.size(); }
/** * Makes the item the first in the list. * <p> * @param me */ @Override protected void adjustListForGet( MemoryElementDescriptor<K, V> me ) { list.makeFirst( me ); } }
@Override public boolean shouldRemove() { return maxObjects > 0 && this.size() > maxObjects; }
@Override public void runTest() throws Exception { this.runConcurrentRangeTests( map2, 10000, max2 ); } } );
@Override public void runTest() throws Exception { this.runConcurrentPutGetTests( map, 2000 ); } } );
/** verify that the last is added when the list is empty. */ public void testAddLast_Empty() { // SETUP DoubleLinkedList<DoubleLinkedListNode<String>> list = new DoubleLinkedList<DoubleLinkedListNode<String>>(); String payload1 = "payload1"; DoubleLinkedListNode<String> node1 = new DoubleLinkedListNode<String>( payload1 ); // WO WORK list.addLast( node1 ); // VERIFY assertEquals( "Wrong last", node1, list.getLast() ); }
/** * Return true if the size is <= 0; * <p> * @return true is size <= 0; */ public boolean isEmpty() { return list.size() <= 0; } }
@Override public void runTest() throws Exception { this.runConcurrentRangeTests( map2, 0, 9999 ); } } );
/** verify that the last is added when the list is empty. */ public void testAddLast_NotEmpty() { // SETUP DoubleLinkedList<DoubleLinkedListNode<String>> list = new DoubleLinkedList<DoubleLinkedListNode<String>>(); String payload1 = "payload1"; DoubleLinkedListNode<String> node1 = new DoubleLinkedListNode<String>( payload1 ); String payload2 = "payload2"; DoubleLinkedListNode<String> node2 = new DoubleLinkedListNode<String>( payload2 ); // WO WORK list.addLast( node1 ); list.addLast( node2 ); // VERIFY assertEquals( "Wrong last", node2, list.getLast() ); }
/** verify that the last is added when the list is empty. */ public void testAddLast_NotEmpty() { // SETUP DoubleLinkedList<DoubleLinkedListNode<String>> list = new DoubleLinkedList<DoubleLinkedListNode<String>>(); String payload1 = "payload1"; DoubleLinkedListNode<String> node1 = new DoubleLinkedListNode<String>( payload1 ); String payload2 = "payload2"; DoubleLinkedListNode<String> node2 = new DoubleLinkedListNode<String>( payload2 ); // WO WORK list.addLast( node1 ); list.addLast( node2 ); // VERIFY assertEquals( "Wrong last", node2, list.getLast() ); }