static <T> T assertAtMostOne(T[] arr) {
		if (arr.length == 0) {
			return null;
		}
		if (arr.length == 1) {
			return arr[0];
		}
		throw new AssertionError("Expected at most one. Got many: " + List.of(arr));
	}
Some utilities for when singleton collections are expected
Ghidra/Framework/Emulation/src/main/java/generic/Unique.java