[
https://issues.apache.org/jira/browse/GEODE-5523?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16628356#comment-16628356
]
ASF subversion and git services commented on GEODE-5523:
--------------------------------------------------------
Commit 1cf64771e786b178ceb92dc6a4a08cf8225a3b2b in geode's branch
refs/heads/develop from Juan Jose Ramos Cassella
[ https://gitbox.apache.org/repos/asf?p=geode.git;h=1cf6477 ]
GEODE-5523: Remove DefaultHashMap
The internal class `DefaultHashMap` was designed as an internal
workaround to return a default value whenever the value returned by
`Map.get(K)` was `null`. Starting with Java 8 the `Map` interface
added the method `getOrDefault`, which does something similar in a more
efficient way but it returns the default only if the key doesn't exist.
After inspecting the code, we don't insert `null` values into the
`statsMap`, so it is safe to delete the old `DefaultHashMap` class and
replace its usaged by `Map.getOrDefault`.
> Remove DefaultHashMap
> ---------------------
>
> Key: GEODE-5523
> URL: https://issues.apache.org/jira/browse/GEODE-5523
> Project: Geode
> Issue Type: Improvement
> Components: general, jmx, statistics
> Reporter: Juan José Ramos Cassella
> Assignee: Juan José Ramos Cassella
> Priority: Major
> Labels: pull-request-available
> Time Spent: 20m
> Remaining Estimate: 0h
>
> The class {{MBeanStatsMonitor}} exposes the static class {{DefaultHashMap}},
> which is basically a wrapper of a simple {{java.util.Map}} that returns a
> default value ({{0}}) when the requested key doesn't exist.
> {code}
> public static class DefaultHashMap { // TODO: delete this class
> private Map<String, Number> internalMap = new HashMap<>();
> public DefaultHashMap() {}
> public Number get(final String key) {
> return internalMap.get(key) != null ? internalMap.get(key) : 0;
> }
> public void put(final String key, final Number value) {
> internalMap.put(key, value);
> }
> public void clear() {
> internalMap.clear();
> }
> /**
> * For testing only
> */
> Map<String, Number> getInternalMap() {
> return this.internalMap;
> }
> }
> {code}
> The containing class, {{MBeanStatsMonitor}}, also has a method that prevents
> {{null}} values from being returned when accessing the {{Map}}, which is
> redundant:
> {code}
> public Number getStatistic(final String statName) {
> Number value = statsMap.get(statName);
> return value != null ? value : 0;
> }
> {code}
> The class {{DefaultHashMap}} should be eliminated, and the method
> {{getStatistic}} should be refactored to use {{Map.getOrDefault(Object key, V
> defaultValue)}} instead of executing the logic manually.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)