-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds a method to get datastore map #520
Conversation
} | ||
return null; | ||
} | ||
|
||
public static synchronized ConcurrentHashMap<Object, Object> getMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The DataStore deliberately avoided returning a Map to hide the internal storage implementation. Exposing this would make changing the implementation of the DataStore harder in the future.
Is there a good reason why the getMap methods needs to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just looking to get a list of entries. I can change these to return an entrySet instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now updated to return entrySet only which we also did previously in the old DataStore.
return map.get(); | ||
} | ||
|
||
public static synchronized Set<Map.Entry<Object, Object>> entrySet() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah Ok.
From https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html#entrySet--
public Set<Map.Entry<K,V>> entrySet()
Returns a Set view of the mappings contained in this map.
The set is backed by the map, so changes to the map are reflected in the set,
and vice-versa. If the map is modified while an iteration over the set is in progress
(except through the iterator's own remove operation, or through the setValue
operation on a map entry returned by the iterator) the results of the iteration are
undefined. The set supports element removal, which removes the corresponding
mapping from the map, via the Iterator.remove, Set.remove, removeAll, retainAll
and clear operations. It does not support the add or addAll operations.
The new DataStore was introduced to prevent modification of the map.
To get over this it's better to return an immutable Map
https://docs.oracle.com/javase/9/core/creating-immutable-lists-sets-and-maps.htm#JSCOR-GUID-4F3E2B7D-CE90-4862-A78A-414FC08DA6E4
You can call that method items
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now updated to return a immutable Map.
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Thanks for making the changes @haroon-sheikh thought a bit more about this and the problem with returning the full map will create two ways of accessing the store values i.e.
Which may be redundant.
The here is a re-implementation of the DataStore to show the usage
This way there is only one way to access or add items to the store. Hope this makes sense. |
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
Thanks for the feedback @zabil. I've now made the suggested changes. |
Marked this for release. Can you bump up the version? You can refer dce766b on how to do that. |
Signed-off-by: Haroon Sheikh <haroon.sheikh@sky.uk>
No description provided.