/** * Returns the element at the specified position in this list. If index > size, * returns null. Otherwise tries to access the array * @param index * @return * @throws IndexOutOfBoundsException in index < 0 */ public E get(int index) throws IndexOutOfBoundsException { if ( index < size() ) return super.get(index); else return null; }
@Test public void testSettingTenElements() { logger.warn("Executing testSettingTenElements"); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(i+1, (int)hasTen.set(i, 2*i)); } Assert.assertEquals(10, hasTen.size()); for ( int i = 0; i < 10; i++ ) { Assert.assertEquals(2*i, (int)hasTen.get(i)); } }
@Test public void testSetExpandingBig() { logger.warn("Executing testSetExpandingBig"); Assert.assertEquals(0, empty.size()); empty.set(1000, 1000); Assert.assertEquals(1001, empty.size()); for ( int i = 0; i < 1000; i++ ) Assert.assertEquals(empty.get(i), null); Assert.assertEquals(1000, (int)empty.get(1000)); }
@Test public void testSet1() { logger.warn("Executing testSet1"); Assert.assertEquals(0, empty.size()); empty.set(0, 1); Assert.assertEquals(1, empty.size()); Assert.assertEquals(1, (int)empty.get(0)); empty.set(1, 2); Assert.assertEquals(2, empty.size()); Assert.assertEquals(2, (int)empty.get(1)); // doesn't expand empty.set(0, 3); Assert.assertEquals(2, empty.size()); Assert.assertEquals(3, (int)empty.get(0)); }
/** * Put mapResult into this MapResultsQueue, associated with its jobID * @param mapResult a non-null map result */ public synchronized void put(final MapResult<MapType> mapResult) { if ( mapResult == null ) throw new IllegalArgumentException("mapResult cannot be null"); // make sure that nothing is at the job id for map assert queue.size() < mapResult.getJobID() || queue.get(mapResult.getJobID()) == null; queue.set(mapResult.getJobID(), mapResult); }
@Test public void testSetExpanding() { logger.warn("Executing testSetExpanding"); Assert.assertEquals(0, empty.size()); empty.set(3, 1); Assert.assertEquals(4, empty.size()); Assert.assertEquals(empty.get(0), null); Assert.assertEquals(empty.get(1), null); Assert.assertEquals(empty.get(2), null); Assert.assertEquals(1, (int)empty.get(3)); }
@Test public void testSetExpandingReset() { logger.warn("Executing testSetExpandingReset"); Assert.assertEquals(0, empty.size()); empty.set(3, 3); empty.set(2, 2); empty.set(1, 1); empty.set(0, 0); Assert.assertEquals(4, empty.size()); for ( int i = 0; i < 4; i++ ) Assert.assertEquals(i, (int)empty.get(i)); }