Graph model footprint optimisation #23

Open
claudio.atzori wants to merge 16 commits from ticket_8369 into master
2 changed files with 22 additions and 4 deletions
Showing only changes of commit 3e0159dcd4 - Show all commits

View File

@ -3,9 +3,7 @@ package eu.dnetlib.dhp.schema.oaf;
import java.beans.Transient; import java.beans.Transient;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.*;
import java.util.List;
import java.util.Objects;
/** /**
* Relation models any edge between two nodes in the OpenAIRE graph. It has a source id and a target id pointing to * Relation models any edge between two nodes in the OpenAIRE graph. It has a source id and a target id pointing to
@ -179,6 +177,18 @@ public class Relation extends Oaf implements Serializable {
throw new IllegalArgumentException("missing SubRel mapping for" + this); throw new IllegalArgumentException("missing SubRel mapping for" + this);
} }
/**
* This mehtod is an implementation of the valueOF case insensitive
* @param value the input Value
* @return the RELCLASS
*/
public static RELCLASS lookUp(String value) {
Optional<RELCLASS> rvlaue = Arrays.stream(RELCLASS.values()).filter(e -> e.name().equalsIgnoreCase(value)).findAny();
if (rvlaue.isPresent())
return rvlaue.get();
throw new IllegalArgumentException("value: "+value+" not found");
}
@Transient @Transient
public RELCLASS getInverse() { public RELCLASS getInverse() {
switch (this) { switch (this) {

View File

@ -2,6 +2,7 @@ package eu.dnetlib.dhp.schema.oaf;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class RelationTest { public class RelationTest {
@ -13,7 +14,7 @@ public class RelationTest {
} }
@Test @Test
public void checSubRelType() { public void checkSubRelType() {
Relation.RELCLASS rc = Relation.RELCLASS.merges; Relation.RELCLASS rc = Relation.RELCLASS.merges;
assertEquals(Relation.SUBRELTYPE.dedup, rc.getSubRel()); assertEquals(Relation.SUBRELTYPE.dedup, rc.getSubRel());
@ -23,4 +24,11 @@ public class RelationTest {
} }
} }
@Test
public void lookRelClassUpTest() {
Assertions.assertEquals(Relation.RELCLASS.Compiles, Relation.RELCLASS.lookUp("compiles"));
Assertions.assertEquals(Relation.RELCLASS.IsMetadataFor, Relation.RELCLASS.lookUp("isMetaDATAFOr"));
Assertions.assertThrows(IllegalArgumentException.class, () -> Relation.RELCLASS.lookUp("hello"));
}
} }