@Override public void insert(int elementId, float rank) { buckets[getRankIdx(rank)].pushFront(handles[elementId]); size++; }
/** * Updates the priority of the given queue item from the oldPriority to the newPriority. * <p /> * NOTE: The given {@link MaterialRequestObject} must be in the queue with the given oldPriority! There will be no checks! * * @param oldPriority * @param newPriority * @param materialRequest */ final void updatePriority(EPriority oldPriority, EPriority newPriority, MaterialRequestObject materialRequest) { EBuildingType buildingType = materialRequest.getBuildingType(); getQueue(oldPriority, buildingType).remove(materialRequest); getQueue(newPriority, buildingType).pushFront(materialRequest); // TODO @Andreas Eberle: check if this should be pushEnd() }
@Test public void testPushFrontAndPopFrontWithClear() { for (int i = 0; i < TEST_NUMBERS; i++) { list.pushFront(new DoubleLinkedIntListItem(i)); } assertEquals(TEST_NUMBERS, list.size()); list.clear(); assertEquals(0, list.size()); testPushFrontAndPopFront(); }
@Test public void testPushFrontAndPopFront() { assertEquals(0, list.size()); for (int i = 0; i < TEST_NUMBERS; i++) { list.pushFront(new DoubleLinkedIntListItem(i)); assertEquals(i + 1, list.size()); } for (int i = TEST_NUMBERS - 1; i >= 0; i--) { assertEquals(i + 1, list.size()); assertEquals(i, list.popFront().value); } assertEquals(0, list.size()); }
@Test public void testRemoveByHandle() { DoubleLinkedIntListItem handles[] = new DoubleLinkedIntListItem[TEST_NUMBERS]; for (int i = 0; i < TEST_NUMBERS; i++) { handles[i] = new DoubleLinkedIntListItem(i); list.pushFront(handles[i]); } list.remove(handles[4]); list.remove(handles[7]); assertEquals("incorrect size after removing 2 values", TEST_NUMBERS - 2, list.size()); assertNull("the removed item should not hold a 'next' reference", handles[4].next); assertNull("the removed item should not hold a 'prev' reference", handles[4].prev); assertNull("the removed item should not hold a 'next' reference", handles[7].next); assertNull("the removed item should not hold a 'prev' reference", handles[7].prev); for (int i = TEST_NUMBERS - 1; i >= 0; i--) { if (i == 4 || i == 7) { // skip the removed values continue; } assertEquals(i, list.popFront().value); } assertEquals("incorrect size after popFront all values", 0, list.size()); }