Seal ItemOrder and MutationBehaviour 03/100503/9
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 9 Apr 2022 19:29:36 +0000 (21:29 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 25 Apr 2022 12:09:16 +0000 (14:09 +0200)
With JDK17 we can properly restrict the class hierarchy of these
interfaces. Also hide MutationBehaviour, as it should not leak.

Change-Id: I0681ef7a0c82abe7aa9dd7adddae69940e57011f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Immutable.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/ItemOrder.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/Mutable.java
common/concepts/src/main/java/org/opendaylight/yangtools/concepts/MutationBehaviour.java

index 1f17aeb6aa977abdf5a55e2993605073475610bf..eb0134777e95b5c6894f4af3e94d464342c4af69 100644 (file)
@@ -32,6 +32,6 @@ package org.opendaylight.yangtools.concepts;
  * @author Robert Varga
  * @author Tony Tkacik
  */
-public interface Immutable extends MutationBehaviour<Immutable> {
-
+public non-sealed interface Immutable extends MutationBehaviour<Immutable> {
+    // Marker interface only
 }
index a840e618ffd1f9517b217db4b3cb614552f1a260..27a8ee8d7264b93b07c350d38095ffda6264e27e 100644 (file)
@@ -23,12 +23,12 @@ import org.eclipse.jdt.annotation.Nullable;
  * @param <T> Item order type
  */
 @Beta
-public interface ItemOrder<T extends ItemOrder<T>> {
+public sealed interface ItemOrder<T extends ItemOrder<T>> {
     /**
      * Items are ordered and their order is significant. A {@link List} is an example of a collection which conforms to
      * this contract.
      */
-    interface Ordered extends ItemOrder<Ordered> {
+    non-sealed interface Ordered extends ItemOrder<Ordered> {
         @Override
         default Class<Ordered> itemOrder() {
             return Ordered.class;
@@ -61,7 +61,7 @@ public interface ItemOrder<T extends ItemOrder<T>> {
      * Items are unordered and their order is insignificant. A {@link Set} is an example of a collection which conforms
      * to this contract.
      */
-    interface Unordered extends ItemOrder<Unordered> {
+    non-sealed interface Unordered extends ItemOrder<Unordered> {
         @Override
         default Class<Unordered> itemOrder() {
             return Unordered.class;
index f6f2893f7222136494c459275fe88da71b9f6f6e..f5ad016c3f22cd0f75418b2d817e7132e137de52 100644 (file)
@@ -13,6 +13,6 @@ package org.opendaylight.yangtools.concepts;
  *
  * @author Tony Tkacik
  */
-public interface Mutable extends MutationBehaviour<Mutable> {
-
+public non-sealed interface Mutable extends MutationBehaviour<Mutable> {
+    // Marker interface only
 }
index 537548d6acf8c726768160d4bd2382f4cbd04d64..40e938e27e03692d9135c474299156245878756e 100644 (file)
@@ -15,8 +15,6 @@ package org.opendaylight.yangtools.concepts;
  *
  * @param <T> Mutation Type
  */
-// FIXME: sealed to allow Mutable and Immutable only when we have JDK17+
-// FIXME: consider hiding this interface afterwards
-public interface MutationBehaviour<T extends MutationBehaviour<T>> {
+sealed interface MutationBehaviour<T extends MutationBehaviour<T>> permits Immutable, Mutable {
     // Marker interface only
 }