/** * {@inheritDoc} */ @Override public T get(int index) { return getHardReference(refs.get(index)); }
@Test(expectedExceptions = { IndexOutOfBoundsException.class }) public void outOfBounds() { assertThat(weakList.get(5), is(nullValue())); }
@BeforeMethod public void initTestClass() { weakList = new WeakList<Object>(); }
/** * Returns a list of hard references. Skips all weak references but doesn't delete them if there * are any. The list returned (especially the indices) aren't the same as the ones from this * list. * * @return An {@link ArrayList} containing all the hard references of this weak list. */ public List<T> getHardReferences() { List<T> result = new ArrayList<T>(); for (int i = 0; i < size(); i++) { T tmp = get(i); if (null != tmp) { result.add(tmp); } } return result; }
/** * {@inheritDoc} */ @Override public T remove(int index) { return getHardReference(refs.remove(index)); }
/** * {@inheritDoc} */ @Override public T set(int index, T element) { return getHardReference(refs.set(index, new SoftReference<T>(element))); }