TimurMahammadov / google-collections

Automatically exported from code.google.com/p/google-collections
Apache License 2.0
0 stars 0 forks source link

Method like Constraints.constrainedList which applies to existing elements #40

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The List returned by Constraints.constrainedList still allows 
unconstrained access to elements using List.get().

I would love a method like constrainedList which applies to the existing 
elements of the source list so that get can be used on the list.
I couldn't find this functionality in the library (which is really useful 
for me, btw).

I attached a quick hack which shows what I mean. This solution is not 
implementing a view of the source list. Of course, there are probably 
better solutions. But I couldn't think of a good one right now :)

Original issue reported on code.google.com by wallaby....@googlemail.com on 25 Nov 2007 at 8:09

Attachments:

GoogleCodeExporter commented 9 years ago
You're right that constrainedList() is only interested in constraining what 
goes in
to the list.

In your case, are you sure you really want to wait until the moment of each 
read to
validate the element?  Wouldn't you rather check everything up front once 
before you
stick it into the constrained list at all?

If you really do want that, you could use Lists.transform() with a function 
that does
your checking and then returns its input...

Original comment by kevin...@gmail.com on 29 Nov 2007 at 1:17

GoogleCodeExporter commented 9 years ago
Closing this, in the absence of further compelling arguments.

Original comment by kevin...@gmail.com on 30 Jan 2008 at 5:03