1
0
Fork 0

avoid NPEs

This commit is contained in:
Claudio Atzori 2024-06-11 12:40:50 +02:00
parent 46018dc804
commit 71927ca818
1 changed files with 16 additions and 14 deletions

View File

@ -1,13 +1,9 @@
package eu.dnetlib.dhp.schema.oaf.utils; package eu.dnetlib.dhp.schema.oaf.utils;
import static eu.dnetlib.dhp.schema.common.ModelConstants.CROSSREF_ID;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
import eu.dnetlib.dhp.schema.common.ModelConstants; import eu.dnetlib.dhp.schema.common.ModelConstants;
import eu.dnetlib.dhp.schema.oaf.KeyValue;
import eu.dnetlib.dhp.schema.oaf.Oaf; import eu.dnetlib.dhp.schema.oaf.Oaf;
import eu.dnetlib.dhp.schema.oaf.OafEntity; import eu.dnetlib.dhp.schema.oaf.OafEntity;
import eu.dnetlib.dhp.schema.oaf.Result; import eu.dnetlib.dhp.schema.oaf.Result;
@ -42,17 +38,23 @@ public class MergeEntitiesComparator implements Comparator<Oaf> {
int res = 0; int res = 0;
// pid authority // pid authority
int cfp1 = left int cfp1 = Optional
.getCollectedfrom() .ofNullable(left.getCollectedfrom())
.stream() .map(
.map(kv -> PID_AUTHORITIES.indexOf(kv.getKey())) cf -> cf
.max(Integer::compare) .stream()
.map(kv -> PID_AUTHORITIES.indexOf(kv.getKey()))
.max(Integer::compare)
.orElse(-1))
.orElse(-1); .orElse(-1);
int cfp2 = right int cfp2 = Optional
.getCollectedfrom() .ofNullable(right.getCollectedfrom())
.stream() .map(
.map(kv -> PID_AUTHORITIES.indexOf(kv.getKey())) cf -> cf
.max(Integer::compare) .stream()
.map(kv -> PID_AUTHORITIES.indexOf(kv.getKey()))
.max(Integer::compare)
.orElse(-1))
.orElse(-1); .orElse(-1);
if (cfp1 >= 0 && cfp1 > cfp2) { if (cfp1 >= 0 && cfp1 > cfp2) {