Closed GoogleCodeExporter closed 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
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
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
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
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
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
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
Original comment by kevin...@gmail.com
on 17 Sep 2009 at 5:45
Original comment by kevin...@gmail.com
on 17 Sep 2009 at 5:57
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
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
Original issue reported on code.google.com by
leonidos
on 3 Sep 2009 at 7:31