The Artima Developer Community
Sponsored Link

Java Answers Forum
entrySet() Analysis

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Steve Schooler

Posts: 17
Nickname: zugzwang
Registered: Aug, 2004

entrySet() Analysis Posted: Oct 12, 2004 3:43 PM
Reply to this message Reply
Advertisement

Goal: Understand how changes made to a map's entrySet simultaneously
change the underlying map itself.

Reason: Bruce Eckel - Thinking in Java 3rd Ed. - p 579-580 - ex 34-37

Author creates a "SlowMap" extension to AbstractMap which is
(initially) based on 2 ArrayLists: keys and values. Author starts
with entrySet() method that returns HashSet of key/value pairs.
Since this HashSet is not "backed" by the SlowMap, changes made via
HashSet.iterator() et al are not reflected in SlowMap.

Challenge: As elegantly as possible, alter SlowMap so that SlowMap.entrySet()
returns set that IS backed by the SlowMap.

Problem: Tried to examine \java\util\*.* source code via my installation's
..\j2sdk1.4.2\src.zip. Examined Map.java, AbstractMap.java, and
HashMap.java, and became confused.

Request: 1. Am I examining the appropriate source code files?
2. Easier to meet challenge if I could find/understand the specific
source code that allows entrySet.Iterator() changes to
simultaneously affect underlying map.
3. Nice if also got sample code or url ref to sample. Perhaps not
uncommon to extend AbstractMap for customized Map.

Topic: Linking Records to Files on a Server Previous Topic   Next Topic Topic: a conceptual query about keyevent handling

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use