Remove useless UnsupportedOperationException throws
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / type / CompatUtils.java
index 552fc93b383c8df5bd45b003e459f3a560b5f93c..455fa059b5702955a0f05f18c0b7900a7263f6e6 100644 (file)
@@ -7,11 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.model.util.type;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
+
 import java.util.List;
 import java.util.Optional;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypedDataSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
@@ -42,7 +43,7 @@ import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
 @Deprecated
 public final class CompatUtils {
     private CompatUtils() {
-        throw new UnsupportedOperationException();
+        // Hidden on purpose
     }
 
     /**
@@ -119,9 +120,8 @@ public final class CompatUtils {
      * @param leaf Leaf for which we are acquiring the type
      * @return Potentially base type of the leaf type.
      */
-    @Nonnull public static TypeDefinition<?> compatType(@Nonnull final TypedDataSchemaNode leaf) {
-        final TypeDefinition<?> leafType = leaf.getType();
-        Preconditions.checkNotNull(leafType);
+    public static @NonNull TypeDefinition<?> compatType(final @NonNull TypedDataSchemaNode leaf) {
+        final TypeDefinition<?> leafType = requireNonNull(leaf.getType());
 
         if (!leaf.getPath().equals(leafType.getPath())) {
             // Old parser semantics, or no new default/units defined for this leaf
@@ -130,7 +130,7 @@ public final class CompatUtils {
 
         // We are dealing with a type generated for the leaf itself
         final TypeDefinition<?> baseType = leafType.getBaseType();
-        Preconditions.checkArgument(baseType != null, "Leaf %s has type for leaf, but no base type", leaf);
+        checkArgument(baseType != null, "Leaf %s has type for leaf, but no base type", leaf);
 
         if (leaf.getPath().equals(baseType.getPath().getParent())) {
             // Internal instantiation of a base YANG type (decimal64 and similar)
@@ -169,54 +169,49 @@ public final class CompatUtils {
         }
     }
 
-    // FIXME: 3.0.0: remove this method
-    @Nonnull public static TypeDefinition<?> compatLeafType(@Nonnull final LeafSchemaNode leaf) {
-        return compatType(leaf);
-    }
-
-    private static BinaryTypeDefinition baseTypeIfNotConstrained(final BinaryTypeDefinition type) {
+    private static BinaryTypeDefinition baseTypeIfNotConstrained(final @NonNull BinaryTypeDefinition type) {
         return baseTypeIfNotConstrained(type, type.getBaseType());
     }
 
-    private static TypeDefinition<?> baseTypeIfNotConstrained(final DecimalTypeDefinition type) {
+    private static TypeDefinition<?> baseTypeIfNotConstrained(final @NonNull DecimalTypeDefinition type) {
         return baseTypeIfNotConstrained(type, type.getBaseType());
     }
 
-    private static TypeDefinition<?> baseTypeIfNotConstrained(final InstanceIdentifierTypeDefinition type) {
+    private static TypeDefinition<?> baseTypeIfNotConstrained(final @NonNull InstanceIdentifierTypeDefinition type) {
         final InstanceIdentifierTypeDefinition base = type.getBaseType();
         return type.requireInstance() == base.requireInstance() ? base : type;
     }
 
-    private static TypeDefinition<?> baseTypeIfNotConstrained(final StringTypeDefinition type) {
+    private static TypeDefinition<?> baseTypeIfNotConstrained(final @NonNull StringTypeDefinition type) {
         final StringTypeDefinition base = type.getBaseType();
         final List<PatternConstraint> patterns = type.getPatternConstraints();
         final Optional<LengthConstraint> optLengths = type.getLengthConstraint();
 
         if ((patterns.isEmpty() || patterns.equals(base.getPatternConstraints()))
-                && (!optLengths.isPresent() || optLengths.equals(base.getLengthConstraint()))) {
+                && (optLengths.isEmpty() || optLengths.equals(base.getLengthConstraint()))) {
             return base;
         }
 
         return type;
     }
 
-    private static <T extends RangeRestrictedTypeDefinition<T, ?>> T baseTypeIfNotConstrained(final T type) {
+    private static <T extends RangeRestrictedTypeDefinition<T, ?>> T baseTypeIfNotConstrained(final @NonNull T type) {
         return baseTypeIfNotConstrained(type, type.getBaseType());
     }
 
-    private static <T extends RangeRestrictedTypeDefinition<T, ?>> T baseTypeIfNotConstrained(final T type,
+    private static <T extends RangeRestrictedTypeDefinition<T, ?>> T baseTypeIfNotConstrained(final @NonNull T type,
             final T base) {
         final Optional<?> optConstraint = type.getRangeConstraint();
-        if (!optConstraint.isPresent()) {
+        if (optConstraint.isEmpty()) {
             return base;
         }
         return optConstraint.equals(base.getRangeConstraint()) ? base : type;
     }
 
-    private static <T extends LengthRestrictedTypeDefinition<T>> T baseTypeIfNotConstrained(final T type,
+    private static <T extends LengthRestrictedTypeDefinition<T>> T baseTypeIfNotConstrained(final @NonNull T type,
             final T base) {
         final Optional<LengthConstraint> optConstraint = type.getLengthConstraint();
-        if (!optConstraint.isPresent()) {
+        if (optConstraint.isEmpty()) {
             return base;
         }
         return optConstraint.equals(base.getLengthConstraint()) ? base : type;