[ONOS-3897] Yang Listener for Enumeration Data Type
Change-Id: If257c73da8fe2dcc2f4111f103967cfcdd7fa273
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
index 59da354..76ab0f3 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnum.java
@@ -20,6 +20,8 @@
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
+import java.util.Objects;
+
/*-
* The "ENUM" statement, which is a sub-statement to the "type"
* statement, MUST be present if the type is "enumeration". It is
@@ -188,6 +190,23 @@
return ParsableDataType.ENUM_DATA;
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangEnum) {
+ final YangEnum other = (YangEnum) obj;
+ return Objects.equals(this.namedValue, other.namedValue);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.namedValue);
+ }
+
/**
* Validate the data on entering the corresponding parse tree node.
*
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
index 7aae900..ec5374e 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/YangEnumeration.java
@@ -16,13 +16,12 @@
package org.onosproject.yangutils.datamodel;
-import java.util.HashSet;
-import java.util.Set;
-
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
import org.onosproject.yangutils.parser.Parsable;
import org.onosproject.yangutils.parser.ParsableDataType;
-import org.onosproject.yangutils.translator.CachedFileHandle;
+
+import java.util.HashSet;
+import java.util.Set;
/*
* The enumeration built-in type represents values from a set of
@@ -32,20 +31,19 @@
/**
* Maintains the enumeration data type information.
*/
-public class YangEnumeration extends YangNode implements Parsable {
+public class YangEnumeration implements Parsable {
- /**
- * Enumeration info set.
- */
+ // Enumeration info set.
private Set<YangEnum> enumSet;
+ // Enumeration name.
+ private String enumerationName;
+
/**
- * Create an enumeration object.
+ * Creates an enumeration object.
*/
public YangEnumeration() {
- super(YangNodeType.ENUMERATION_NODE);
setEnumSet(new HashSet<YangEnum>());
-
}
/**
@@ -67,12 +65,33 @@
}
/**
- * Add ENUM value.
+ * Add ENUM information.
*
- * @param enumInfo the ENUM value of string
+ * @param enumInfo the ENUM information to be added.
+ * @throws DataModelException due to violation in data model rules.
*/
- public void addEnumInfo(YangEnum enumInfo) {
+ public void addEnumInfo(YangEnum enumInfo) throws DataModelException {
+ if (!getEnumSet().add(enumInfo)) {
+ throw new DataModelException("YANG ENUM already exists");
+ }
+ }
+ /**
+ * Return enumeration name.
+ *
+ * @return the enumeration name
+ */
+ public String getEnumerationName() {
+ return enumerationName;
+ }
+
+ /**
+ * Set the enumeration name.
+ *
+ * @param enumerationName enumeration name
+ */
+ public void setEnumerationName(String enumerationName) {
+ this.enumerationName = enumerationName;
}
/**
@@ -104,70 +123,4 @@
public void validateDataOnExit() throws DataModelException {
// TODO auto-generated method stub, to be implemented by parser
}
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#getName()
- */
- @Override
- public String getName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#setName(java.lang.String)
- */
- @Override
- public void setName(String name) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#getPackage()
- */
- @Override
- public String getPackage() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.datamodel.YangNode#setPackage(java.lang.String)
- */
- @Override
- public void setPackage(String pkg) {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeEntry()
- */
- @Override
- public void generateJavaCodeEntry() {
- // TODO Auto-generated method stub
-
- }
-
- /* (non-Javadoc)
- * @see org.onosproject.yangutils.translator.CodeGenerator#generateJavaCodeExit()
- */
- @Override
- public void generateJavaCodeExit() {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public CachedFileHandle getFileHandle() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void setFileHandle(CachedFileHandle fileHandle) {
- // TODO Auto-generated method stub
-
- }
}