I decided to do server-side sorting. I have a HashMap with Objects (key is a String, value is an ItemDTO). These are loaded statically upon server start.
For every character (CharacterDTO) that has an amount of items (in this case ItemOnCharacterDTO) I need to be able to sort stuff. So my client sends a request for sorting the objects as well as some filter-data. What I now want to do is:
- get the full ItemDTOs based on the IDs saved in ItemOnCharacterDTOs
- add those ItemDTOs into a list
- sort the ItemDTOs inside that list (probably using a Comparator)
- create an Array of IDs (it corresponds to the sequence of the list of ItemDTOs after the sorting)
- discard the list of ItemDTOs that I've previously created, since I got the correct order after sorting already
My question is now: do I need to copy the ItemDTOs before adding them to the list in order to not interfere with several sortings going on at the same time?
I do change the order of ItemDTOs within the newly created list of ItemDTOs (step 2 above), but I don't change the ItemDTOs themselves (hence they are static and within the HashMap I mentioned at the beginning).
Thank you for your help in advance!