ca.appsimulations.models.model.application.CallResolver Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of models Show documentation
Show all versions of models Show documentation
Application and cloud models
The newest version!
package ca.appsimulations.models.model.application;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static java.util.stream.Collectors.toList;
@Data
@NoArgsConstructor
@Accessors(chain = true, fluent = true)
public class CallResolver {
private Map> callsToMap = new HashMap<>();
private Map> calledByMap = new HashMap<>();
public void calls(String name, Call call) {
addCallToMap(name, call, callsToMap);
}
public void calledBy(String name, Call call) {
addCallToMap(name, call, calledByMap);
}
private void addCallToMap(String name,
Call call,
Map> callsMap) {
List calls;
if (callsMap.containsKey(name)) {
calls = callsMap.get(name);
}
else {
calls = new ArrayList<>();
}
calls.add(call);
callsMap.put(name,
calls);
}
public List calledBy() {
return calledByMap.values().stream().flatMap(calls -> calls.stream())
.collect(toList());
}
public List callsTo() {
return callsToMap.values().stream().flatMap(calls -> calls.stream())
.collect(toList());
}
}