List backed up by a HashSet
<p>I need to store objects in a collection in the order they were added, that's why I need a <code>List</code>. However, the list should contain no duplicates. I also need to quickly determine if an object already exists in the collection. Instead of iterating the list every time, it would be better to have something like a <code>HashSet</code>. I can quickly both find and add elements and preserve the insertion order.</p>

<p>The question is - should I:</p>

<ol>
<li><p>extend ArrayList by adding a HashSet field?</p></li>
<li><p>implement one of the Java collection interfaces (List or Set)?</p></li>
<li><p>simply create a new class with two fields - ArrayList and
HashSet?</p></li>
</ol>

<p>The 1st option has the disadvantage - I don't need all of the ArrayList methods, so I'd have to override all of them so that users of my class don't call base class methods that would simply mess things up (for instance, one could remove an object from the list but the object would still exist in the set). And there's no way to remove the base class methods (except from overriding it and throwing an exception).</p>

<p>Similarly for 2, I'd really have to implement all methods of the interface.</p>

<p>The 3rd option looks the best to me, but it makes the code implementation dependent, because my class doesn't implement any interface.</p>

<p>What should I do in this case? <strong>I'd like to have all <code>add</code> methods the <code>List</code> interface has. - LinkedHashSet is not an option</strong>.</p>