/** * * @param value * * @return True if one or more of the keys in this map points to the * given value. * */ public final boolean containsValue(Object value) { Iterator i = values().iterator(); // // look through each map entry's set of values to see if // the given value is present // while (i.hasNext()) { Collection values = (Collection)i.next(); if (values.contains(value)) return true; } return false; }
/** * * NOTE: This method takes O(n) time, where n is the number of keys in * the map. It would be more efficient to keep a counter for the size, * but this would require overriding more methods and dealing with the * complicated issue of map integrity and entrySet(). This implementation * is the most robust when you consider that all Maps allow users to * modify their contents without using the interface directly. * * @return The sum of the sizes of all the map entries (value collections). * */ public final int size() { Iterator i = values().iterator(); int count = 0; // // for each key, add the number of values to the count // while (i.hasNext()) { Collection values = (Collection)i.next(); count += values.size(); } return count; } }