Iterating through a stream to use that object in a method call
I have a method where a Set is used and I'm changing this so that it instead uses a Stream. In the current method, it looks like this:
public void deleteEdgesByClient(String clientId) {
Set<Edge> clientEdges = edgeDAO.getEdgesForClient(clientId, true, false);
for (Edge edge : clientEdges) {
disableEdgeForClient(edge, clientId);
}}
Where there is a Set made of objects called Edges and for each edge in this set it performs the disableEdgeForClient method where the current edge that it is iterating through is a parameter of this method. Now though, clientEdges is a Stream and so I cant perform this same for loop. I know that an Iterator won't work because the parameter should be an Edge and not an Iterator<Edge> but now I'm trying to use forEach() on the Stream to solve my problem. Currently what I have is this:
public void deleteEdgesByClient(String clientId) {
Stream<Edge> clientEdges = edgeDAO.getEdgesForClient(clientId, true, false);
clientEdges.forEach(disableEdgeForClient(<The current edge>, clientId));
}
So my issue is that I'm not sure how to make this work because in the first one, it was calling each Edge in the Set an edge so I could use that as the parameter but now what can I put in that parameter field to say "preform this on the current edge in the stream"?
If you have any other ideas on how to make this method work by other means then please let me know but one thing that must remain true is that this must be a Stream. Thanks!
Posted Jun 16, 2017, 7:13 PM UTC · edited