Greg Brown <[email protected]> wrote:
This approach allows us to combine collection behaviors without collisions on the Iterable type (for example, org.apache.pivot.xml.Element implements List<Node> and Dictionary<String, String>, which wouldn't compile if Dictionary also implemented Iterable).

I didn't suggest that Dictionary<K,V> should implement Iterable.
I would not be feasible anyway: should it iterate on the keys or the values?

Map<K, V> iterates over keys (since it extends Collection<K>).

Pivot's collections all follow the same pattern:

List<T> : Sequence<T>, Collection<T>
Map<K, V> : Dictionary<K, V>, Collection<K>
Set<E> : Group<E>, Collection<E>

I see. I still fail to see the collision, but I see now that you have a different understanding, or rather a different "vision", of how a collection library should look like. See, my understanding is that (almost) everything is a sequence, with maps being sequences of pairs, and a collection is an enhanced sequence which can be updated. So IMHO it would look like this:

  List<T> extends Sequence<T> extends Iterable<T>, Collection<T>
Map<K, V> extends Dictionary<K, V> extends Sequence<Pair<K,V>>, Collection<K>
  Set<E> extends Group<E> extends Iterable<E>, Collection<E>

But I'm not a library designer, so I should probably keep my mouth shut. I'll stop babbling about it and won't raise this issue again. Thanks, Greg, for your detailed explanations!

It wouldn't make sense to make Sequence iterable

You're the first person I get to know who says that sequences are not iterable. ;-)

Iterating over a list using indices is sooo 90ies. Why can't I simply write:
for (Object row : tableView.getSelectedRows()) {
 ...
}
That's true, but getSelectedRows() is primarily meant to be a convenience method. The primary means of obtaining a table view's selection is getSelectedRanges(). This method returns an instance of ListSelectionSequence, which could (and probably should) implement Iterable.

That's ok, it would help in this case. Note that you need to make getSelectedRanges() return ListSelectionSequence instead of Sequence<Span>. And ListSelectionSequence needs to be public. (And, btw., you are making just one more class, which is implementing Sequence directly (but not List), implement Iterable. ;-)

Please don't forget ListView.getSelectedRanges(), too.
Uh, and TreeView.getSelectedPaths(). And FileBrowser(Sheet).getSelectedFiles().

You might suggest that getSelectedRows() return a List. We don't do this because it might imply that the return value is a "live" collection to which the caller can listen for updates, which is not the case.

So you're saying that any list that is not "live" is a sequence and is not iterable?!? That's odd. (Sorry, can't stop :-)

Regards,
Dirk.



Reply via email to