Lazy non-modifiable list in Google Collections

Posted by mindas on Stack Overflow See other posts from Stack Overflow or by mindas
Published on 2010-04-22T21:07:45Z Indexed on 2010/04/22 21:33 UTC
Read the original article Hit count: 395

I was looking for a decent implementation of a generic lazy non-modifiable list implementation to wrap my search result entries. The unmodifiable part of the task is easy as it can be achieved by Collections.unmodifiableList() so I only need to sort out the the lazy part.

Surprisingly, google-collections doesn't have anything to offer; while LazyList from Apache Commons Collections does not support generics.

I have found an attempt to build something on top of google-collections but it seems to be incomplete (e.g. does not support size()), outdated (does not compile with 1.0 final) and requiring some external classes, but could be used as a good starting point to build my own class.

Is anybody aware of any good implementation of a LazyList? If not, which option do you think is better:

  • write my own implementation, based on google-collections ForwardingList, similar to what Peter Maas did;
  • write my own wrapper around Commons Collections LazyList (the wrapper would only add generics so I don't have to cast everywhere but only in the wrapper itself);
  • just write something on top of java.util.AbstractList;

Any other suggestions are welcome.

© Stack Overflow or respective owner

Related posts about java

Related posts about google-collections