Minor fixes
- typo in ModelConverter
- equals and compareTo behavior in SchemaId
- log original Exception in YobUtils
Change-Id: If4062dbe76e95730744f389cece42f82518d8d2b
diff --git a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
index 2a3e094..22e07df 100644
--- a/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
+++ b/model/src/main/java/org/onosproject/yang/model/ModelConverter.java
@@ -37,7 +37,7 @@
* Produces an immutable tree structure rooted at the returned DataNode
* using the supplied model POJO object.
* <p>
- * Model object identifier will be converted to resource identfier and
+ * Model object identifier will be converted to resource identifier and
* list of model objects will be converted to list of data nodes.
*
* @param modelData model object data
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaId.java b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
index 7e0249b..c07a5dc 100644
--- a/model/src/main/java/org/onosproject/yang/model/SchemaId.java
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaId.java
@@ -19,6 +19,8 @@
import java.io.Serializable;
import java.util.Objects;
+import com.google.common.collect.ComparisonChain;
+
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.yang.model.ModelConstants.INCOMPLETE_SCHEMA_INFO;
@@ -68,6 +70,7 @@
* @throws CloneNotSupportedException if the object's class does not
* support the {@code Cloneable} interface
*/
+ @Override
public SchemaId clone() throws CloneNotSupportedException {
return (SchemaId) super.clone();
}
@@ -79,23 +82,23 @@
@Override
public boolean equals(Object obj) {
- if (obj == null) {
- return false;
+ if (obj == this) {
+ return true;
}
- SchemaId that = (SchemaId) obj;
- return Objects.equals(name, that.name) &&
- Objects.equals(nameSpace, that.nameSpace);
+ if (obj instanceof SchemaId) {
+ SchemaId that = (SchemaId) obj;
+ return Objects.equals(name, that.name) &&
+ Objects.equals(nameSpace, that.nameSpace);
+ }
+ return false;
}
@Override
public int compareTo(SchemaId o) {
- checkNotNull(o);
- if (name.equals(o.name)) {
- if (nameSpace.equals(o.nameSpace)) {
- return 0;
- }
- }
- return -1;
+ return ComparisonChain.start()
+ .compare(this.name, o.name)
+ .compare(this.nameSpace, o.nameSpace)
+ .result();
}
@Override
diff --git a/model/src/test/java/org/onosproject/yang/model/SchemaIdTest.java b/model/src/test/java/org/onosproject/yang/model/SchemaIdTest.java
new file mode 100644
index 0000000..0334df8
--- /dev/null
+++ b/model/src/test/java/org/onosproject/yang/model/SchemaIdTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.yang.model;
+
+import org.junit.Test;
+
+import com.google.common.testing.EqualsTester;
+
+public class SchemaIdTest {
+
+ @Test
+ public void testEquals() {
+
+ new EqualsTester()
+ .addEqualityGroup(new SchemaId("a1", "a1"), new SchemaId("a" + 1, "a1"))
+ .addEqualityGroup(new SchemaId("b1", "a1"))
+ .addEqualityGroup(new SchemaId("a1", "b1"))
+ .addEqualityGroup(new SchemaId("c", "c"))
+ .testEquals();
+ }
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
index 7185240..63505ad 100644
--- a/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/impl/YobUtils.java
@@ -870,7 +870,7 @@
}
}
} catch (ClassNotFoundException e) {
- throw new ModelConverterException(E_FAIL_TO_LOAD_LEAF_IDENTIFIER_CLASS);
+ throw new ModelConverterException(E_FAIL_TO_LOAD_LEAF_IDENTIFIER_CLASS, e);
}
}
return midb;