State () { synchronized (myStatus) { // remove default entries myStatus.entrySet().removeIf(entry -> entry.getValue().status == Status.ACTIVE && entry.getValue().error == null); if (myStatus.isEmpty()) { return new State(Collections.emptyList()); } Entry[] entries = myStatus.values().toArray(new Entry[0]); Arrays.sort(entries); return new State(Arrays.asList(entries)); } }