Note that I'm not actually doing anything with the database, so the ORM tools are probably not what I'm looking for.
I want to have several containers, each of which contains several objects, and all objects in one container have one class. The container should display the behavior of the database table, namely:
- allows you to use one of the fields of the object as a unique key, i.e. E. Other objects that have the same value in this field are not added to the container.
- after accepting a new object, the container should issue a numerical identifier that is returned to the calling insert method.
Instead of throwing an error when a βrepeat entryβ is requested, the container should just skip pasting and return the key of an existing object.
Now I would write a generic container class that accepts objects that implement the interface to get the key field value, and use a HashMap with these values ββas a real storage class. Is there a better approach using existing built-in classes? I was browsing through HashSet and the like, but they didn't seem to fit in.
java collections data-structures
Hanno fietz
source share