Replace redundant instanceof with non-null check

Change-Id: Ib86b0c8561824b1753b299f680d7d336205dd9a4
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java
index 4dc2d21..06e01ae 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcInitiatedLspRequestVer1.java
@@ -283,13 +283,13 @@
         ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
         toStrHelper.add("SrpObject", srpObject).add("LspObject", lspObject);
 
-        if (endPointsObject instanceof PcepEndPointsObject) {
+        if (endPointsObject != null) {
             toStrHelper.add("EndPointObject", endPointsObject);
         }
-        if (eroObject instanceof PcepEroObject) {
+        if (eroObject != null) {
             toStrHelper.add("EroObject", eroObject);
         }
-        if (pcepAttribute instanceof PcepAttribute) {
+        if (pcepAttribute != null) {
             toStrHelper.add("PcepAttribute", pcepAttribute);
         }
         return toStrHelper.toString();
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java
index 3e3e562..446cc1f 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepAttributeVer1.java
@@ -423,18 +423,18 @@
     public String toString() {
         ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
 
-        if (lspaObject instanceof PcepLspaObject) {
+        if (lspaObject != null) {
             toStrHelper.add("lspaObject", lspaObject);
         }
-        if (bandwidthObject instanceof PcepBandwidthObject) {
+        if (bandwidthObject != null) {
             toStrHelper.add("bandwidthObject", bandwidthObject);
         }
         if (llMetricList instanceof PcepMetricObject) {
             toStrHelper.add("MetricObjectList", llMetricList);
         }
-        if (iroObject instanceof PcepIroObject) {
+        if (iroObject != null) {
             toStrHelper.add("IroObject", iroObject);
         }
         return toStrHelper.toString();
     }
-}
\ No newline at end of file
+}
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java
index 2326804..fbbba27 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepErrorMsgVer1.java
@@ -146,7 +146,7 @@
             tempObjHeader = parseErrorObjectList(llErrObjList, cb);
 
             //check whether OPEN-OBJECT is present.
-            if ((tempObjHeader instanceof PcepObjectHeader)
+            if ((tempObjHeader != null)
                     && (tempObjHeader.getObjClass() == PcepOpenObjectVer1.OPEN_OBJ_CLASS)) {
 
                 if (llErrObjList.isEmpty()) {
@@ -156,7 +156,7 @@
                 PcepOpenObject pcepOpenObj = PcepOpenObjectVer1.read(cb);
                 this.errObjListWithOpen = new ErrorObjListWithOpen(llErrObjList, pcepOpenObj);
 
-            } else if ((tempObjHeader instanceof PcepObjectHeader) //check whether RP or TE Object is present.
+            } else if ((tempObjHeader != null) //check whether RP or TE Object is present.
                     && ((tempObjHeader.getObjClass() == PcepRPObjectVer1.RP_OBJ_CLASS)
                             || (tempObjHeader.getObjClass() == PcepTEObjectVer1.TE_OBJ_CLASS))) {
 
@@ -273,10 +273,10 @@
             // write ( <error-obj-list> [<Open>] ) if exists.
             // otherwise write <error> [<error-list>]
 
-            if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
+            if ((errObjListWithOpen != null)
                     && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
                 errObjListWithOpen.write(cb);
-            } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
+            } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
                 errInfo.write(cb);
             } else {
                 throw new PcepParseException("Empty PCEP-ERROR message.");
@@ -324,10 +324,10 @@
      */
     public LinkedList<Integer> getErrorType() {
         LinkedList<Integer> llErrorType = new LinkedList<Integer>();
-        if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
+        if ((errObjListWithOpen != null)
                 && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
             llErrorType = errObjListWithOpen.getErrorType();
-        } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
+        } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
             llErrorType = errInfo.getErrorType();
         }
 
@@ -341,10 +341,10 @@
      */
     public LinkedList<Integer> getErrorValue() {
         LinkedList<Integer> llErrorValue = new LinkedList<Integer>();
-        if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
+        if ((errObjListWithOpen != null)
                 && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
             llErrorValue = errObjListWithOpen.getErrorValue();
-        } else if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
+        } else if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
             llErrorValue = errInfo.getErrorValue();
         }
 
@@ -355,11 +355,11 @@
     public String toString() {
         ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
 
-        if ((errObjListWithOpen instanceof ErrorObjListWithOpen)
+        if ((errObjListWithOpen != null)
                 && (errObjListWithOpen.isErrorObjListWithOpenPresent())) {
             toStrHelper.add("ErrorObjectListWithOpen", errObjListWithOpen);
         }
-        if ((errInfo instanceof PcepErrorInfo) && (errInfo.isErrorInfoPresent())) {
+        if ((errInfo != null) && (errInfo.isErrorInfoPresent())) {
             toStrHelper.add("ErrorInfo", errInfo);
         }
 
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java
index 60d4af9..5b47f53 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepInitiateMsgVer1.java
@@ -252,7 +252,7 @@
 
                 //Srp Object is mandatory
                 PcepSrpObject srpObj = listReq.getSrpObject();
-                if (srpObj instanceof PcepSrpObject) {
+                if (srpObj != null) {
                     isDelLspRequest = srpObj.getRFlag();
                     srpObj.write(cb);
                 } else {
@@ -261,7 +261,7 @@
 
                 //LSP Object is mandatory
                 PcepLspObject lspObj = listReq.getLspObject();
-                if (lspObj instanceof PcepLspObject) {
+                if (lspObj != null) {
                     lspObj.write(cb);
                 } else {
                     throw new PcepParseException("LSP Object is mandatory for PcInitiate message.");
@@ -275,7 +275,7 @@
 
                     //EndPoints object is mandatory
                     PcepEndPointsObject endPointObj = listReq.getEndPointsObject();
-                    if (endPointObj instanceof PcepEndPointsObject) {
+                    if (endPointObj != null) {
                         endPointObj.write(cb);
                     } else {
                         throw new PcepParseException("End points Object is mandatory for PcInitiate message.");
@@ -283,7 +283,7 @@
 
                     //Ero object is mandatory
                     PcepEroObject eroObj = listReq.getEroObject();
-                    if (eroObj instanceof PcepEroObject) {
+                    if (eroObj != null) {
                         eroObj.write(cb);
                     } else {
                         throw new PcepParseException("ERO Object is mandatory for PcInitiate message.");
@@ -291,7 +291,7 @@
 
                     //PcepAttribute is optional
                     PcepAttribute pcepAttribute = listReq.getPcepAttribute();
-                    if (pcepAttribute instanceof PcepAttribute) {
+                    if (pcepAttribute != null) {
                         pcepAttribute.write(cb);
                     }
                 }
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java
index a13045d..2e6c26b 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepLabelUpdateVer1.java
@@ -350,10 +350,10 @@
     public String toString() {
         ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
 
-        if (labelDownload instanceof PcepLabelDownload) {
+        if (labelDownload != null) {
             toStrHelper.add("LabelDownload", labelDownload);
         }
-        if (labelMap instanceof PcepLabelMap) {
+        if (labelMap != null) {
             toStrHelper.add("LabelMap", labelMap);
         }
         return toStrHelper.toString();
diff --git a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java
index 3a1bfcf..456a3c1 100644
--- a/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java
+++ b/pcep/pcepio/src/main/java/org/onosproject/pcepio/protocol/ver1/PcepStateReportVer1.java
@@ -263,7 +263,7 @@
         public String toString() {
             ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
 
-            if (attrList instanceof PcepAttribute) {
+            if (attrList != null) {
                 toStrHelper.add("AttributeList", attrList);
             }
             if (rroObj instanceof PcepRroObjectVer1) {
@@ -413,15 +413,15 @@
     public String toString() {
         ToStringHelper toStrHelper = MoreObjects.toStringHelper(getClass());
 
-        if (this.srpObject instanceof PcepSrpObject) {
+        if (this.srpObject != null) {
             toStrHelper.add("SrpObject", srpObject);
         }
-        if (this.lspObject instanceof PcepLspObject) {
+        if (this.lspObject != null) {
             toStrHelper.add("LspObject", lspObject);
         }
-        if (this.msgPath instanceof PcepStateReport.PcepMsgPath) {
+        if (this.msgPath != null) {
             toStrHelper.add("MsgPath", msgPath);
         }
         return toStrHelper.toString();
     }
-}
\ No newline at end of file
+}