In our project, we use proxies-based database API (Tinkerpop Frames), so we have a lot of loops like:
List<Link> links = new LinkedList<>();
for (LinkModel model : obj.getLinks())
{
Link l = new Link(model.getLink(), model.getDescription());
links.add(l);
}
I would like to get rid of these for two reasons:
- To remove boilerplate code
- For larger lists, memory issues may arise.
Is there a nice way to get an Iterable
that takes from the other one and converts using given method? What I would like to do is:
Iterable<Link> links_ = new IterableConverter<LinkModel, Link>(obj.getLinks()){
public Link from(LinkModel m){ return new Link(m.getLink(), m.getDescription()); }
};
I guess there's something like that in Java 8. I need this for Java 7.