I am making an application where users will be typing on a shared document over a network.
One of the issues is blocking lines that other users are typing in.
To do that I have a DocumentListener that is checking for line changes. When a user successfully moves to a new line (which means that line is not used) the listener will notify other users that the line is now used.
A DocumentFilter will check each time an edit is made if that line is blocked, before allowing it.
Now, one of my concerns is what kind of collection is most appropriate for storing the line numbers. The collection will be holding just Integer. When a line is blocked it will be added to that collection. When the DocumentFilter needs to check if a line is available it will go through that list . Also when the user that was using that line moves to a new line, another message is send that will remove that line from the collection of users.
I am aware that an ArrayList will probably be enough although I was hoping someone might think different.
HashSet<Integer>will outperform anArrayList<Integer>by a large margin if you expect a large amount of Lookups and a large amount of blocked documents.As far as i know worst case lookups(referring to “contains”) are
ArrayListSortedListHashSethowever this is related to the hash method ..If you need to track additional data on a per lock basis you might consider to use a
HashMap<Integer, ILockInformation>.