I've created many Geodata objects (name,postalCode,lat,lon). Now 开发者_JAVA技巧I want to put them into a collection to search for different entries later.
Everything should happen objectOriented/in-memory, so there shouln't be a need for a relational database.
Such a Query looks like:
- Find lat and lon by name or plz
- Find objects between LAT1,LAT2 and LON1,LON2
What collection is the best one for such a "simple" datastructure?
What complexity is needed for such a query? Can multithreading be a benefit? If it is, which collection is used at best for thread safety?
Is there a chance to write such queries in a key=>value database?
You could use an in-memory database.
This is good as relational databases are good for relational queries like these.... :-)
For home-made pure Java, you could use:
Map
, with the name as keyMap
, with the plz as keyList<List<"object">>
with LAT for the first list, LON for the second list.
Both are sorted, so for each you can search for a value using binary-search, and return an interval efficiently withsubList
.
This amounts to a duplication for the keys, but not for all objects, as you can reuse the same instance objects in all of these cases.
Multi-threading is acceptable (if your need it for other reasons), but I doubt you need to introduce it to improve the performance of a single search. The data structures mentioned should deliver the correct answers in less than a millisecond !
Thread-safety is not a problem for these data structures, as your use case seem to be read-only. If you need to modify the "objects" in some case, then you can only protect the "objects" themselves, not the data structures used for searching.
精彩评论