Seal util classes 43/102043/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Aug 2022 20:21:28 +0000 (22:21 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 16 Aug 2022 19:02:37 +0000 (21:02 +0200)
Most of our utility classes can be safely sealed, make sure we do that.

Change-Id: Iea937912d2a586f13963141727f29f97b004958c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableMapTemplate.java
common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/ImmutableOffsetMapTemplate.java
common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMap.java
common/util/src/main/java/org/opendaylight/yangtools/util/SharedSingletonMapTemplate.java

index 62d41551d5576eb5380119fbcba56eef3f128e09..fb74c31244dee1b79b9ac1ac54ffa0f67991eb27 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.util;
 
 import static com.google.common.base.Preconditions.checkArgument;
 
-import com.google.common.annotations.Beta;
 import java.util.Collection;
 import java.util.Map;
 import java.util.Set;
@@ -29,8 +28,8 @@ import org.opendaylight.yangtools.concepts.Immutable;
  *
  * @param <K> the type of keys maintained by this template
  */
-@Beta
-public abstract class ImmutableMapTemplate<K> implements Immutable {
+public abstract sealed class ImmutableMapTemplate<K> implements Immutable
+        permits ImmutableOffsetMapTemplate, SharedSingletonMapTemplate {
     ImmutableMapTemplate() {
         // Hidden on purpose
     }
index 5c3a3235e2f271abd75dc51dd5ef3fa42c53bd57..2043465a5e2d32e5509261367e9ce7432899ddaf 100644 (file)
@@ -45,7 +45,7 @@ import org.eclipse.jdt.annotation.Nullable;
  * @param <V> the type of mapped values
  */
 @Beta
-public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K, V>, Serializable {
+public abstract sealed class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K, V>, Serializable {
     static final class Ordered<K, V> extends ImmutableOffsetMap<K, V> {
         @Serial
         private static final long serialVersionUID = 1L;
@@ -102,7 +102,7 @@ public abstract class ImmutableOffsetMap<K, V> implements UnmodifiableMapPhase<K
      * @param objects Array of value object, may not be null. The array is stored as is, the caller
      *              is responsible for ensuring its contents remain unmodified.
      */
-    ImmutableOffsetMap(final ImmutableMap<K, Integer> offsets, final V[] objects) {
+    private ImmutableOffsetMap(final ImmutableMap<K, Integer> offsets, final V[] objects) {
         this.offsets = requireNonNull(offsets);
         this.objects = requireNonNull(objects);
         checkArgument(offsets.size() == objects.length);
index c171a82f7e62e5650a0bef8cc258809876c919d6..438c38aaa62ea84a22ad6273d24c7e981e3d7092 100644 (file)
@@ -30,7 +30,7 @@ import org.eclipse.jdt.annotation.NonNull;
  *
  * @param <K> the type of keys maintained by this template
  */
-public abstract class ImmutableOffsetMapTemplate<K> extends ImmutableMapTemplate<K> {
+public abstract sealed class ImmutableOffsetMapTemplate<K> extends ImmutableMapTemplate<K> {
     private static final class Ordered<K> extends ImmutableOffsetMapTemplate<K> {
         Ordered(final Collection<K> keys) {
             super(OffsetMapCache.orderedOffsets(keys));
@@ -55,7 +55,7 @@ public abstract class ImmutableOffsetMapTemplate<K> extends ImmutableMapTemplate
 
     private final @NonNull ImmutableMap<K, Integer> offsets;
 
-    ImmutableOffsetMapTemplate(final ImmutableMap<K, Integer> offsets) {
+    private ImmutableOffsetMapTemplate(final ImmutableMap<K, Integer> offsets) {
         this.offsets = requireNonNull(offsets);
     }
 
index b1a6ee836b9e63272b2aa72209239bc541160bd3..58e65893bcc1282ed9fee5af480eadedc76c8451 100644 (file)
@@ -33,7 +33,7 @@ import org.eclipse.jdt.annotation.NonNull;
  * @param <V> the type of mapped values
  */
 @Beta
-public abstract class SharedSingletonMap<K, V> implements Serializable, UnmodifiableMapPhase<K, V> {
+public abstract sealed class SharedSingletonMap<K, V> implements Serializable, UnmodifiableMapPhase<K, V> {
     static final class Ordered<K, V> extends SharedSingletonMap<K, V> {
         @Serial
         private static final long serialVersionUID = 1L;
@@ -84,12 +84,12 @@ public abstract class SharedSingletonMap<K, V> implements Serializable, Unmodifi
     private final @NonNull V value;
     private int hashCode;
 
-    SharedSingletonMap(final SingletonSet<K> keySet, final V value) {
+    private SharedSingletonMap(final SingletonSet<K> keySet, final V value) {
         this.keySet = requireNonNull(keySet);
         this.value = requireNonNull(value);
     }
 
-    SharedSingletonMap(final K key, final V value) {
+    private SharedSingletonMap(final K key, final V value) {
         this(cachedSet(key), value);
     }
 
index 97f3115295f81e94fe8267d70145d555de341f58..dd12b65264ec25a82878f5a7d692bd445b8fef1b 100644 (file)
@@ -23,7 +23,7 @@ import org.eclipse.jdt.annotation.NonNull;
  *
  * @param <K> the type of keys maintained by this template
  */
-public abstract class SharedSingletonMapTemplate<K> extends ImmutableMapTemplate<K> {
+public abstract sealed class SharedSingletonMapTemplate<K> extends ImmutableMapTemplate<K> {
     private static final class Ordered<K> extends SharedSingletonMapTemplate<K> {
         Ordered(final K key) {
             super(key);
@@ -48,7 +48,7 @@ public abstract class SharedSingletonMapTemplate<K> extends ImmutableMapTemplate
 
     private final @NonNull SingletonSet<K> keySet;
 
-    SharedSingletonMapTemplate(final K key) {
+    private SharedSingletonMapTemplate(final K key) {
         this.keySet = SharedSingletonMap.cachedSet(key);
     }