From d90704f1bb3df509d30dca3a341c6c465ee56432 Mon Sep 17 00:00:00 2001 From: Sandro La Bruzzo Date: Fri, 14 Jan 2022 10:06:49 +0100 Subject: [PATCH] updated method, using java.lang.Pair instead of scala tuple2 --- .../java/eu/dnetlib/dhp/schema/oaf/Result.java | 16 ++++++++++------ .../eu/dnetlib/dhp/schema/oaf/MergeTest.java | 5 ++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java b/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java index 9ede797..9d1f52c 100644 --- a/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java +++ b/src/main/java/eu/dnetlib/dhp/schema/oaf/Result.java @@ -5,10 +5,12 @@ import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; + import eu.dnetlib.dhp.schema.common.AccessRightComparator; import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions; -import scala.Tuple2; /** * The type Result. @@ -571,19 +573,21 @@ public class Result extends OafEntity implements Serializable { * @return the result map */ public static Map toInstanceMap(final List ri) { + + return ri .stream() .filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null) .flatMap(i -> { - final List> result = new ArrayList<>(); + final List> result = new ArrayList<>(); if (i.getPid() != null) - i.getPid().stream().filter(Result::validPid).forEach(p -> result.add(new Tuple2<>(extractKeyFromPid(p), i))); + i.getPid().stream().filter(Result::validPid).forEach(p -> result.add(new ImmutablePair<>(extractKeyFromPid(p), i))); if (i.getAlternateIdentifier() != null) - i.getAlternateIdentifier().stream().filter(Result::validPid).forEach(p -> result.add(new Tuple2<>(extractKeyFromPid(p), i))); + i.getAlternateIdentifier().stream().filter(Result::validPid).forEach(p -> result.add(new ImmutablePair<>(extractKeyFromPid(p), i))); return result.stream(); }).collect(Collectors.toMap( - Tuple2::_1, - Tuple2::_2, + Pair::getLeft, + Pair::getRight, (a, b) -> a )); } diff --git a/src/test/java/eu/dnetlib/dhp/schema/oaf/MergeTest.java b/src/test/java/eu/dnetlib/dhp/schema/oaf/MergeTest.java index 6e335e0..69af8e3 100644 --- a/src/test/java/eu/dnetlib/dhp/schema/oaf/MergeTest.java +++ b/src/test/java/eu/dnetlib/dhp/schema/oaf/MergeTest.java @@ -3,7 +3,6 @@ package eu.dnetlib.dhp.schema.oaf; import static org.junit.jupiter.api.Assertions.*; - import java.io.IOException; import java.io.InputStream; import java.time.format.DateTimeParseException; @@ -12,12 +11,12 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; - -import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * The type Merge test. */