UniqueList extends AbstractList<T> implements List<T> { @Override public T set(final int index, final T element) { final String elementName = element.getName(); if (this.elementByName.containsKey(elementName)) { throw new IllegalArgumentException("Element " + elementName + " already in list"); } this.elementByName.put(elementName, element); return this.list.set(index, element); } UniqueList(); @Override void add(final int index, final T element); @Override T get(final int index); T getByName(final String name); Set<String> nameSet(); @Override T remove(final int index); @Override boolean remove(final Object o); T removeByName(final String name); @Override T set(final int index, final T element); @Override int size();  }
@Test() public final void testSet() { final UniqueList<FirstLetter> ul = new UniqueList<FirstLetter>(); ul.add(new FirstLetter("FastODS")); ul.add(new FirstLetter("GastODS")); Assert.assertEquals(Sets.newHashSet("F", "G"), ul.nameSet()); }