updated method, using java.lang.Pair instead of scala tuple2
This commit is contained in:
parent
3838658535
commit
d90704f1bb
|
@ -5,10 +5,12 @@ import java.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
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.AccessRightComparator;
|
||||||
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
import eu.dnetlib.dhp.schema.common.ModelConstants;
|
||||||
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
|
import eu.dnetlib.dhp.schema.oaf.utils.CleaningFunctions;
|
||||||
import scala.Tuple2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Result.
|
* The type Result.
|
||||||
|
@ -571,19 +573,21 @@ public class Result extends OafEntity implements Serializable {
|
||||||
* @return the result map
|
* @return the result map
|
||||||
*/
|
*/
|
||||||
public static Map<String, Instance> toInstanceMap(final List<Instance> ri) {
|
public static Map<String, Instance> toInstanceMap(final List<Instance> ri) {
|
||||||
|
|
||||||
|
|
||||||
return ri
|
return ri
|
||||||
.stream()
|
.stream()
|
||||||
.filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null)
|
.filter(i -> i.getPid() != null || i.getAlternateIdentifier() != null)
|
||||||
.flatMap(i -> {
|
.flatMap(i -> {
|
||||||
final List<Tuple2<String, Instance>> result = new ArrayList<>();
|
final List<Pair<String, Instance>> result = new ArrayList<>();
|
||||||
if (i.getPid() != null)
|
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)
|
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();
|
return result.stream();
|
||||||
}).collect(Collectors.toMap(
|
}).collect(Collectors.toMap(
|
||||||
Tuple2::_1,
|
Pair::getLeft,
|
||||||
Tuple2::_2,
|
Pair::getRight,
|
||||||
(a, b) -> a
|
(a, b) -> a
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package eu.dnetlib.dhp.schema.oaf;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.time.format.DateTimeParseException;
|
import java.time.format.DateTimeParseException;
|
||||||
|
@ -12,12 +11,12 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type Merge test.
|
* The type Merge test.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue