MatchResult (@NotNull JsonSchemaTreeNode root) { List<JsonSchemaObject> schemas = new ArrayList<>(); Int2ObjectMap<List<JsonSchemaObject>> oneOfGroups = new Int2ObjectOpenHashMap<>(); iterateTree(root, node -> { if (node.isAny()) return true; int groupNumber = node.getExcludingGroupNumber(); if (groupNumber < 0) { schemas.add(node.getSchema()); } else { oneOfGroups.computeIfAbsent(groupNumber, __ -> new ArrayList<>()).add(node.getSchema()); } return true; }); List<Collection<? extends JsonSchemaObject>> result; if (oneOfGroups.isEmpty()) { result = Collections.emptyList(); } else { result = new ArrayList<>(oneOfGroups.values()); } return new MatchResult(schemas, result); }