Skip to content

Instantly share code, notes, and snippets.

@kirshiyin89
Created August 24, 2020 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirshiyin89/866397e58900d87a51082cf11c3640a7 to your computer and use it in GitHub Desktop.
Save kirshiyin89/866397e58900d87a51082cf11c3640a7 to your computer and use it in GitHub Desktop.
The DataService.java processing the server info and mapping it to the final result.
public List<ServerInfo> getServerInfo() {
List<ServerInfo> result = new ArrayList<>();
Map<String, String> serverData = getServerData();
for (Map.Entry<String, String> info : serverData.entrySet()) {
result.add(new ServerInfo(info.getKey(), map(info.getValue())));
}
return result;
}
private static List<ServiceInfo> map(String data) {
List<ServiceInfo> result = new ArrayList<>();
if (!data.isEmpty() && !data.startsWith("error")) {
String[] split = data.split(",");
for (String service : split) {
String[] status = service.split(":");
Boolean b = false;
if (Integer.valueOf(status[1])>0) {
b = true;
}
result.add(new ServiceInfo(status[0], b));
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment