[ONOS-4670] Removal of Data Model dependencies on Linker
Change-Id: I3f9c5af30198ea31d743e06cea1764dcb306ec32
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
index 29d384b..97c7327 100644
--- a/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/DataModelUtils.java
@@ -18,20 +18,18 @@
import java.util.List;
import java.util.Set;
-
import org.onosproject.yangutils.datamodel.CollisionDetector;
+import org.onosproject.yangutils.datamodel.ResolvableType;
import org.onosproject.yangutils.datamodel.YangLeaf;
import org.onosproject.yangutils.datamodel.YangLeafList;
import org.onosproject.yangutils.datamodel.YangLeavesHolder;
import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangReferenceResolver;
+import org.onosproject.yangutils.datamodel.YangResolutionInfo;
import org.onosproject.yangutils.datamodel.YangRpc;
import org.onosproject.yangutils.datamodel.YangType;
import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
-import org.onosproject.yangutils.linker.ResolvableType;
-import org.onosproject.yangutils.linker.YangReferenceResolver;
-import org.onosproject.yangutils.linker.impl.YangResolutionInfo;
import org.onosproject.yangutils.parser.Parsable;
-import org.onosproject.yangutils.plugin.manager.YangFileInfo;
import org.onosproject.yangutils.utils.YangConstructType;
/**
@@ -179,7 +177,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void resolveLinkingForResolutionList(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
for (YangResolutionInfo resolutionInfo : resolutionList) {
@@ -195,7 +193,7 @@
* @throws DataModelException a violation of data model rules
*/
public static void linkInterFileReferences(List<YangResolutionInfo> resolutionList,
- YangReferenceResolver dataModelRootNode)
+ YangReferenceResolver dataModelRootNode)
throws DataModelException {
/*
* Run through the resolution list, find type/uses referring to
@@ -226,19 +224,18 @@
/**
* Returns referred node in a given set.
*
- * @param yangFileInfoSet YANG file info set
- * @param refNodeName name of the node which is referred
+ * @param yangNodeSet YANG node set
+ * @param refNodeName name of the node which is referred
* @return referred node's reference
*/
- public static YangNode findReferredNode(Set<YangFileInfo> yangFileInfoSet, String refNodeName) {
+ public static YangNode findReferredNode(Set<YangNode> yangNodeSet, String refNodeName) {
/*
* Run through the YANG files to see which YANG file matches the
* referred node name.
*/
- for (YangFileInfo yangFileInfo : yangFileInfoSet) {
- YangNode yangNode = yangFileInfo.getRootNode();
+ for (YangNode yangNode : yangNodeSet) {
if (yangNode.getName().equals(refNodeName)) {
- return yangFileInfo.getRootNode();
+ return yangNode;
}
}
return null;
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
new file mode 100644
index 0000000..4148278
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/RestrictionResolver.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils;
+
+import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+import org.onosproject.yangutils.datamodel.YangRangeInterval;
+import org.onosproject.yangutils.datamodel.YangRangeRestriction;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.utils.YangConstructType;
+import org.onosproject.yangutils.datamodel.utils.builtindatatype.YangBuiltInDataTypeInfo;
+
+import static org.onosproject.yangutils.datamodel.YangDataTypes.DECIMAL64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.INT8;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT16;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT32;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT64;
+import static org.onosproject.yangutils.datamodel.YangDataTypes.UINT8;
+import static org.onosproject.yangutils.utils.UtilConstants.ADD;
+import static org.onosproject.yangutils.utils.UtilConstants.EMPTY_STRING;
+import static org.onosproject.yangutils.utils.YangConstructType.LENGTH_DATA;
+import static org.onosproject.yangutils.utils.YangConstructType.RANGE_DATA;
+import static org.onosproject.yangutils.datamodel.utils.builtindatatype.BuiltInTypeObjectFactory.getDataObjectFromString;
+
+/**
+ * Represents restriction resolver which provide common utility used by parser
+ * and during linking for restriction resolution.
+ */
+public final class RestrictionResolver {
+
+ private static final String PIPE = "|";
+ private static final String INTERVAL = "..";
+ private static final int MAX_RANGE_BOUNDARY = 2;
+ private static final int MIN_RANGE_BOUNDARY = 1;
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Creates a restriction resolver.
+ */
+ private RestrictionResolver() {
+ }
+
+ /**
+ * Processes the range restriction for parser and linker.
+ *
+ * @param refRangeRestriction range restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curRangeString caller type's range string
+ * @param effectiveType effective type, when called from linker
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processRangeRestriction(YangRangeRestriction refRangeRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curRangeString, YangDataTypes effectiveType)
+ throws DataModelException {
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction rangeRestriction = new YangRangeRestriction();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curRangeString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(RANGE_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, effectiveType);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refRangeRestriction.getMinRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refRangeRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refRangeRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, effectiveType);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ rangeRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return rangeRestriction;
+ }
+
+ /**
+ * Processes the length restriction for parser and linker.
+ *
+ * @param refLengthRestriction length restriction of referred typedef
+ * @param lineNumber error line number
+ * @param charPositionInLine error character position in line
+ * @param hasReferredRestriction whether has referred restriction
+ * @param curLengthString caller type's length string
+ * @return YANG range restriction
+ * @throws DataModelException a violation in data model rule
+ */
+ public static YangRangeRestriction processLengthRestriction(YangRangeRestriction refLengthRestriction,
+ int lineNumber, int charPositionInLine,
+ boolean hasReferredRestriction,
+ String curLengthString) throws DataModelException {
+
+ YangBuiltInDataTypeInfo<?> startValue;
+ YangBuiltInDataTypeInfo<?> endValue;
+ YangRangeRestriction lengthRestriction = new YangRangeRestriction<>();
+
+ String rangeArgument = removeQuotesAndHandleConcat(curLengthString);
+ String[] rangeArguments = rangeArgument.trim().split(Pattern.quote(PIPE));
+
+ for (String rangePart : rangeArguments) {
+ String startInterval;
+ String endInterval;
+ YangRangeInterval rangeInterval = new YangRangeInterval<>();
+ String[] rangeBoundary = rangePart.trim().split(Pattern.quote(INTERVAL));
+
+ if (rangeBoundary.length > MAX_RANGE_BOUNDARY) {
+ DataModelException dataModelException = new DataModelException("YANG file error : " +
+ YangConstructType.getYangConstructType(LENGTH_DATA) + " " + rangeArgument +
+ " is not valid.");
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ if (rangeBoundary.length == MIN_RANGE_BOUNDARY) {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[0].trim();
+ } else {
+ startInterval = rangeBoundary[0].trim();
+ endInterval = rangeBoundary[1].trim();
+ }
+
+ try {
+ if (hasReferredRestriction && startInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && startInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ startValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ startValue = getDataObjectFromString(startInterval, YangDataTypes.UINT64);
+ }
+ if (hasReferredRestriction && endInterval.equals(MIN_KEYWORD)
+ && refLengthRestriction.getMinRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMinRestrictedvalue();
+ } else if (hasReferredRestriction && endInterval.equals(MAX_KEYWORD)
+ && refLengthRestriction.getMaxRestrictedvalue() != null) {
+ endValue = refLengthRestriction.getMaxRestrictedvalue();
+ } else {
+ endValue = getDataObjectFromString(endInterval, YangDataTypes.UINT64);
+ }
+ } catch (Exception e) {
+ DataModelException dataModelException = new DataModelException(e.getMessage());
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+
+ rangeInterval.setStartValue(startValue);
+ rangeInterval.setEndValue(endValue);
+
+ try {
+ lengthRestriction.addRangeRestrictionInterval(rangeInterval);
+ } catch (DataModelException dataModelException) {
+ dataModelException.setLine(lineNumber);
+ dataModelException.setCharPosition(charPositionInLine);
+ throw dataModelException;
+ }
+ }
+ return lengthRestriction;
+ }
+
+ /**
+ * Returns whether the data type is of range restricted type.
+ *
+ * @param dataType data type to be checked
+ * @return true, if data type can have range restrictions, false otherwise
+ */
+ public static boolean isOfRangeRestrictedType(YangDataTypes dataType) {
+ return (dataType == INT8
+ || dataType == INT16
+ || dataType == INT32
+ || dataType == INT64
+ || dataType == UINT8
+ || dataType == UINT16
+ || dataType == UINT32
+ || dataType == UINT64
+ || dataType == DECIMAL64);
+ }
+
+ /**
+ * Removes doubles quotes and concatenates if string has plus symbol.
+ *
+ * @param yangStringData string from yang file
+ * @return concatenated string after removing double quotes
+ */
+ private static String removeQuotesAndHandleConcat(String yangStringData) {
+
+ yangStringData = yangStringData.replace("\"", EMPTY_STRING);
+ String[] tmpData = yangStringData.split(Pattern.quote(ADD));
+ StringBuilder builder = new StringBuilder();
+ for (String yangString : tmpData) {
+ builder.append(yangString);
+ }
+ return builder.toString();
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
new file mode 100644
index 0000000..4c2d79b
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/BuiltInTypeObjectFactory.java
@@ -0,0 +1,75 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Factory to create an object of required type.
+ */
+public final class BuiltInTypeObjectFactory {
+
+ /**
+ * Utility factory class, hence the object creation is forbidden.
+ */
+ private BuiltInTypeObjectFactory() {
+ }
+
+ /**
+ * Given the value represented in string return the corresponding types
+ * object with the value initialized.
+ *
+ * @param valueInStr value represented in string
+ * @param builtInType built in data type
+ * @param <T> the data type of the target object
+ * @return the target data type object with the value initialized
+ */
+ public static <T extends YangBuiltInDataTypeInfo<?>> T getDataObjectFromString(String valueInStr,
+ YangDataTypes builtInType) {
+
+ switch (builtInType) {
+ case INT8: {
+ return (T) new YangInt8(valueInStr);
+ }
+ case INT16: {
+ return (T) new YangInt16(valueInStr);
+ }
+ case INT32: {
+ return (T) new YangInt32(valueInStr);
+ }
+ case INT64: {
+ return (T) new YangInt64(valueInStr);
+ }
+ case UINT8: {
+ return (T) new YangUint8(valueInStr);
+ }
+ case UINT16: {
+ return (T) new YangUint16(valueInStr);
+ }
+ case UINT32: {
+ return (T) new YangUint32(valueInStr);
+ }
+ case UINT64: {
+ return (T) new YangUint64(valueInStr);
+ }
+ default: {
+ throw new DataTypeException("YANG file error : Unsupported data type");
+ }
+ }
+
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
new file mode 100644
index 0000000..8c24d6c
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/DataTypeException.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+/**
+ * Base class for exceptions in data type.
+ */
+public class DataTypeException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+
+ /**
+ * Create a new data type exception.
+ */
+ public DataTypeException() {
+ super();
+ }
+
+ /**
+ * Creates a new data type exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public DataTypeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new data type exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new data type exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public DataTypeException(final Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
new file mode 100644
index 0000000..a93379b
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBinary.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents binary data type.
+ */
+public final class YangBinary {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG binary.
+ */
+ private YangBinary() {
+ }
+
+ /**
+ * Creates an instance of YANG binary.
+ *
+ * @param bytes byte array
+ */
+ public YangBinary(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG binary.
+ *
+ * @param bytes byte array
+ * @return object of YANG binary
+ */
+ public static YangBinary of(byte[] bytes) {
+ return new YangBinary(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBinary) {
+ YangBinary other = (YangBinary) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG binary fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG binary
+ */
+ public static YangBinary fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
new file mode 100644
index 0000000..f2c05f7
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBits.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents bits data type.
+ */
+public class YangBits {
+
+ private byte[] byteArray;
+
+ /**
+ * Creates an instance of YANG bits.
+ */
+ private YangBits() {
+ }
+
+ /**
+ * Creates an instance of YANG bits.
+ *
+ * @param bytes byte array
+ */
+ public YangBits(byte[] bytes) {
+ this.byteArray = bytes;
+ }
+
+ /**
+ * Returns object of YANG bits.
+ *
+ * @param bytes byte array
+ * @return object of YANG bits
+ */
+ public static YangBits of(byte[] bytes) {
+ return new YangBits(bytes);
+ }
+
+ /**
+ * Returns byte array.
+ *
+ * @return byte array
+ */
+ public byte[] byteArray() {
+ return byteArray;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(byteArray);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangBits) {
+ YangBits other = (YangBits) obj;
+ return Objects.equals(byteArray, other.byteArray);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("byteArray", byteArray)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG bits fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG bits
+ */
+ public static YangBits fromString(String valInString) {
+ try {
+ byte[] tmpVal = valInString.getBytes();
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
new file mode 100644
index 0000000..b082c16
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangBuiltInDataTypeInfo.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Represents the list of utility functions to be supported by YANG built in
+ * data type implementations.
+ *
+ * @param <T> The target data type
+ */
+public interface YangBuiltInDataTypeInfo<T> extends Comparable<T> {
+
+ /**
+ * Returns the YANG built in type.
+ *
+ * @return the YANG built in type
+ */
+ YangDataTypes getYangType();
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
new file mode 100644
index 0000000..ca45073
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangDecimal64.java
@@ -0,0 +1,111 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.util.Objects;
+import com.google.common.base.MoreObjects;
+
+/**
+ * Represents YANG decimal 64.
+ */
+public class YangDecimal64 {
+
+ private int fractionDigit;
+
+ /**
+ * Creates an instance of YANG decimal64.
+ */
+ public YangDecimal64() {
+ }
+
+ /**
+ * Creates an instance of of YANG decimal64.
+ *
+ * @param fractionDigit fraction digit
+ */
+ public YangDecimal64(int fractionDigit) {
+ this.setFractionDigit(fractionDigit);
+ }
+
+ /**
+ * Returns fraction digit.
+ *
+ * @return the fractionDigit
+ */
+ public int getFractionDigit() {
+ return fractionDigit;
+ }
+
+ /**
+ * Sets fraction digit.
+ *
+ * @param fractionDigit fraction digits.
+ */
+ public void setFractionDigit(int fractionDigit) {
+ this.fractionDigit = fractionDigit;
+ }
+
+ /**
+ * Returns object of YANG decimal64.
+ *
+ * @param value fraction digit
+ * @return YANG decimal64
+ */
+ public static YangDecimal64 of(int value) {
+ return new YangDecimal64(value);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(fractionDigit);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj instanceof YangDecimal64) {
+ YangDecimal64 other = (YangDecimal64) obj;
+ return Objects.equals(fractionDigit, other.fractionDigit);
+ }
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(getClass())
+ .omitNullValues()
+ .add("fractionDigit", fractionDigit)
+ .toString();
+ }
+
+ /**
+ * Returns the object of YANG decimal64 fromString input String.
+ *
+ * @param valInString input String
+ * @return Object of YANG decimal64
+ */
+ public static YangDecimal64 fromString(String valInString) {
+ try {
+ int tmpVal = Integer.parseInt(valInString);
+ return of(tmpVal);
+ } catch (Exception e) {
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
new file mode 100644
index 0000000..2a660c1
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt16.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+
+/**
+ * Handles the YANG's int16 data type processing.
+ *
+ * int16 represents integer values between -32768 and 32767, inclusively.
+ */
+public class YangInt16 implements YangBuiltInDataTypeInfo<YangInt16> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int16.
+ */
+ public static final short MIN_VALUE = -32768;
+
+ /**
+ * Valid maximum value of YANG's int16.
+ */
+ public static final short MAX_VALUE = 32767;
+
+ /**
+ * The value of YANG's int16.
+ */
+ private final short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int16.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int16 value.
+ *
+ * @return value of YANG's int16
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt16 anotherYangInt16) {
+ return Short.compare(value, anotherYangInt16.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT16;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
new file mode 100644
index 0000000..6774b37
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt32.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int32 data type processing.
+ *
+ * int32 represents integer values between -2147483648 and 2147483647, inclusively.
+ */
+public class YangInt32 implements YangBuiltInDataTypeInfo<YangInt32> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int32.
+ */
+ public static final int MIN_VALUE = -2147483648;
+
+ /**
+ * Valid maximum value of YANG's int32.
+ */
+ public static final int MAX_VALUE = 2147483647;
+
+ /**
+ * The value of YANG's int32.
+ */
+ private final int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int32.");
+ }
+ }
+ }
+
+
+ /**
+ * Returns YANG's int32 value.
+ *
+ * @return value of YANG's int32
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt32 anotherYangInt32) {
+ return Integer.compare(value, anotherYangInt32.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT32;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
new file mode 100644
index 0000000..6a426d1
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt64.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -9223372036854775808 and 9223372036854775807, inclusively.
+ */
+public class YangInt64 implements YangBuiltInDataTypeInfo<YangInt64> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int64.
+ */
+ public static final Long MIN_VALUE = 0x8000000000000000L;
+
+ /**
+ * Valid maximum value of YANG's int64.
+ */
+ public static final long MAX_VALUE = 0x7fffffffffffffffL;
+
+ /**
+ * The value of YANG's int64.
+ */
+ private final long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int64.");
+ }
+ }
+ }
+
+
+ /**
+ * Returns YANG's int64 value.
+ *
+ * @return value of YANG's int64
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt64 anotherYangInt64) {
+ return Long.compare(value, anotherYangInt64.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT64;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
new file mode 100644
index 0000000..df3221d
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangInt8.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's int8 data type processing.
+ *
+ * int8 represents integer values between -128 and 127, inclusively.
+ */
+public class YangInt8 implements YangBuiltInDataTypeInfo<YangInt8> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's int8.
+ */
+ public static final byte MIN_VALUE = -128;
+
+ /**
+ * Valid maximum value of YANG's int8.
+ */
+ public static final byte MAX_VALUE = 127;
+
+ /**
+ * The value of YANG's int8.
+ */
+ private final byte value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ public YangInt8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Byte.parseByte(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "int8.");
+ }
+ }
+ }
+
+ /**
+ * Returns YANG's int8 value.
+ *
+ * @return value of YANG's int8
+ */
+ public byte getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangInt8 anotherYangInt8) {
+ return Byte.compare(value, anotherYangInt8.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.INT8;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
new file mode 100644
index 0000000..8a4fa93
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint16.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint16 represents integer values between 0 and 65535, inclusively.
+ */
+public class YangUint16 implements YangBuiltInDataTypeInfo<YangUint16> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint16.
+ */
+ public static final int MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint16.
+ */
+ public static final int MAX_VALUE = 65535;
+
+ /**
+ * Value of the object.
+ */
+ private int value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint16(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Integer.parseInt(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint16.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint16 value.
+ *
+ * @return value of YANG's uint16
+ */
+ public int getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint16 another) {
+ return Integer.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT16;
+ }
+
+}
+
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
new file mode 100644
index 0000000..f3dc7ec
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint32.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint32 data type processing.
+ *
+ * Uint32 represents integer values between 0 and 4294967295, inclusively.
+ */
+public class YangUint32 implements YangBuiltInDataTypeInfo<YangUint32> {
+
+ private static final String MIN_KEYWORD = "min";
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint32.
+ */
+ public static final long MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint32.
+ */
+ public static final long MAX_VALUE = 4294967295L;
+
+ /**
+ * Value of the object.
+ */
+ private long value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint32(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Long.parseLong(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint32.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint32 value.
+ *
+ * @return value of YANG's uint32
+ */
+ public long getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint32 another) {
+ return Long.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT32;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
new file mode 100644
index 0000000..bc66d59
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint64.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import java.math.BigInteger;
+import java.util.regex.Pattern;
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint16 data type processing.
+ *
+ * Uint64 represents integer values between 0 and 18446744073709551615, inclusively.
+ */
+public class YangUint64 implements YangBuiltInDataTypeInfo<YangUint64> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * YANG's Integer value pattern.
+ */
+ private static final Pattern NON_NEGATIVE_INTEGER_PATTERN = Pattern.compile("[0-9]+");
+
+ /**
+ * Valid minimum value of YANG's Uint64.
+ */
+ public static final BigInteger MIN_VALUE = BigInteger.valueOf(0);
+
+ /**
+ * Valid maximum value of YANG's Uint64.
+ */
+ public static final BigInteger MAX_VALUE = new BigInteger("18446744073709551615");
+
+ /**
+ * Value of the object.
+ */
+ private BigInteger value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint64(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else if (NON_NEGATIVE_INTEGER_PATTERN.matcher(valueInString).matches()) {
+ value = new BigInteger(valueInString);
+ } else {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint64.");
+ }
+
+ if (value.compareTo(MIN_VALUE) < 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value.compareTo(MAX_VALUE) > 0) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint64 value.
+ *
+ * @return value of YANG's uint64
+ */
+ public BigInteger getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint64 another) {
+ return value.compareTo(another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT64;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
new file mode 100644
index 0000000..dd4901f
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/YangUint8.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;
+
+import org.onosproject.yangutils.datamodel.YangDataTypes;
+
+/**
+ * Handles the YANG's Uint8 data type processing.
+ *
+ * Uint8 represents integer values between 0 and 255, inclusively.
+ */
+public class YangUint8 implements YangBuiltInDataTypeInfo<YangUint8> {
+
+ /**
+ * YANG's min keyword.
+ */
+ private static final String MIN_KEYWORD = "min";
+
+ /**
+ * YANG's max keyword.
+ */
+ private static final String MAX_KEYWORD = "max";
+
+ /**
+ * Valid minimum value of YANG's Uint8.
+ */
+ public static final short MIN_VALUE = 0;
+
+ /**
+ * Valid maximum value of YANG's Uint8.
+ */
+ public static final short MAX_VALUE = 255;
+
+ /**
+ * Value of the object.
+ */
+ private short value;
+
+ /**
+ * Creates an object with the value initialized with value represented in
+ * string.
+ *
+ * @param valueInString value of the object in string
+ */
+ YangUint8(String valueInString) {
+
+ if (valueInString.matches(MIN_KEYWORD)) {
+ value = MIN_VALUE;
+ } else if (valueInString.matches(MAX_KEYWORD)) {
+ value = MAX_VALUE;
+ } else {
+ try {
+ value = Short.parseShort(valueInString);
+ } catch (Exception e) {
+ throw new DataTypeException("YANG file error : Input value \"" + valueInString + "\" is not a valid " +
+ "uint8.");
+ }
+ }
+
+ if (value < MIN_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is lesser than minimum value "
+ + MIN_VALUE + ".");
+ } else if (value > MAX_VALUE) {
+ throw new DataTypeException("YANG file error : " + valueInString + " is greater than maximum value "
+ + MAX_VALUE + ".");
+ }
+ }
+
+ /**
+ * Returns YANG's uint8 value.
+ *
+ * @return value of YANG's uint8
+ */
+ public short getValue() {
+ return value;
+ }
+
+ @Override
+ public int compareTo(YangUint8 another) {
+ return Short.compare(value, another.value);
+ }
+
+ @Override
+ public YangDataTypes getYangType() {
+ return YangDataTypes.UINT8;
+ }
+
+}
diff --git a/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
new file mode 100644
index 0000000..d1ceae5
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/datamodel/utils/builtindatatype/package-info.java
@@ -0,0 +1,20 @@
+/*-
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Utilities for YANG built in data types.
+ */
+package org.onosproject.yangutils.datamodel.utils.builtindatatype;