Initial opendaylight infrastructure commit!!
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / main / java / org / opendaylight / controller / sal / binding / generator / impl / ConstantBuilderImpl.java
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/ConstantBuilderImpl.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/ConstantBuilderImpl.java
new file mode 100644 (file)
index 0000000..cb2fc87
--- /dev/null
@@ -0,0 +1,189 @@
+/*\r
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
+ *\r
+ * This program and the accompanying materials are made available under the\r
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
+ * and is available at http://www.eclipse.org/legal/epl-v10.html\r
+ */\r
+package org.opendaylight.controller.sal.binding.generator.impl;\r
+\r
+import org.opendaylight.controller.sal.binding.model.api.Constant;\r
+import org.opendaylight.controller.sal.binding.model.api.Type;\r
+import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;\r
+\r
+final class ConstantBuilderImpl implements ConstantBuilder {\r
+\r
+    private final Type type;\r
+    private final String name;\r
+    private Object value;\r
+\r
+    public ConstantBuilderImpl(Type type, String name, Object value) {\r
+        super();\r
+        this.type = type;\r
+        this.name = name;\r
+        this.value = value;\r
+    }\r
+\r
+    public ConstantBuilderImpl(Type type, String name) {\r
+        super();\r
+        this.type = type;\r
+        this.name = name;\r
+    }\r
+\r
+    @Override\r
+    public void assignValue(Object value) {\r
+        this.value = value;\r
+    }\r
+\r
+    @Override\r
+    public Constant toInstance(final Type definingType) {\r
+        return new ConstantImpl(definingType, type, name, value);\r
+    }\r
+\r
+    private static final class ConstantImpl implements Constant {\r
+\r
+        final Type definingType;\r
+        private final Type type;\r
+        private final String name;\r
+        private final Object value;\r
+\r
+        public ConstantImpl(final Type definingType, final Type type,\r
+                final String name, final Object value) {\r
+            super();\r
+            this.definingType = definingType;\r
+            this.type = type;\r
+            this.name = name;\r
+            this.value = value;\r
+        }\r
+\r
+        @Override\r
+        public Type getDefiningType() {\r
+            return definingType;\r
+        }\r
+\r
+        @Override\r
+        public Type getType() {\r
+            return type;\r
+        }\r
+\r
+        @Override\r
+        public String getName() {\r
+            return name;\r
+        }\r
+\r
+        @Override\r
+        public Object getValue() {\r
+            return value;\r
+        }\r
+\r
+        @Override\r
+        public String toFormattedString() {\r
+            StringBuilder builder = new StringBuilder();\r
+            builder.append(type);\r
+            builder.append(" ");\r
+            builder.append(name);\r
+            builder.append(" ");\r
+            builder.append(value);\r
+            return builder.toString();\r
+        }\r
+\r
+        /*\r
+         * (non-Javadoc)\r
+         * \r
+         * @see java.lang.Object#hashCode()\r
+         */\r
+        @Override\r
+        public int hashCode() {\r
+            final int prime = 31;\r
+            int result = 1;\r
+            result = prime * result + ((name == null) ? 0 : name.hashCode());\r
+            result = prime * result + ((type == null) ? 0 : type.hashCode());\r
+            result = prime * result + ((value == null) ? 0 : value.hashCode());\r
+            if (definingType != null) {\r
+                result = prime\r
+                        * result\r
+                        + ((definingType.getPackageName() == null) ? 0\r
+                                : definingType.getPackageName().hashCode());\r
+                result = prime\r
+                        * result\r
+                        + ((definingType.getName() == null) ? 0 : definingType\r
+                                .getName().hashCode());\r
+            }\r
+            return result;\r
+        }\r
+\r
+        /*\r
+         * (non-Javadoc)\r
+         * \r
+         * @see java.lang.Object#equals(java.lang.Object)\r
+         */\r
+        @Override\r
+        public boolean equals(Object obj) {\r
+            if (this == obj) {\r
+                return true;\r
+            }\r
+            if (obj == null) {\r
+                return false;\r
+            }\r
+            if (getClass() != obj.getClass()) {\r
+                return false;\r
+            }\r
+            ConstantImpl other = (ConstantImpl) obj;\r
+            if (name == null) {\r
+                if (other.name != null) {\r
+                    return false;\r
+                }\r
+            } else if (!name.equals(other.name)) {\r
+                return false;\r
+            }\r
+            if (type == null) {\r
+                if (other.type != null) {\r
+                    return false;\r
+                }\r
+            } else if (!type.equals(other.type)) {\r
+                return false;\r
+            }\r
+            if (value == null) {\r
+                if (other.value != null) {\r
+                    return false;\r
+                }\r
+            } else if (!value.equals(other.value)) {\r
+                return false;\r
+            }\r
+            if (definingType == null) {\r
+                if (other.definingType != null) {\r
+                    return false;\r
+                }\r
+            } else if ((definingType != null) && (other.definingType != null)) {\r
+                if (!definingType.getPackageName().equals(\r
+                        other.definingType.getPackageName())\r
+                        && !definingType.getName().equals(\r
+                                other.definingType.getName())) {\r
+                    return false;\r
+                }\r
+            }\r
+            return true;\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            StringBuilder builder = new StringBuilder();\r
+            builder.append("ConstantImpl [type=");\r
+            builder.append(type);\r
+            builder.append(", name=");\r
+            builder.append(name);\r
+            builder.append(", value=");\r
+            builder.append(value);\r
+            if (definingType != null) {\r
+                builder.append(", definingType=");\r
+                builder.append(definingType.getPackageName());\r
+                builder.append(".");\r
+                builder.append(definingType.getName());\r
+            } else {\r
+                builder.append(", definingType= null");\r
+            }\r
+            builder.append("]");\r
+            return builder.toString();\r
+        }\r
+    }\r
+}\r