ACMNexus / google-collections

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

ImmutableCollection.asList() #229

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
ImmutableSortedSet holds items in a predicatble order in an array, so can 
quickly provide its items by index.

So, it's a good idea to implement List<E> in ImmutableSortedSet<E>.

The usage is to provide ISS as a List in legacy open API. Currently, I have 
to copy set's items to a list each time when I asked items by open API, or to 
hold two collections of items - one in ISS to use them iternally and one in 
IL - to return them by open API calls.

Original issue reported on code.google.com by leonidos on 3 Sep 2009 at 7:31

GoogleCodeExporter commented 8 years ago
It can't implement List (incompatible equals() specifications, for one thing).  
An
asList() method has been suggested before, but we could also simply make
ImmutableList.copyOf(ImmutableSet) do the smart thing.  (I think.)  Then we 
don't
need any API expansion.

Original comment by kevin...@gmail.com on 3 Sep 2009 at 7:52

GoogleCodeExporter commented 8 years ago
Will ImmutableList.copyOf(ImmutableSet) do a real copy of all items? 

May be a better approach is to make the ImmutableSortedSet.AsList() instance 
function, 
that returns a view of this set (instead of copy all items).

The AsList() will be meaningfull for ordered set only (because non-ordered sets 
may 
have unpredictable order of items).

Original comment by leonidos on 3 Sep 2009 at 8:11

GoogleCodeExporter commented 8 years ago
No, "the smart thing" means to share the array directly, somewhat similar to the
smarts of ImmutableList.copyOf(ImmutableList).

Original comment by kevin...@gmail.com on 3 Sep 2009 at 8:23

GoogleCodeExporter commented 8 years ago
Hmm, this smart behaviour can be unnoticed for a user... may be to name this 
function a 
bit more clear - ImmutableList.viewOf(ImmutableSortedSet), and describe this 
behaviour 
explicitly?

Original comment by leonidos on 3 Sep 2009 at 8:27

GoogleCodeExporter commented 8 years ago
All of the current ImmutableCollections implementations have a well-defined 
ordering.
For example, the ImmutableSet builder and factory methods create instances that
follow the insertion ordering.

I'd prefer an ImmutableCollection.asList() method, so it's clear that the data 
isn't
being copied unnecessarily.

Original comment by jared.l....@gmail.com on 3 Sep 2009 at 8:28

GoogleCodeExporter commented 8 years ago
ImmutableCollection.asList() sounds okay, and it sounds like a method that 
should be 
safe to add post-1.0, am I wrong?

Original comment by kev...@google.com on 10 Sep 2009 at 5:08

GoogleCodeExporter commented 8 years ago
Add asList() for all ImmutableCollections, returning ImmutableList.

Possible alternate idea is to only make sure that ImmutableList.copyOf() always 
does 
the smart thing, however that idea is not favored because it's considered 
surprising.

Original comment by kevin...@gmail.com on 17 Sep 2009 at 4:54

GoogleCodeExporter commented 8 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 5:45

GoogleCodeExporter commented 8 years ago

Original comment by kevin...@gmail.com on 17 Sep 2009 at 5:57

GoogleCodeExporter commented 8 years ago
Using ImmutableCollection.asList() sounds more clear than using 
ImmutableList.copyOf() 
- in the second case one can attempt to avoid copyOf thinking that "copy" 
really makes 
a copy.

Original comment by leonidos on 23 Sep 2009 at 2:08

GoogleCodeExporter commented 8 years ago
This issue has been moved to the Guava project (keeping the same id number). 
Simply replace 'google-collections' with 'guava-libraries' in your address 
bar and it should take you there.

Original comment by kevinb@google.com on 5 Jan 2010 at 11:09