@Test public void testGetCodeOfFirstElement() throws Exception { Icinga2Result result = new Icinga2Result(); Map<String, String> map = new HashMap<>(); map.put("code", "200.00"); result.setResults(Collections.singletonList(map)); assertEquals(result.getCodeOfFirstElement().get().intValue(), 200); result.setResults(null); assertFalse(result.getCodeOfFirstElement().isPresent()); map.put("code", null); result.setResults(Collections.singletonList(map)); assertFalse(result.getCodeOfFirstElement().isPresent()); assertEquals(result.getFirstElementAsString(), "[NULL] - EMPTY MESSAGE"); result.setResults(Collections.singletonList(new HashMap<>())); assertFalse(result.getCodeOfFirstElement().isPresent()); }
public Optional<Integer> getCodeOfFirstElement() { if (results != null) { return results.stream() .filter(Objects::nonNull) .findFirst() .map(e -> e.get("code")) .map(s -> Integer.valueOf(StringUtils.substringBefore(s, "."))); } return Optional.empty(); }
Icinga2Result { public Optional<Integer> getCodeOfFirstElement() { if (results != null) { return results.stream() .filter(Objects::nonNull) .findFirst() .map(e -> e.get("code")) .map(s -> Integer.valueOf(StringUtils.substringBefore(s, "."))); } return Optional.empty(); } }
Icinga2Result { public Optional<Integer> getCodeOfFirstElement() { if (results != null) { return results.stream() .filter(Objects::nonNull) .findFirst() .map(e -> e.get("code")) .map(s -> Integer.valueOf(StringUtils.substringBefore(s, "."))); } return Optional.empty(); }  }
Icinga2Result { public Optional<Integer> getCodeOfFirstElement() { if (results != null) { return results.stream() .filter(Objects::nonNull) .findFirst() .map(e -> e.get("code")) .map(s -> Integer.valueOf(StringUtils.substringBefore(s, "."))); } return Optional.empty(); }  List<Map<String, String>> getResults(); void setResults(List<Map<String, String>> results); Optional<String> getStatusOfFirstElement(); Optional<Integer> getCodeOfFirstElement(); boolean isSuccess(); String getFirstElementAsString(); }
Icinga2Result { public Optional<Integer> getCodeOfFirstElement() { if (results != null) { return results.stream() .filter(Objects::nonNull) .findFirst() .map(e -> e.get("code")) .map(s -> Integer.valueOf(StringUtils.substringBefore(s, "."))); } return Optional.empty(); }  List<Map<String, String>> getResults(); void setResults(List<Map<String, String>> results); Optional<String> getStatusOfFirstElement(); Optional<Integer> getCodeOfFirstElement(); boolean isSuccess(); String getFirstElementAsString();  }