Data structure for fast searching of custom object using its attributes (fields) in Java
<p>I have abstract super class and some sub classes. My question is how is the best way to keep objects of those classes so I can easily find them using all the different parameters.</p>

<p>For example if I want to look up with resourceCode (every object is with unique resource code) I can use HashMap with key value resourceCode. But what happens if I want to look up with genre - there are many games with the same genre so I will get all those games. My first idea was with ArrayList of those objects, but isn’t it too slow if we have 1 000 000 games (about 1 000 000 operations). </p>

<p>My other idea is to have a HashTable with key value the product code. Complexity of the search is constant. After that I create that many HashSets  as I have fields in the classes and for each field I get the productCode/product Codes of the objects, that are in the HashSet under that certain filed (for example game promoter). With those unique codes I can get everything I want from the HashTable. Is this a good idea? It seems there will be needed a lot of space for the date to be stored, but it will be fast.</p>

<p>So my question is what Data Structure should I use so I can implement fast finding of custom object, searching by its attributes (fields)</p>

<p>Please see the attachment: <a href="http://i.stack.imgur.com/9y7e0.png" rel="nofollow">Classes Example</a></p>

<p>Thank you in advanced.</p>

<p>Stefan Stefanov</p>