Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions core/src/test/java/org/incenp/linkml/core/ObjectConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -56,17 +57,20 @@
import org.incenp.linkml.core.samples.base.ContainerOfIRIIdentifiableObjects;
import org.incenp.linkml.core.samples.base.ContainerOfInlinedObjects;
import org.incenp.linkml.core.samples.base.ContainerOfIntegerValues;
import org.incenp.linkml.core.samples.base.ContainerOfKeyedSelfDesignatedObjects;
import org.incenp.linkml.core.samples.base.ContainerOfReferences;
import org.incenp.linkml.core.samples.base.ContainerOfSelfDesignatedObjects;
import org.incenp.linkml.core.samples.base.ContainerOfSimpleDicts;
import org.incenp.linkml.core.samples.base.ContainerOfSimpleObjects;
import org.incenp.linkml.core.samples.base.DerivedCurieSelfDesignatedClass;
import org.incenp.linkml.core.samples.base.DerivedKeyedSelfDesignatedClass;
import org.incenp.linkml.core.samples.base.DerivedMultiSelfDesignatedClass;
import org.incenp.linkml.core.samples.base.DerivedSelfDesignatedClass;
import org.incenp.linkml.core.samples.base.DerivedURISelfDesignatedClass;
import org.incenp.linkml.core.samples.base.ExtensibleSimpleClass;
import org.incenp.linkml.core.samples.base.ExtraSimpleDict;
import org.incenp.linkml.core.samples.base.IRISimpleIdentifiableClass;
import org.incenp.linkml.core.samples.base.KeyedSelfDesignatedClass;
import org.incenp.linkml.core.samples.base.MultivaluedSimpleDict;
import org.incenp.linkml.core.samples.base.SampleEnum;
import org.incenp.linkml.core.samples.base.SecondDerivedSelfDesignatedClass;
Expand Down Expand Up @@ -515,6 +519,26 @@ void testMultiLevelTypeDesignators() throws IOException {
roundtrip(cosdo);
}

@Test
void testKeyTypeDesignator() throws IOException {
ContainerOfKeyedSelfDesignatedObjects cksdo = parse("container-of-keyed-self-designated-objects.yaml",
ContainerOfKeyedSelfDesignatedObjects.class);

HashMap<String, KeyedSelfDesignatedClass> d = new HashMap<>();
for ( KeyedSelfDesignatedClass o : cksdo.getObjects() ) {
d.put(o.getType(), o);
}
KeyedSelfDesignatedClass ksdc = d.get("KeyedSelfDesignatedClass");
Assertions.assertNotNull(ksdc);
Assertions.assertEquals("Alice", ksdc.getFrobnicator());

ksdc = d.get("DerivedKeyedSelfDesignatedClass");
Assertions.assertNotNull(ksdc);
Assertions.assertEquals("Bob", ksdc.getFrobnicator());
Assertions.assertInstanceOf(DerivedKeyedSelfDesignatedClass.class, ksdc);
Assertions.assertEquals(123, ((DerivedKeyedSelfDesignatedClass) ksdc).getLength());
}

@Test
void testReferenceToIRIIdentifiers() throws IOException, LinkMLRuntimeException {
ctx.addPrefix("PFX", "https://example.org/");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.incenp.linkml.core.samples.base;

import java.net.URI;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.incenp.linkml.core.annotations.Converter;
import org.incenp.linkml.core.annotations.ExtensionHolder;
import org.incenp.linkml.core.annotations.Identifier;
import org.incenp.linkml.core.annotations.Inlined;
import org.incenp.linkml.core.annotations.LinkURI;
import org.incenp.linkml.core.annotations.Required;
import org.incenp.linkml.core.annotations.SlotName;
import org.incenp.linkml.core.annotations.TypeDesignator;
import org.incenp.linkml.core.CurieConverter;

@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#ContainerOfKeyedSelfDesignatedObjects")
public class ContainerOfKeyedSelfDesignatedObjects {

@Inlined
@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#objects")
private List<KeyedSelfDesignatedClass> objects;

public void setObjects(List<KeyedSelfDesignatedClass> objects) {
this.objects = objects;
}

public List<KeyedSelfDesignatedClass> getObjects() {
return this.objects;
}

public List<KeyedSelfDesignatedClass> getObjects(boolean set) {
if ( this.objects == null && set ) {
this.objects = new ArrayList<>();
}
return this.objects;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Object o;
sb.append("ContainerOfKeyedSelfDesignatedObjects(");
if ( (o = this.getObjects()) != null ) {
sb.append("objects=");
sb.append(o);
sb.append(",");
}
sb.append(")");
return sb.toString();
}

@Override
public boolean equals(final Object o) {
if ( o == this ) return true;
if ( !(o instanceof ContainerOfKeyedSelfDesignatedObjects) ) return false;
final ContainerOfKeyedSelfDesignatedObjects other = (ContainerOfKeyedSelfDesignatedObjects) o;
if ( !other.canEqual((Object) this)) return false;
final Object this$objects = this.getObjects();
final Object other$objects = other.getObjects();
if ( this$objects == null ? other$objects != null : !this$objects.equals(other$objects)) return false;
return true;
}

protected boolean canEqual(final Object other) {
return other instanceof ContainerOfKeyedSelfDesignatedObjects;
}

@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $objects = this.getObjects();
result = result * PRIME + ($objects == null ? 43 : $objects.hashCode());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.incenp.linkml.core.samples.base;

import java.net.URI;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.incenp.linkml.core.annotations.Converter;
import org.incenp.linkml.core.annotations.ExtensionHolder;
import org.incenp.linkml.core.annotations.Identifier;
import org.incenp.linkml.core.annotations.Inlined;
import org.incenp.linkml.core.annotations.LinkURI;
import org.incenp.linkml.core.annotations.Required;
import org.incenp.linkml.core.annotations.SlotName;
import org.incenp.linkml.core.annotations.TypeDesignator;
import org.incenp.linkml.core.CurieConverter;

@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#DerivedKeyedSelfDesignatedClass")
public class DerivedKeyedSelfDesignatedClass extends KeyedSelfDesignatedClass {

@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#length")
private Integer length;

public void setLength(Integer length) {
this.length = length;
}

public Integer getLength() {
return this.length;
}

@Override
public String toString() {
return "DerivedKeyedSelfDesignatedClass(type=" + this.getType() + ")";
}

@Override
public boolean equals(final Object o) {
if ( o == this ) return true;
if ( !(o instanceof DerivedKeyedSelfDesignatedClass) ) return false;
final DerivedKeyedSelfDesignatedClass other = (DerivedKeyedSelfDesignatedClass) o;
if ( !other.canEqual((Object) this)) return false;
if ( !super.equals(o) ) return false;

final Object this$length = this.getLength();
final Object other$length = other.getLength();
if ( this$length == null ? other$length != null : !this$length.equals(other$length)) return false;
return true;
}

protected boolean canEqual(final Object other) {
return other instanceof DerivedKeyedSelfDesignatedClass;
}

@Override
public int hashCode() {
final int PRIME = 59;
int result = super.hashCode();
final Object $length = this.getLength();
result = result * PRIME + ($length == null ? 43 : $length.hashCode());
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package org.incenp.linkml.core.samples.base;

import java.net.URI;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.incenp.linkml.core.annotations.Converter;
import org.incenp.linkml.core.annotations.ExtensionHolder;
import org.incenp.linkml.core.annotations.Identifier;
import org.incenp.linkml.core.annotations.Inlined;
import org.incenp.linkml.core.annotations.LinkURI;
import org.incenp.linkml.core.annotations.Required;
import org.incenp.linkml.core.annotations.SlotName;
import org.incenp.linkml.core.annotations.TypeDesignator;
import org.incenp.linkml.core.CurieConverter;

@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#KeyedSelfDesignatedClass")
public class KeyedSelfDesignatedClass {

@Identifier(isGlobal = false)
@TypeDesignator
@Required
@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#type")
private String type;

@LinkURI("https://incenp.org/dvlpt/linkml-java/tests/samples#frobnicator")
private String frobnicator;

public void setType(String type) {
this.type = type;
}

public String getType() {
return this.type;
}

public void setFrobnicator(String frobnicator) {
this.frobnicator = frobnicator;
}

public String getFrobnicator() {
return this.frobnicator;
}

@Override
public String toString() {
return "KeyedSelfDesignatedClass(type=" + this.getType() + ")";
}

@Override
public boolean equals(final Object o) {
if ( o == this ) return true;
if ( !(o instanceof KeyedSelfDesignatedClass) ) return false;
final KeyedSelfDesignatedClass other = (KeyedSelfDesignatedClass) o;
if ( !other.canEqual((Object) this)) return false;
final Object this$type = this.getType();
final Object other$type = other.getType();
if ( this$type == null ? other$type != null : !this$type.equals(other$type)) return false;
final Object this$frobnicator = this.getFrobnicator();
final Object other$frobnicator = other.getFrobnicator();
if ( this$frobnicator == null ? other$frobnicator != null : !this$frobnicator.equals(other$frobnicator)) return false;
return true;
}

protected boolean canEqual(final Object other) {
return other instanceof KeyedSelfDesignatedClass;
}

@Override
public int hashCode() {
final int PRIME = 59;
int result = 1;
final Object $type = this.getType();
result = result * PRIME + ($type == null ? 43 : $type.hashCode());
final Object $frobnicator = this.getFrobnicator();
result = result * PRIME + ($frobnicator == null ? 43 : $frobnicator.hashCode());
return result;
}
}
29 changes: 29 additions & 0 deletions core/src/test/linkml/samples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,35 @@ classes:
range: Anything
multivalued: true

KeyedSelfDesignatedClass:
description: >-
A class with a slot that is both a type designator and a key slot.
attributes:
type:
designates_type: true
key: true
frobnicator:

DerivedKeyedSelfDesignatedClass:
description: >-
A class that derives from a class with a slot that is both a type
designator and a key slot.
is_a: KeyedSelfDesignatedClass
attributes:
length:
range: integer

ContainerOfKeyedSelfDesignatedObjects:
description: >-
A class with a slot whose range is set to a class with a slot that is
both a key slot and and a type designator slot.
attributes:
objects:
range: KeyedSelfDesignatedClass
multivalued: true
inlined: true
inlined_as_list: false


enums:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
objects:
DerivedKeyedSelfDesignatedClass:
frobnicator: Bob
length: 123
KeyedSelfDesignatedClass:
frobnicator: Alice
Loading