YANG string restriction listener + YANG Range restriction listener review comment fix
Change-Id: I9e7af9c67f8fbf918d4e0d8ff147a560889ff264
diff --git a/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java b/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
index f60b650..f9a6fda 100644
--- a/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
+++ b/src/main/java/org/onosproject/yangutils/utils/YangConstructType.java
@@ -277,7 +277,17 @@
/**
* Identifies the YANG range element parsed data.
*/
- RANGE_DATA;
+ RANGE_DATA,
+
+ /**
+ * Identifies the YANG length element parsed data.
+ */
+ LENGTH_DATA,
+
+ /**
+ * Identifies the YANG pattern element parsed data.
+ */
+ PATTERN_DATA;
/**
* Returns the YANG construct keyword corresponding to enum values.
@@ -392,6 +402,10 @@
return "union";
case RANGE_DATA:
return "range";
+ case LENGTH_DATA:
+ return "length";
+ case PATTERN_DATA:
+ return "pattern";
default:
return "yang";
}
diff --git a/src/main/java/org/onosproject/yangutils/utils/builtindatatype/BuiltInTypeObjectFactory.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/BuiltInTypeObjectFactory.java
new file mode 100644
index 0000000..7002129
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/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.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
+ * @return the target data type object with the value initialized
+ * @param <T> the data type of the target object
+ */
+ 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/utils/builtindatatype/DataTypeException.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/DataTypeException.java
new file mode 100644
index 0000000..4cad2cd
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/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.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/utils/builtindatatype/YangBuiltInDataTypeInfo.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangBuiltInDataTypeInfo.java
new file mode 100644
index 0000000..437fe0f
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/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.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/utils/builtindatatype/YangInt16.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java
new file mode 100644
index 0000000..1ad76b5
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt16.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+ }
+
+ /**
+ * 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/utils/builtindatatype/YangInt32.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java
new file mode 100644
index 0000000..93dcec6
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt32.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+ }
+
+
+ /**
+ * 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/utils/builtindatatype/YangInt64.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java
new file mode 100644
index 0000000..a046ee8
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt64.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+ }
+
+
+ /**
+ * 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/utils/builtindatatype/YangInt8.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java
new file mode 100644
index 0000000..c902410
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangInt8.java
@@ -0,0 +1,92 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+ }
+
+ /**
+ * 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/utils/builtindatatype/YangUint16.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java
new file mode 100644
index 0000000..b109103
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint16.java
@@ -0,0 +1,101 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+
+ 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/utils/builtindatatype/YangUint32.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java
new file mode 100644
index 0000000..e356055
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint32.java
@@ -0,0 +1,93 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+
+ 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/utils/builtindatatype/YangUint64.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java
new file mode 100644
index 0000000..70001ae
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint64.java
@@ -0,0 +1,105 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+
+ 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/utils/builtindatatype/YangUint8.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java
new file mode 100644
index 0000000..caf0628
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/YangUint8.java
@@ -0,0 +1,100 @@
+/*
+ * 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.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 : " + valueInString + " is not valid.");
+ }
+ }
+
+ 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/utils/builtindatatype/package-info.java b/src/main/java/org/onosproject/yangutils/utils/builtindatatype/package-info.java
new file mode 100644
index 0000000..9d3aa33
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/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.utils.builtindatatype;