Turn BuiltinEffectiveStatements into an enum 62/58262/4
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 5 Jun 2017 15:59:04 +0000 (17:59 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 7 Jun 2017 13:44:28 +0000 (13:44 +0000)
This class is effectively is an enum, make that explicit, leading to
less verbose code and smaller overall memory footprint. It also
makes for slightly better debuggability, as we will no longer see
anonymous subclasses.

Change-Id: Ib76bdfb7e22f4b0ffda916febf55fd4bd7027a4f
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/BuiltinEffectiveStatement.java [moved from yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/AbstractBuiltinEffectiveStatement.java with 65% similarity]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BuiltinEffectiveStatements.java [deleted file]

index 992404533e13a5baa4d4ae50b72a86556f09c539..5fdd9bfb516e1ec159c23b8a55269fc91011d195 100644 (file)
@@ -50,7 +50,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.TypeDefEffe
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BooleanTypeEffectiveStatementImpl;
-import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BuiltinEffectiveStatements;
+import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BuiltinEffectiveStatement;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.DecimalTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EmptyTypeEffectiveStatementImpl;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumTypeEffectiveStatementImpl;
@@ -118,43 +118,43 @@ public class TypeStatementImpl extends AbstractDeclaredStatement<String>
             final TypeEffectiveStatement<TypeStatement> typeStmt;
             switch (ctx.getStatementArgument()) {
                 case TypeUtils.BINARY:
-                    typeStmt = BuiltinEffectiveStatements.BINARY;
+                    typeStmt = BuiltinEffectiveStatement.BINARY;
                     break;
                 case TypeUtils.BOOLEAN:
-                    typeStmt = BuiltinEffectiveStatements.BOOLEAN;
+                    typeStmt = BuiltinEffectiveStatement.BOOLEAN;
                     break;
                 case TypeUtils.EMPTY:
-                    typeStmt = BuiltinEffectiveStatements.EMPTY;
+                    typeStmt = BuiltinEffectiveStatement.EMPTY;
                     break;
                 case TypeUtils.INSTANCE_IDENTIFIER:
-                    typeStmt = BuiltinEffectiveStatements.INSTANCE_IDENTIFIER;
+                    typeStmt = BuiltinEffectiveStatement.INSTANCE_IDENTIFIER;
                     break;
             case TypeUtils.INT8:
-                typeStmt = BuiltinEffectiveStatements.INT8;
+                typeStmt = BuiltinEffectiveStatement.INT8;
                 break;
             case TypeUtils.INT16:
-                typeStmt = BuiltinEffectiveStatements.INT16;
+                typeStmt = BuiltinEffectiveStatement.INT16;
                 break;
             case TypeUtils.INT32:
-                typeStmt = BuiltinEffectiveStatements.INT32;
+                typeStmt = BuiltinEffectiveStatement.INT32;
                 break;
             case TypeUtils.INT64:
-                typeStmt = BuiltinEffectiveStatements.INT64;
+                typeStmt = BuiltinEffectiveStatement.INT64;
                 break;
             case TypeUtils.STRING:
-                typeStmt = BuiltinEffectiveStatements.STRING;
+                typeStmt = BuiltinEffectiveStatement.STRING;
                 break;
             case TypeUtils.UINT8:
-                typeStmt = BuiltinEffectiveStatements.UINT8;
+                typeStmt = BuiltinEffectiveStatement.UINT8;
                 break;
             case TypeUtils.UINT16:
-                typeStmt = BuiltinEffectiveStatements.UINT16;
+                typeStmt = BuiltinEffectiveStatement.UINT16;
                 break;
             case TypeUtils.UINT32:
-                typeStmt = BuiltinEffectiveStatements.UINT32;
+                typeStmt = BuiltinEffectiveStatement.UINT32;
                 break;
             case TypeUtils.UINT64:
-                typeStmt = BuiltinEffectiveStatements.UINT64;
+                typeStmt = BuiltinEffectiveStatement.UINT64;
                 break;
             default:
                 final QName qname = Utils.qNameFromArgument(ctx, ctx.getStatementArgument());
@@ -7,10 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import java.util.Collection;
 import java.util.Map;
 import javax.annotation.Nonnull;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace;
@@ -18,8 +20,37 @@ import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 import org.opendaylight.yangtools.yang.model.api.meta.StatementSource;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.TypeStatement;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+
+/**
+ * Common shared effective statements for built-in types.
+ */
+public enum BuiltinEffectiveStatement implements TypeEffectiveStatement<TypeStatement> {
+    BINARY(BaseTypes.binaryType()),
+    BOOLEAN(BaseTypes.booleanType()),
+    EMPTY(BaseTypes.emptyType()),
+    INSTANCE_IDENTIFIER(BaseTypes.instanceIdentifierType()),
+    INT8(BaseTypes.int8Type()),
+    INT16(BaseTypes.int16Type()),
+    INT32(BaseTypes.int32Type()),
+    INT64(BaseTypes.int64Type()),
+    STRING(BaseTypes.stringType()),
+    UINT8(BaseTypes.uint8Type()),
+    UINT16(BaseTypes.uint16Type()),
+    UINT32(BaseTypes.uint32Type()),
+    UINT64(BaseTypes.uint64Type());
+
+    private final TypeDefinition<?> typedef;
+
+    BuiltinEffectiveStatement(final TypeDefinition<?> typedef) {
+        this.typedef = Preconditions.checkNotNull(typedef);
+    }
+
+    @Override
+    public @Nonnull TypeDefinition<?> getTypeDefinition() {
+        return typedef;
+    }
 
-abstract class AbstractBuiltinEffectiveStatement implements TypeEffectiveStatement<TypeStatement> {
     @Override
     public final TypeStatement getDeclared() {
         return null;
diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BuiltinEffectiveStatements.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/BuiltinEffectiveStatements.java
deleted file mode 100644 (file)
index 7105e69..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2015 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,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type;
-
-import javax.annotation.Nonnull;
-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.BinaryTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-
-public final class BuiltinEffectiveStatements {
-    private BuiltinEffectiveStatements() {
-        throw new UnsupportedOperationException();
-    }
-
-    public static final TypeEffectiveStatement<TypeStatement> BINARY = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public BinaryTypeDefinition getTypeDefinition() {
-            return BaseTypes.binaryType();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> BOOLEAN = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public BooleanTypeDefinition getTypeDefinition() {
-            return BaseTypes.booleanType();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> EMPTY = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public EmptyTypeDefinition getTypeDefinition() {
-            return BaseTypes.emptyType();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> INSTANCE_IDENTIFIER = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public InstanceIdentifierTypeDefinition getTypeDefinition() {
-            return BaseTypes.instanceIdentifierType();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> INT8 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public IntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.int8Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> INT16 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public IntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.int16Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> INT32 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public IntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.int32Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> INT64 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public IntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.int64Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> STRING = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public StringTypeDefinition getTypeDefinition() {
-            return BaseTypes.stringType();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> UINT8 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public UnsignedIntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.uint8Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> UINT16 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public UnsignedIntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.uint16Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> UINT32 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public UnsignedIntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.uint32Type();
-        }
-    };
-    public static final TypeEffectiveStatement<TypeStatement> UINT64 = new AbstractBuiltinEffectiveStatement() {
-        @Nonnull
-        @Override
-        public UnsignedIntegerTypeDefinition getTypeDefinition() {
-            return BaseTypes.uint64Type();
-        }
-    };
-}