diff --git a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/Bar.java b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/Bar.java index b9d0b28..2d8f4d5 100644 --- a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/Bar.java +++ b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/Bar.java @@ -1,19 +1,74 @@ package org.incenp.linkml.core.samples.refinhslot; -/** - * An example of a class that is used in a “refined” slot. - *
- * This class is used in the {@link Foo} class. Some of the classes that are
- * derived from Foo uses derived classes instead.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/Bar")
public class Bar {
+
+ @LinkURI("https://w3id.org/linkml/tests/refined_derived_slots/name")
private String name;
+ public void setName(String name) {
+ this.name = name;
+ }
+
public String getName() {
- return name;
+ return this.name;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ Object o;
+ sb.append("Bar(");
+ if ( (o = this.getName()) != null ) {
+ sb.append("name=");
+ 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 Bar) ) return false;
+ final Bar other = (Bar) o;
+ if ( !other.canEqual((Object) this)) return false;
+ final Object this$name = this.getName();
+ final Object other$name = other.getName();
+ if ( this$name == null ? other$name != null : !this$name.equals(other$name)) return false;
+ return true;
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof Bar;
}
- public void setName(String value) {
- name = value;
+ @Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = 1;
+ final Object $name = this.getName();
+ result = result * PRIME + ($name == null ? 43 : $name.hashCode());
+ return result;
}
-}
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedBar.java b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedBar.java
index efe9acb..ada1f58 100644
--- a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedBar.java
+++ b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedBar.java
@@ -1,20 +1,81 @@
package org.incenp.linkml.core.samples.refinhslot;
-/**
- * First derived class from Bar.
- *
- * This class is used, instead of its parent
- * This class is used, instead of its parent Bar in
- * {@link FirstDerivedFoo}.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/FirstDerivedBar")
public class FirstDerivedBar extends Bar {
- private int length;
+ @LinkURI("https://w3id.org/linkml/tests/refined_derived_slots/length")
+ private Integer length;
+
+ public void setLength(Integer length) {
+ this.length = length;
+ }
+
+ public Integer getLength() {
+ return this.length;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ Object o;
+ sb.append("FirstDerivedBar(");
+ if ( (o = this.getLength()) != null ) {
+ sb.append("length=");
+ sb.append(o);
+ sb.append(",");
+ }
+ if ( (o = this.getName()) != null ) {
+ sb.append("name=");
+ 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 FirstDerivedBar) ) return false;
+ final FirstDerivedBar other = (FirstDerivedBar) 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;
+ }
- public int getLength() {
- return length;
+ protected boolean canEqual(final Object other) {
+ return other instanceof FirstDerivedBar;
}
- public void setLength(int value) {
- length = value;
+ @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;
}
-}
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedFoo.java b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedFoo.java
index 8f1c450..8f403cf 100644
--- a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedFoo.java
+++ b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/FirstDerivedFoo.java
@@ -1,33 +1,36 @@
package org.incenp.linkml.core.samples.refinhslot;
+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;
-/**
- * An example of a class that refines the range of its slots to make them accept
- * only a more specialised subclass.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/FirstDerivedFoo")
public class FirstDerivedFoo extends Foo {
- /*
- * Overridden read accessor for the `bar` slot.
- *
- * We override it to ensure that it returns the more specialised subtype.
- */
@Override
public FirstDerivedBar getBar() {
- // This cast is perfectly safe because the write accessor below guarantees that
- // only a FirstDerivedBar object can be assigned to the slot.
return (FirstDerivedBar) super.getBar();
}
- /*
- * Overridden write accessor for the `bar` slot.
- *
- * We override it to add a runtime check to enforce the more specialised type
- * constraint. We cannot prevent client code from trying to assign an object of
- * the wrong type, but if that happens we can at least immediately throw an
- * exception.
- */
+ public void setBar(FirstDerivedBar value) {
+ super.setBar(value);
+ }
+
@Override
public void setBar(Bar value) {
if ( !(value instanceof FirstDerivedBar) ) {
@@ -36,54 +39,17 @@ public void setBar(Bar value) {
super.setBar(value);
}
- /*
- * Overloaded write accessor for the `bar` slot.
- *
- * This accessor is not strictly necessary, but it makes it clearer that in this
- * class, the value of the `bar` slot should be a `FirstDerivedBar`. It also
- * allows to bypass the dynamic check in the normal accessor above, if the
- * compiler already knows that the assigned value is a FirstDerivedBar.
- */
- public void setBar(FirstDerivedBar value) {
- super.setBar(value);
- }
-
- /*
- * Overridden “Standard” read accessor.
- *
- * We override it to ensure it returns the more specialised subtype.
- *
- * Because the slot could be (and instead is, in this example) refined further
- * in subclasses, we must still return a generic wildcard, so this accessor has
- * the same limitation as the one it overrides in the `Foo` class: modifying the
- * returned list requires an explicit cast into a non-wildcard form.
- */
@Override
@SuppressWarnings("unchecked")
public List extends FirstDerivedBar> getBars() {
- // This cast should be safe IFF nobody explicitly modify the value returned by
- // this accessor after casting it into a `ListFirstDerivedBar, in
- * {@link ThirdDerivedFoo}.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/SecondDerivedBar")
public class SecondDerivedBar extends FirstDerivedBar {
-}
+ @LinkURI("https://w3id.org/linkml/tests/refined_derived_slots/width")
+ private Integer width;
+
+ public void setWidth(Integer width) {
+ this.width = width;
+ }
+
+ public Integer getWidth() {
+ return this.width;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ Object o;
+ sb.append("SecondDerivedBar(");
+ if ( (o = this.getWidth()) != null ) {
+ sb.append("width=");
+ sb.append(o);
+ sb.append(",");
+ }
+ if ( (o = this.getLength()) != null ) {
+ sb.append("length=");
+ sb.append(o);
+ sb.append(",");
+ }
+ if ( (o = this.getName()) != null ) {
+ sb.append("name=");
+ 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 SecondDerivedBar) ) return false;
+ final SecondDerivedBar other = (SecondDerivedBar) o;
+ if ( !other.canEqual((Object) this)) return false;
+ if ( !super.equals(o) ) return false;
+
+ final Object this$width = this.getWidth();
+ final Object other$width = other.getWidth();
+ if ( this$width == null ? other$width != null : !this$width.equals(other$width)) return false;
+ return true;
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof SecondDerivedBar;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = super.hashCode();
+ final Object $width = this.getWidth();
+ result = result * PRIME + ($width == null ? 43 : $width.hashCode());
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/SecondDerivedFoo.java b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/SecondDerivedFoo.java
index 6ab2a54..67266b0 100644
--- a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/SecondDerivedFoo.java
+++ b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/SecondDerivedFoo.java
@@ -1,13 +1,65 @@
package org.incenp.linkml.core.samples.refinhslot;
-/**
- * An example of a class that inherits from a class that refines its slots, but
- * that does no do any refinement itself.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/SecondDerivedFoo")
public class SecondDerivedFoo extends FirstDerivedFoo {
- /*
- * In this class, the `bar` and `bars` slot are of the same type as in the
- * parental `FirstDerivedFoo` class, so no overriding of accessors is necessary.
- */
-}
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ Object o;
+ sb.append("SecondDerivedFoo(");
+ if ( (o = this.getBar()) != null ) {
+ sb.append("bar=");
+ sb.append(o);
+ sb.append(",");
+ }
+ if ( (o = this.getBars()) != null ) {
+ sb.append("bars=");
+ 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 SecondDerivedFoo) ) return false;
+ final SecondDerivedFoo other = (SecondDerivedFoo) o;
+ if ( !other.canEqual((Object) this)) return false;
+ if ( !super.equals(o) ) return false;
+
+ return true;
+ }
+
+ protected boolean canEqual(final Object other) {
+ return other instanceof SecondDerivedFoo;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 59;
+ int result = super.hashCode();
+ return result;
+ }
+}
\ No newline at end of file
diff --git a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/ThirdDerivedFoo.java b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/ThirdDerivedFoo.java
index e06104a..89c3f52 100644
--- a/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/ThirdDerivedFoo.java
+++ b/core/src/test/java/org/incenp/linkml/core/samples/refinhslot/ThirdDerivedFoo.java
@@ -1,48 +1,36 @@
package org.incenp.linkml.core.samples.refinhslot;
+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;
-/**
- * An example of a class that refines the range of its slots, that it inherited
- * from a class that already refined them.
- *
- * Importantly, this class has no derived class, so we know its slots cannot be
- * further refined by another class.
- */
+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://w3id.org/linkml/tests/refined_derived_slots/ThirdDerivedFoo")
public class ThirdDerivedFoo extends SecondDerivedFoo {
- /*
- * Overridden read accessor for the `bar` slot.
- *
- * We override it to ensure that it returns the more specialised subtype.
- */
@Override
public SecondDerivedBar getBar() {
return (SecondDerivedBar) super.getBar();
}
- /*
- * Overridden write accessor for the `bar` slot.
- *
- * We override it to add a runtime check to enforce the more specialised type
- * constraint. We cannot prevent client code from trying to assign an object of
- * the wrong type, but if that happens we can at least immediately throw an
- * exception.
- */
- @Override
- public void setBar(Bar value) {
- if ( !(value instanceof SecondDerivedBar) ) {
- throw new IllegalArgumentException("Invalid bar value");
- }
+ public void setBar(SecondDerivedBar value) {
super.setBar(value);
}
- /*
- * Second overridden write accessor for the `bar` slot.
- *
- * Since `FirstDerivedFoo` defined this accessor, we must override it as well,
- * otherwise it would allow client code to assign a FirstDerivedBar to the slot.
- */
@Override
public void setBar(FirstDerivedBar value) {
if ( !(value instanceof SecondDerivedBar) ) {
@@ -51,52 +39,25 @@ public void setBar(FirstDerivedBar value) {
super.setBar(value);
}
- /*
- * Overloaded write accessor for the `bar` slot.
- *
- * This accessor is not strictly necessary, but it makes it clearer that in this
- * class, the value of the `bar` slot should be a `SecondDerivedBar`. It also
- * allows to bypass the dynamic check in the normal accessor above, if the
- * compiler already knows that the assigned value is a FirstDerivedBar.
- */
- public void setBar(SecondDerivedBar value) {
+ @Override
+ public void setBar(Bar value) {
+ if ( !(value instanceof SecondDerivedBar) ) {
+ throw new IllegalArgumentException("Invalid bar value");
+ }
super.setBar(value);
}
- /*
- * Overridden “standard” read accessor.
- *
- * We override it to ensure it returns the more specialised subtype.
- *
- * Here, since we know the slot cannot be further refined (no subclass), we can
- * dispense with a wildcard generic.
- */
@Override
@SuppressWarnings("unchecked")
public List