yangxu998 / guava-libraries

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

Add `Lists.get(List<T>, Iterable<Integer>)` #641

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I propose a helper method to select elements from a list by specifying their 
indexes.

This is handy when only indexes are available as input while the actual data 
they refer to is hold by the application. A very common case is a Web 
application that only transfers the indexes of a selection, be it a rich UI's 
component or a simple HTML select form field.

Possible implementation:

  public static <T> Iterable<T> get(final List<T> elements, Iterable<Integer> indexes) {
    return Iterables.transform(indexes, new Function<Integer, T>() {
      @Override
      public T apply(Integer index) {
        return elements.get(index);
      }
    });
  }

Original issue reported on code.google.com by j...@nwsnet.de on 6 Jun 2011 at 2:46

GoogleCodeExporter commented 9 years ago
Please review issue 557 and add more info if you think it's missing. It could 
be reopened but right now it doesn't seem compelling.

Original comment by kevinb@google.com on 13 Jul 2011 at 6:50

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:15

GoogleCodeExporter commented 9 years ago

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