Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-5523

Remove DefaultHashMap

    XMLWordPrintableJSON

Details

    Description

      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.

        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;
          }
        }
      

      The containing class, MBeanStatsMonitor, also has a method that prevents null values from being returned when accessing the Map, which is redundant:

        public Number getStatistic(final String statName) {
          Number value = statsMap.get(statName);
          return value != null ? value : 0;
        }
      

      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.

      Attachments

        Activity

          People

            jjramos Juan Ramos
            jjramos Juan Ramos
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m