Is there something like a two sided list in Java? Maybe a third party implementation?
Here a little example to demonstrate what I have in mind.
Original state:
A: 0-1-2-3 | | | | B: 0-1-2-3
After removal of element 1 in B:
Null
|
A: 0-1-2-3
| / /
B: 0-1-2
The data structure must be accessible from both sides. So it’s more a mix of a bidirectional map and a list.
Things I thought about:
a) Using two lists that store Integer objects. The downside is that those must always be kept in sync.
b) Using a BidiMap from Apache Commons. The downside hereby is that it is unsorted and doesn’t behave like a list when elements are removed (updating the other indidces).
At the end I used two lists that save the positions viewed from each site.
As I always only modify one of the lists, the other will be recalculated.
Below the full code (if someone is interested). It is embedded into a JFace document class, but the logic could also be implemented somewhere else.