From 5e0b8f9b5fa27dc7e595c65753a682b12ec3e553 Mon Sep 17 00:00:00 2001 From: "miriam.baglioni" Date: Fri, 20 May 2022 09:15:53 +0200 Subject: [PATCH] [CountryPropagation] refactoring --- .../SparkCountryPropagationJob.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/countrypropagation/SparkCountryPropagationJob.java b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/countrypropagation/SparkCountryPropagationJob.java index 25cd82248..d9f6433a0 100644 --- a/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/countrypropagation/SparkCountryPropagationJob.java +++ b/dhp-workflows/dhp-enrichment/src/main/java/eu/dnetlib/dhp/countrypropagation/SparkCountryPropagationJob.java @@ -102,7 +102,7 @@ public class SparkCountryPropagationJob { private static MapFunction, R> getCountryMergeFn() { return t -> { Optional.ofNullable(t._2()).ifPresent(r -> { - if(Optional.ofNullable(t._1().getCountry()).isPresent()) + if (Optional.ofNullable(t._1().getCountry()).isPresent()) t._1().getCountry().addAll(merge(t._1().getCountry(), r.getCountrySet())); else t._1().setCountry(merge(null, t._2().getCountrySet())); @@ -113,11 +113,12 @@ public class SparkCountryPropagationJob { private static List merge(List c1, List c2) { HashSet countries = new HashSet<>(); - if(Optional.ofNullable(c1).isPresent()){ - countries = c1.stream().map(Qualifier::getClassid) - .collect(Collectors.toCollection(HashSet::new)); - } - + if (Optional.ofNullable(c1).isPresent()) { + countries = c1 + .stream() + .map(Qualifier::getClassid) + .collect(Collectors.toCollection(HashSet::new)); + } HashSet finalCountries = countries; return c2