Consolidate (Unsinged)IntegerTypeEffectiveStatementImpl 55/65055/10
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Nov 2017 17:37:49 +0000 (18:37 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Nov 2017 13:10:35 +0000 (14:10 +0100)
The two classes are the same, hence we can concentrate them into
a single class, called IntegralTypeEffectiveStatementImpl.

Change-Id: I8fd5fb3ebe4feaa7005faeaeb5c8f55a692cd662
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/TypeStatementImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/IntegralTypeEffectiveStatementImpl.java [moved from yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/IntegerTypeEffectiveStatementImpl.java with 51% similarity]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/UnsignedIntegerTypeEffectiveStatementImpl.java [deleted file]

index 71517122fc0c984227c057f992c52fe85835f103..53d5ceeb448fc56169a94c5e3b49cef57dd00123 100644 (file)
@@ -64,11 +64,10 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EmptyT
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityrefTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.InstanceIdentifierTypeEffectiveStatementImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IntegerTypeEffectiveStatementImpl;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IntegralTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.StringTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionTypeEffectiveStatementImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnsignedIntegerTypeEffectiveStatementImpl;
 
 public class TypeStatementImpl extends AbstractDeclaredStatement<String>
         implements TypeStatement {
@@ -199,25 +198,25 @@ public class TypeStatementImpl extends AbstractDeclaredStatement<String>
                 return new InstanceIdentifierTypeEffectiveStatementImpl(ctx,
                     (InstanceIdentifierTypeDefinition) baseType);
             } else if (baseType instanceof Int8TypeDefinition) {
-                return IntegerTypeEffectiveStatementImpl.create(ctx, (Int8TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Int8TypeDefinition) baseType);
             } else if (baseType instanceof Int16TypeDefinition) {
-                return IntegerTypeEffectiveStatementImpl.create(ctx, (Int16TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Int16TypeDefinition) baseType);
             } else if (baseType instanceof Int32TypeDefinition) {
-                return IntegerTypeEffectiveStatementImpl.create(ctx, (Int32TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Int32TypeDefinition) baseType);
             } else if (baseType instanceof Int64TypeDefinition) {
-                return IntegerTypeEffectiveStatementImpl.create(ctx, (Int64TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Int64TypeDefinition) baseType);
             } else if (baseType instanceof LeafrefTypeDefinition) {
                 return new LeafrefTypeEffectiveStatementImpl(ctx, (LeafrefTypeDefinition) baseType);
             } else if (baseType instanceof StringTypeDefinition) {
                 return new StringTypeEffectiveStatementImpl(ctx, (StringTypeDefinition) baseType);
             } else if (baseType instanceof Uint8TypeDefinition) {
-                return UnsignedIntegerTypeEffectiveStatementImpl.create(ctx, (Uint8TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Uint8TypeDefinition) baseType);
             } else if (baseType instanceof Uint16TypeDefinition) {
-                return UnsignedIntegerTypeEffectiveStatementImpl.create(ctx, (Uint16TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Uint16TypeDefinition) baseType);
             } else if (baseType instanceof Uint32TypeDefinition) {
-                return UnsignedIntegerTypeEffectiveStatementImpl.create(ctx, (Uint32TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Uint32TypeDefinition) baseType);
             } else if (baseType instanceof Uint64TypeDefinition) {
-                return UnsignedIntegerTypeEffectiveStatementImpl.create(ctx, (Uint64TypeDefinition) baseType);
+                return IntegralTypeEffectiveStatementImpl.create(ctx, (Uint64TypeDefinition) baseType);
             } else if (baseType instanceof UnionTypeDefinition) {
                 return new UnionTypeEffectiveStatementImpl(ctx, (UnionTypeDefinition) baseType);
             } else {
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -8,6 +8,7 @@
 
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
+import java.math.BigInteger;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
@@ -16,7 +17,11 @@ import org.opendaylight.yangtools.yang.model.api.type.Int16TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int32TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int64TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.Int8TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeRestrictedTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
 import org.opendaylight.yangtools.yang.model.util.type.InvalidRangeConstraintException;
 import org.opendaylight.yangtools.yang.model.util.type.RangeRestrictedTypeBuilder;
 import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
@@ -26,21 +31,21 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
 
-public final class IntegerTypeEffectiveStatementImpl<T extends IntegerTypeDefinition<N, T>,
+public final class IntegralTypeEffectiveStatementImpl<T extends RangeRestrictedTypeDefinition<T, N>,
         N extends Number & Comparable<N>> extends DeclaredEffectiveStatementBase<String, TypeStatement>
         implements TypeEffectiveStatement<TypeStatement> {
 
     private final T typeDefinition;
 
-    private IntegerTypeEffectiveStatementImpl(
+    private IntegralTypeEffectiveStatementImpl(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final RangeRestrictedTypeBuilder<T, N> builder) {
         super(ctx);
 
         for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
             if (stmt instanceof RangeEffectiveStatementImpl) {
-                final RangeEffectiveStatementImpl range = (RangeEffectiveStatementImpl) stmt;
-                builder.setRangeConstraint(range, range.argument());
+                final RangeEffectiveStatementImpl rangeStmt = (RangeEffectiveStatementImpl)stmt;
+                builder.setRangeConstraint(rangeStmt, rangeStmt.argument());
             }
             if (stmt instanceof UnknownEffectiveStatementImpl) {
                 builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
@@ -55,31 +60,59 @@ public final class IntegerTypeEffectiveStatementImpl<T extends IntegerTypeDefini
         }
     }
 
-    public static IntegerTypeEffectiveStatementImpl<Int8TypeDefinition, Byte> create(
+    public static IntegralTypeEffectiveStatementImpl<Int8TypeDefinition, Byte> create(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final Int8TypeDefinition baseType) {
-        return new IntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt8Builder(baseType,
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt8Builder(baseType,
             TypeUtils.typeEffectiveSchemaPath(ctx)));
     }
 
-    public static IntegerTypeEffectiveStatementImpl<Int16TypeDefinition, Short> create(
+    public static IntegralTypeEffectiveStatementImpl<Int16TypeDefinition, Short> create(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final Int16TypeDefinition baseType) {
-        return new IntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt16Builder(baseType,
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt16Builder(baseType,
             TypeUtils.typeEffectiveSchemaPath(ctx)));
     }
 
-    public static IntegerTypeEffectiveStatementImpl<Int32TypeDefinition, Integer> create(
+    public static IntegralTypeEffectiveStatementImpl<Int32TypeDefinition, Integer> create(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final Int32TypeDefinition baseType) {
-        return new IntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt32Builder(baseType,
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt32Builder(baseType,
             TypeUtils.typeEffectiveSchemaPath(ctx)));
     }
 
-    public static IntegerTypeEffectiveStatementImpl<Int64TypeDefinition, Long> create(
+    public static IntegralTypeEffectiveStatementImpl<Int64TypeDefinition, Long> create(
             final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
             final Int64TypeDefinition baseType) {
-        return new IntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt64Builder(baseType,
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newInt64Builder(baseType,
+            TypeUtils.typeEffectiveSchemaPath(ctx)));
+    }
+
+    public static IntegralTypeEffectiveStatementImpl<Uint8TypeDefinition, Short> create(
+            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
+            final Uint8TypeDefinition baseType) {
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint8Builder(baseType,
+            TypeUtils.typeEffectiveSchemaPath(ctx)));
+    }
+
+    public static IntegralTypeEffectiveStatementImpl<Uint16TypeDefinition, Integer> create(
+            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
+            final Uint16TypeDefinition baseType) {
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint16Builder(baseType,
+            TypeUtils.typeEffectiveSchemaPath(ctx)));
+    }
+
+    public static IntegralTypeEffectiveStatementImpl<Uint32TypeDefinition, Long> create(
+            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
+            final Uint32TypeDefinition baseType) {
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint32Builder(baseType,
+            TypeUtils.typeEffectiveSchemaPath(ctx)));
+    }
+
+    public static IntegralTypeEffectiveStatementImpl<Uint64TypeDefinition, BigInteger> create(
+            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
+            final Uint64TypeDefinition baseType) {
+        return new IntegralTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint64Builder(baseType,
             TypeUtils.typeEffectiveSchemaPath(ctx)));
     }
 
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/UnsignedIntegerTypeEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/UnsignedIntegerTypeEffectiveStatementImpl.java
deleted file mode 100644 (file)
index c17ebb1..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
-
-import java.math.BigInteger;
-import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
-import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
-import org.opendaylight.yangtools.yang.model.api.type.Uint16TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.Uint32TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.Uint64TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.Uint8TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.type.RangeRestrictedTypeBuilder;
-import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.TypeUtils;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.UnknownEffectiveStatementImpl;
-
-public final class UnsignedIntegerTypeEffectiveStatementImpl<T extends UnsignedIntegerTypeDefinition<N, T>,
-        N extends Number & Comparable<N>> extends DeclaredEffectiveStatementBase<String, TypeStatement>
-        implements TypeEffectiveStatement<TypeStatement> {
-
-    private final T typeDefinition;
-
-    private UnsignedIntegerTypeEffectiveStatementImpl(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final RangeRestrictedTypeBuilder<T, N> builder) {
-        super(ctx);
-
-        for (EffectiveStatement<?, ?> stmt : effectiveSubstatements()) {
-            if (stmt instanceof RangeEffectiveStatementImpl) {
-                final RangeEffectiveStatementImpl rangeStmt = (RangeEffectiveStatementImpl)stmt;
-                builder.setRangeConstraint(rangeStmt, rangeStmt.argument());
-            }
-            if (stmt instanceof UnknownEffectiveStatementImpl) {
-                builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt);
-            }
-        }
-
-        typeDefinition = builder.build();
-    }
-
-    public static UnsignedIntegerTypeEffectiveStatementImpl<Uint8TypeDefinition, Short> create(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final Uint8TypeDefinition baseType) {
-        return new UnsignedIntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint8Builder(baseType,
-            TypeUtils.typeEffectiveSchemaPath(ctx)));
-    }
-
-    public static UnsignedIntegerTypeEffectiveStatementImpl<Uint16TypeDefinition, Integer> create(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final Uint16TypeDefinition baseType) {
-        return new UnsignedIntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint16Builder(baseType,
-            TypeUtils.typeEffectiveSchemaPath(ctx)));
-    }
-
-    public static UnsignedIntegerTypeEffectiveStatementImpl<Uint32TypeDefinition, Long> create(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final Uint32TypeDefinition baseType) {
-        return new UnsignedIntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint32Builder(baseType,
-            TypeUtils.typeEffectiveSchemaPath(ctx)));
-    }
-
-    public static UnsignedIntegerTypeEffectiveStatementImpl<Uint64TypeDefinition, BigInteger> create(
-            final StmtContext<String, TypeStatement, EffectiveStatement<String, TypeStatement>> ctx,
-            final Uint64TypeDefinition baseType) {
-        return new UnsignedIntegerTypeEffectiveStatementImpl<>(ctx, RestrictedTypes.newUint64Builder(baseType,
-            TypeUtils.typeEffectiveSchemaPath(ctx)));
-    }
-
-    @Nonnull
-    @Override
-    public T getTypeDefinition() {
-        return typeDefinition;
-    }
-}