allalizaki / guava-libraries

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

ImmutableCollection.asList() #229

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 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 9 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 9 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 9 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 9 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 9 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 9 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 9 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 9 years ago

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

GoogleCodeExporter commented 9 years ago

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

GoogleCodeExporter commented 9 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 9 years ago
Added in r02, removed from beta in r03.

Original comment by kevinb@google.com on 9 Apr 2010 at 5:39

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 9 Dec 2010 at 6:19

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:16

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10