From 8a809a60e29bc6f8f13c3416ba60018eac2e56af Mon Sep 17 00:00:00 2001 From: Claudio Atzori Date: Mon, 6 Dec 2021 10:45:23 +0100 Subject: [PATCH] Added helper method to lookup for inverse relations regardless of the upper/lower case in the relation encoding --- .../dnetlib/dhp/schema/common/ModelSupport.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java b/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java index 8639d55..1aa0d8f 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java +++ b/src/main/java/eu/dnetlib/dhp/schema/common/ModelSupport.java @@ -158,6 +158,21 @@ public class ModelSupport { } } + /** + * Helper method: lookup relation inverse, given the direct relation encoding (case insensitive) + * @param encoding + * @return the relation inverse descriptor, throws @IllegalArgumentException when not found. + */ + public static RelationInverse findInverse(String encoding) { + return ModelSupport.relationInverseMap + .entrySet() + .stream() + .filter(r -> encoding.equalsIgnoreCase(r.getKey())) + .findFirst() + .map(r -> r.getValue()) + .orElseThrow(() -> new IllegalArgumentException("invalid relationship: " + encoding)); + } + /** * Helper method: fina a relation filtering by a relation name * @param relationName