Stephen,

 

I'm all for adding support for unmodifiableIterable, unmodifableNavigableMap, 
and unmodifableNavigableSet.  However, I think adding public access to such a 
iterator decorator goes against the guidelines of the collections design faq (4 
and 5):

http://java.sun.com/javase/6/docs/technotes/guides/collections/designfaq.html#8

 

 

So following the guideline of never passing an Iterator around, that leaves you 
with the following:

1. Your custom container is backed by collection, use 
Collections.unmodifiableXXX(this.internal).iterator()

2. Your custom container is backed by an array, use Arrays.asList, followed by 
point 1.

3. Your custom container has specialized layout, you have to write an iterator 
with a remove implementation that removes or throws and the unmodifable one is 
easy to write.

 

Assuming that JDK had unmodifiableIterable decorator, is there is there a 
corner case that I'm not seeing or is the main reservation the extra method 
calls and creation of some well behaved garbage?

 

Jason
 
> Date: Tue, 30 Mar 2010 17:01:57 -0400
> Subject: Re: java.util.Pair
> From: scolebou...@joda.org
> To: core-libs-dev@openjdk.java.net
> 
> (I´m writing from a slow connection in a national park in Chile)
> 
> I meant a decortator for an iterator that wraps the original making it
> immutable.
> 
> Stephen
                                          
_________________________________________________________________
Hotmail: Trusted email with Microsoft’s powerful SPAM protection.
http://clk.atdmt.com/GBL/go/210850552/direct/01/

Reply via email to