TimurMahammadov / google-collections

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

add Objects.pick(T ... o) #80

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
similiar with Objects.firstNonNull(T o1, T o2), but can input more elements.

the name pick is from jQuery, I think it's short and meanful. perhaps you
can deprecate firstNonNull, and rename to pick :)

Thanks!

Jiming

Original issue reported on code.google.com by jiming...@gmail.com on 12 Jun 2008 at 12:23

GoogleCodeExporter commented 9 years ago
If the suggested method has the same functionality as firstNonNull, it should 
have
the same name:

public static <T> T firstNonNull(@Nullable T first, @Nullable T second, T... 
others)

The question is whether that method would be used often enough to justify 
adding it
to the library.

Original comment by jared.l....@gmail.com on 12 Jun 2008 at 4:27

GoogleCodeExporter commented 9 years ago
There's two separate issues here.

One is whether "pick" or "firstNonNull" is the better name for this/these 
methods. 
Personally, I like "pick", and would be okay with us changing that.

The second is whether to support varargs.  In truth, we are undergoing an 
exercise to
try to BANISH varargs from our API as much as we can.  They're great in theory, 
but
in practice they're a near-disaster.  I don't think there would be enough 
demand for
this method you describe anyway; if there is, we could address 80% of that 
demand by
adding a three-arg overload and leave it at that.

It's too bad about varargs.

Original comment by kevin...@gmail.com on 12 Jun 2008 at 4:36

GoogleCodeExporter commented 9 years ago
Our consensus is that the name "firstNonNull" makes up for its verbosity by 
being
clear and self-explanatory, while "pick" is slightly vulnerable to confusion. 
Combined with my earlier statements about varargs, I'm considering this issue a
won't-fix.

Thanks for your feedback; it is appreciated.

Original comment by kevin...@gmail.com on 12 Jun 2008 at 6:16

GoogleCodeExporter commented 9 years ago
Thanks for your quick reply!

About the name I agree with you.

However, saying varargs, I myself think this is a nice feature. I beliee a lot 
of
other guys would have same opnion with me. Could you please give some hint, 
such as a
url or description or examples, on it? I think it worth to be put in FAQ as 
well.

Thanks

Jiming 

Original comment by jiming...@gmail.com on 13 Jun 2008 at 4:48