Let's say I have a Node class that has a function as an instance variable.
public class Node { private Function<Node, Double> function; ...
I have a list of these nodes:
List<Node> nodes = Lists.newLinkedList(); nodes.add(new Node(someFunction)); nodes.add(new Node(someOtherFunction));
I can do it:
public Collection<Double> getValues() { SomeFunction f = new SomeFunction(); return Collections2.transform(nodes, f); }
Of course, we will iterate over the nodes of the List and apply the function f to each element, for example mapcar.
What I'm trying to do is convert using the function that every Node element has.
So I, even the Supplier, would help.
class NodeSupplier implements Supplier<Node> { Iterator<Node> iterator; NodeSupplier(Iterable p) { iterator = Iterators.cycle(p); } @Override public Node get() { return iterator.next(); } }
Then function to get Node.
class SupplierGetter implements Function<Supplier<Node>, Node> { @Override public Node apply(Supplier<Node> from) { return from.get(); } }
Then compose them:
FunctionGetter fg = new FunctionGetter(); NodeSupplier sup = new NodeSupplier(this);
But then it gives me a type mismatch when I try to use it:
Collections2.transform(nodes, supplier);
he wants suppler.get (), which is called once.
Collections2.transform(nodes, supplier.get());
Is there an easier way?
I saw a mention
Suppliers.supplierFunction()
but does not seem to exist in verison r09.