Skip to content

Commit

Permalink
Feat: Improve error message when some Perception IDs are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
McModknower committed Jul 16, 2024
1 parent 2581f98 commit 888cadf
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,23 @@ private static void checkForIncompleteIds(List<OwlRecord> 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<Integer> 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<OwlRecord> records) {
Expand Down

0 comments on commit 888cadf

Please sign in to comment.