Class WellBehavedMap<K,​V>

  • All Implemented Interfaces:
    java.util.Map<K,​V>

    @GwtCompatible
    final class WellBehavedMap<K,​V>
    extends ForwardingMap<K,​V>
    Workaround for EnumMap bug. If you want to pass an EnumMap, with the intention of using its entrySet() method, you should wrap the EnumMap in this class instead.

    This class is not thread-safe even if the underlying map is.

    • Field Detail

      • delegate

        private final java.util.Map<K,​V> delegate
      • entrySet

        private java.util.Set<java.util.Map.Entry<K,​V>> entrySet
    • Constructor Detail

      • WellBehavedMap

        private WellBehavedMap​(java.util.Map<K,​V> delegate)
    • Method Detail

      • wrap

        static <K,​V> WellBehavedMap<K,​V> wrap​(java.util.Map<K,​V> delegate)
        Wraps the given map into a WellBehavedEntriesMap, which intercepts its entrySet() method by taking the Set<K> keySet() and transforming it to Set<Entry<K, V>>. All other invocations are delegated as-is.
      • delegate

        protected java.util.Map<K,​V> delegate()
        Description copied from class: ForwardingObject
        Returns the backing delegate instance that methods are forwarded to. Abstract subclasses generally override this method with an abstract method that has a more specific return type, such as ForwardingSet.delegate(). Concrete subclasses override this method to supply the instance being decorated.
        Specified by:
        delegate in class ForwardingMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Overrides:
        entrySet in class ForwardingMap<K,​V>