JavaMiscellaneous: AbstractMap


AbstractMap

Introduction

AbstractMap is implemented on top of its entrySet. This leads to some inefficiencies if the implementation is not based on existing Map.Entrys, but has to create them for the iteration. It is then better to base some implementations on keySet/values or to code them directly.

Queries

size

By default creates the entrySet (if lazy), can be overridden to avoid it.

get

By default iterates over the entrySet, can be overridden to do it directly.

containsKey

By default iterates over the entrySet, can be overridden to use the keySet or directly.

containsValue

By default iterates over the entrySet, can be overridden to use the values Collection or directly (but is not an important method)

keySet

By default most methods are based on the entrySet iterator. Only used from the outside.

values

By default most methods are based on the entrySet iterator. Only used from the outside.

hashCode

By default iterates over the entrySet

equals

By default iterates over the entrySet

toString

By default iterates over the entrySet

Modifications

remove

By default iterates over the entrySet, can be overridden to do it directly (alas, it has to return the old value, otherwise it could simply use the keySet).

clear

By default clears the entrySet, can be overridden to do it directly or to clear the keySet (or the values Collection).

Implementing entrySet on top of get/put

TBD


(C) 2001-2009 Christian Kaufhold (swing@chka.de)