public static <S extends Subject> S findSubject(List<S> items, URI ref) { if (items == null || ref == null) { return null; } String value = ref.toString(); String id = value.startsWith("#") ? value.substring(1) : null; for (S subject : items) { if (id != null && id.equals(subject.getId())) { return subject; } if (subject.getIdentifiers() != null) { for (Identifier identifier : subject.getIdentifiers()) { if (ref.equals(identifier.getValue())) { return subject; } } } } return null; }