diff --git a/src/main/java/com/malte3d/suturo/knowledge/owl2anything/output/PerceptionClassesFilter.java b/src/main/java/com/malte3d/suturo/knowledge/owl2anything/output/PerceptionClassesFilter.java index 869eef4..56d07db 100644 --- a/src/main/java/com/malte3d/suturo/knowledge/owl2anything/output/PerceptionClassesFilter.java +++ b/src/main/java/com/malte3d/suturo/knowledge/owl2anything/output/PerceptionClassesFilter.java @@ -79,13 +79,23 @@ private static void checkForIncompleteIds(List records) { if (!incompleteRecords.isEmpty()) throw new IllegalStateException("Classes without Id found: " + generateRecordsList(incompleteRecords)); - boolean isSortedAndContinuous = records.stream() - .mapToInt(OwlRecord::getPerceptionId) - .reduce((int a, int b) -> b == (a + 1) ? b : Integer.MIN_VALUE) - .orElse(Integer.MIN_VALUE) != Integer.MIN_VALUE; - if (!isSortedAndContinuous) - throw new IllegalStateException("Ids are not continuously increasing: " + generateRecordsList(records)); + List missingIds = new ArrayList<>(); + int nextExpectedId = 0; + + for (PrimitiveIterator.OfInt it = records.stream() + .mapToInt(OwlRecord::getPerceptionId).iterator(); it.hasNext(); ) { + int id = it.next(); + if (id > nextExpectedId) { + for (int i = nextExpectedId; i < id; i++) { + missingIds.add(i); + } + } + nextExpectedId = id+1; + } + + if(!missingIds.isEmpty()) + throw new IllegalStateException("Perception Ids are not continuous, missing Id(s): " + missingIds); } private static void checkForDuplicates(List records) {