Priyanka B
Committed by Ray Milkey

Compare fix

Change-Id: I56ad744ff9d99198136c97f62896c487285192ec
...@@ -238,6 +238,7 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> { ...@@ -238,6 +238,7 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> {
238 return 0; 238 return 0;
239 } 239 }
240 int result = this.localNodeDescriptors.compareTo(((BgpPrefixLSIdentifier) o).localNodeDescriptors); 240 int result = this.localNodeDescriptors.compareTo(((BgpPrefixLSIdentifier) o).localNodeDescriptors);
241 + boolean tlvFound = false;
241 if (result != 0) { 242 if (result != 0) {
242 return result; 243 return result;
243 } else { 244 } else {
...@@ -252,17 +253,21 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> { ...@@ -252,17 +253,21 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> {
252 } 253 }
253 254
254 ListIterator<BgpValueType> listIterator = prefixDescriptor.listIterator(); 255 ListIterator<BgpValueType> listIterator = prefixDescriptor.listIterator();
255 - ListIterator<BgpValueType> listIteratorOther = ((BgpPrefixLSIdentifier) o).prefixDescriptor.listIterator();
256 while (listIterator.hasNext()) { 256 while (listIterator.hasNext()) {
257 - BgpValueType tlv = listIterator.next(); 257 + BgpValueType tlv1 = listIterator.next();
258 - if (prefixDescriptor.contains(tlv) && ((BgpPrefixLSIdentifier) o).prefixDescriptor.contains(tlv)) { 258 + for (BgpValueType tlv : ((BgpPrefixLSIdentifier) o).prefixDescriptor) {
259 - int res = prefixDescriptor.get(prefixDescriptor.indexOf(tlv)).compareTo( 259 + if (tlv.getType() == tlv1.getType()) {
260 + result = prefixDescriptor.get(prefixDescriptor.indexOf(tlv1)).compareTo(
260 ((BgpPrefixLSIdentifier) o).prefixDescriptor 261 ((BgpPrefixLSIdentifier) o).prefixDescriptor
261 .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv))); 262 .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv)));
262 - if (res != 0) { 263 + if (result != 0) {
263 - return res; 264 + return result;
264 } 265 }
265 - } else { 266 + tlvFound = true;
267 + break;
268 + }
269 + }
270 + if (!tlvFound) {
266 return 1; 271 return 1;
267 } 272 }
268 } 273 }
......
...@@ -234,14 +234,20 @@ public class NodeDescriptors { ...@@ -234,14 +234,20 @@ public class NodeDescriptors {
234 .toString(); 234 .toString();
235 } 235 }
236 236
237 + /**
238 + * Compares this and o object.
239 + *
240 + * @param o object to be compared with this object
241 + * @return which object is greater
242 + */
237 public int compareTo(Object o) { 243 public int compareTo(Object o) {
238 if (this.equals(o)) { 244 if (this.equals(o)) {
239 return 0; 245 return 0;
240 } 246 }
241 ListIterator<BgpValueType> listIterator = subTlvs.listIterator(); 247 ListIterator<BgpValueType> listIterator = subTlvs.listIterator();
242 - ListIterator<BgpValueType> listIteratorOther = ((NodeDescriptors) o).subTlvs.listIterator();
243 int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size(); 248 int countOtherSubTlv = ((NodeDescriptors) o).subTlvs.size();
244 int countObjSubTlv = subTlvs.size(); 249 int countObjSubTlv = subTlvs.size();
250 + boolean tlvFound = false;
245 if (countOtherSubTlv != countObjSubTlv) { 251 if (countOtherSubTlv != countObjSubTlv) {
246 if (countOtherSubTlv > countObjSubTlv) { 252 if (countOtherSubTlv > countObjSubTlv) {
247 return 1; 253 return 1;
...@@ -250,15 +256,20 @@ public class NodeDescriptors { ...@@ -250,15 +256,20 @@ public class NodeDescriptors {
250 } 256 }
251 } else { 257 } else {
252 while (listIterator.hasNext()) { 258 while (listIterator.hasNext()) {
253 - BgpValueType tlv = listIterator.next(); 259 + BgpValueType tlv1 = listIterator.next();
254 log.debug("NodeDescriptor compare subtlv's"); 260 log.debug("NodeDescriptor compare subtlv's");
255 - if (subTlvs.contains(tlv) && ((NodeDescriptors) o).subTlvs.contains(tlv)) { 261 + for (BgpValueType tlv : ((NodeDescriptors) o).subTlvs) {
256 - int result = subTlvs.get(subTlvs.indexOf(tlv)).compareTo( 262 + if (tlv.getType() == tlv1.getType()) {
263 + int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo(
257 ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv))); 264 ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv)));
258 if (result != 0) { 265 if (result != 0) {
259 return result; 266 return result;
260 } 267 }
261 - } else { 268 + tlvFound = true;
269 + break;
270 + }
271 + }
272 + if (!tlvFound) {
262 return 1; 273 return 1;
263 } 274 }
264 } 275 }
......