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 {
...@@ -249,20 +250,24 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> { ...@@ -249,20 +250,24 @@ public class BgpPrefixLSIdentifier implements Comparable<Object> {
249 } else { 250 } else {
250 return -1; 251 return -1;
251 } 252 }
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 - ((BgpPrefixLSIdentifier) o).prefixDescriptor 260 + result = prefixDescriptor.get(prefixDescriptor.indexOf(tlv1)).compareTo(
261 - .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv))); 261 + ((BgpPrefixLSIdentifier) o).prefixDescriptor
262 - if (res != 0) { 262 + .get(((BgpPrefixLSIdentifier) o).prefixDescriptor.indexOf(tlv)));
263 - return res; 263 + if (result != 0) {
264 + return result;
265 + }
266 + tlvFound = true;
267 + break;
264 } 268 }
265 - } else { 269 + }
270 + if (!tlvFound) {
266 return 1; 271 return 1;
267 } 272 }
268 } 273 }
......
...@@ -234,31 +234,42 @@ public class NodeDescriptors { ...@@ -234,31 +234,42 @@ 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;
248 - } else { 254 + } else {
249 - return -1; 255 + return -1;
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()) {
257 - ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv))); 263 + int result = subTlvs.get(subTlvs.indexOf(tlv1)).compareTo(
258 - if (result != 0) { 264 + ((NodeDescriptors) o).subTlvs.get(((NodeDescriptors) o).subTlvs.indexOf(tlv)));
259 - return result; 265 + if (result != 0) {
266 + return result;
267 + }
268 + tlvFound = true;
269 + break;
260 } 270 }
261 - } else { 271 + }
272 + if (!tlvFound) {
262 return 1; 273 return 1;
263 } 274 }
264 } 275 }
......