Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Let Elements implement java.lang.Iterable

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: "Steve Loughran" <steve.loughran AT gmail.com>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Let Elements implement java.lang.Iterable
  • Date: Tue, 18 Mar 2008 21:42:52 +0000

On Tue, Mar 11, 2008 at 3:36 AM, Elliotte Harold <elharo AT metalab.unc.edu>
wrote:
> You know, I was about to say "Not going to happen as long as Java allows
> type-erasure", but now that I think about it for 30 seconds, does that
> matter? I could expose Iterable<Node> without actually compromising
> XOM's type-safety. What do people think?
>
> I'm still not convinced this is a good idea. For one thing I expect
> people would be surprised by just what an Element iterated over, no
> matter what I picked.
>
> Also it would tie XOM to Java 5, and I'm not quite ready to do that yet.
> If I do this it would probably be in 1.3.

1. the transition to java1.5 is good, though I understand why there
may be some reluctance, especially from tools pushing their users
forward. Ant is still 1.4-enabled. We jumped to 1.5 acrss smartfrog
because the pre-1.5 concurrency model was inadequate, but I dont
regret it. There are lots of things to like
-java concurrency
-StringBuilder
-generics
Moving to generics can be fairly traumatic though. You need to
understand what you are doing, or be prepared to learn through
experimentation

2. I have iterability extensions for Xom here
http://smartfrog.svn.sourceforge.net/viewvc/smartfrog/trunk/core/components/xml/src/org/smartfrog/services/xml/utils/iterators/

Note that by making Iterators implement Iterable, you can do
for(Attribute e:attributes()) or even something fancy with namespaces
for(Attribute e:attributes("http://example.org)) , and still have a
different iterator for elements, nodes,. etc. You just have to decide
whether the Iterable.iterator() method returns this; or this.clone()

In my iterator classes I tried to be clever , only to find java
generics isnt as powerful as youd think, and makes most of its
decisions at compile time, not run time. More like C++ generics than
Standard ML.

-steve




Archive powered by MHonArc 2.6.24.

Top of Page