updated method, using java.lang.Pair instead of scala tuple2

This commit is contained in:
Sandro La Bruzzo 2022-01-14 10:06:49 +01:00
parent 3838658535
commit d90704f1bb
2 changed files with 12 additions and 9 deletions

View File

@ -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<String, Instance> toInstanceMap(final List<Instance> ri) {
return ri
.stream()
.filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null)
.flatMap(i -> {
final List<Tuple2<String, Instance>> result = new ArrayList<>();
final List<Pair<String, Instance>> 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
));
}

View File

@ -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.
*/