@Test public void testAlignRtRowAttrsLeadingNulls() { RouteRowAttribute rra1 = RouteRowAttribute.builder().setNextHop("node1").build(); RouteRowAttribute rra2 = RouteRowAttribute.builder().setNextHop("node2").build(); RouteRowAttribute rra3 = RouteRowAttribute.builder().setNextHop("node3").build(); List<List<RouteRowAttribute>> alignedRouteRowattrs = alignRouteRowAttributes(ImmutableList.of(rra3), ImmutableList.of(rra1, rra2, rra3)); List<List<RouteRowAttribute>> expectedOutput = ImmutableList.of( Lists.newArrayList(null, rra1), Lists.newArrayList(null, rra2), Lists.newArrayList(rra3, rra3)); assertThat(alignedRouteRowattrs, equalTo(expectedOutput)); }
static List<List<RouteRowAttribute>> alignRouteRowAttributes( List<RouteRowAttribute> routeRowAttributes1, List<RouteRowAttribute> routeRowAttributes2) { List<List<RouteRowAttribute>> alignedRouteRowAttrs = new ArrayList<>(); int i = 0; int j = 0; while (i < routeRowAttributes1.size() && j < routeRowAttributes2.size()) { RouteRowAttribute routeRowAttribute1 = routeRowAttributes1.get(i); RouteRowAttribute routeRowAttribute2 = routeRowAttributes2.get(j); if (routeRowAttribute1.compareTo(routeRowAttribute2) < 0) { i++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, null)); } else if (routeRowAttribute1.compareTo(routeRowAttribute2) > 0) { j++; alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttribute2)); } else { i++; j++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, routeRowAttribute2)); } } while (i < routeRowAttributes1.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttributes1.get(i++), null)); } while (j < routeRowAttributes2.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttributes2.get(j++))); } return alignedRouteRowAttrs; }
RoutesAnswererUtil { static List<List<RouteRowAttribute>> alignRouteRowAttributes( List<RouteRowAttribute> routeRowAttributes1, List<RouteRowAttribute> routeRowAttributes2) { List<List<RouteRowAttribute>> alignedRouteRowAttrs = new ArrayList<>(); int i = 0; int j = 0; while (i < routeRowAttributes1.size() && j < routeRowAttributes2.size()) { RouteRowAttribute routeRowAttribute1 = routeRowAttributes1.get(i); RouteRowAttribute routeRowAttribute2 = routeRowAttributes2.get(j); if (routeRowAttribute1.compareTo(routeRowAttribute2) < 0) { i++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, null)); } else if (routeRowAttribute1.compareTo(routeRowAttribute2) > 0) { j++; alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttribute2)); } else { i++; j++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, routeRowAttribute2)); } } while (i < routeRowAttributes1.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttributes1.get(i++), null)); } while (j < routeRowAttributes2.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttributes2.get(j++))); } return alignedRouteRowAttrs; } }
RoutesAnswererUtil { static List<List<RouteRowAttribute>> alignRouteRowAttributes( List<RouteRowAttribute> routeRowAttributes1, List<RouteRowAttribute> routeRowAttributes2) { List<List<RouteRowAttribute>> alignedRouteRowAttrs = new ArrayList<>(); int i = 0; int j = 0; while (i < routeRowAttributes1.size() && j < routeRowAttributes2.size()) { RouteRowAttribute routeRowAttribute1 = routeRowAttributes1.get(i); RouteRowAttribute routeRowAttribute2 = routeRowAttributes2.get(j); if (routeRowAttribute1.compareTo(routeRowAttribute2) < 0) { i++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, null)); } else if (routeRowAttribute1.compareTo(routeRowAttribute2) > 0) { j++; alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttribute2)); } else { i++; j++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, routeRowAttribute2)); } } while (i < routeRowAttributes1.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttributes1.get(i++), null)); } while (j < routeRowAttributes2.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttributes2.get(j++))); } return alignedRouteRowAttrs; }  }
RoutesAnswererUtil { static List<List<RouteRowAttribute>> alignRouteRowAttributes( List<RouteRowAttribute> routeRowAttributes1, List<RouteRowAttribute> routeRowAttributes2) { List<List<RouteRowAttribute>> alignedRouteRowAttrs = new ArrayList<>(); int i = 0; int j = 0; while (i < routeRowAttributes1.size() && j < routeRowAttributes2.size()) { RouteRowAttribute routeRowAttribute1 = routeRowAttributes1.get(i); RouteRowAttribute routeRowAttribute2 = routeRowAttributes2.get(j); if (routeRowAttribute1.compareTo(routeRowAttribute2) < 0) { i++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, null)); } else if (routeRowAttribute1.compareTo(routeRowAttribute2) > 0) { j++; alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttribute2)); } else { i++; j++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, routeRowAttribute2)); } } while (i < routeRowAttributes1.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttributes1.get(i++), null)); } while (j < routeRowAttributes2.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttributes2.get(j++))); } return alignedRouteRowAttrs; }  static Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> groupRoutes(
          SortedMap<String, SortedMap<String, GenericRib<T>>> ribs,
          Set<String> matchingNodes,
          @Nullable Prefix network,
          String vrfRegex,
          RoutingProtocolSpecifier protocolSpec,
          @Nullable Map<Ip, Set<String>> ipOwners); static List<DiffRoutesOutput> getRoutesDiff(
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase,
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef); }
RoutesAnswererUtil { static List<List<RouteRowAttribute>> alignRouteRowAttributes( List<RouteRowAttribute> routeRowAttributes1, List<RouteRowAttribute> routeRowAttributes2) { List<List<RouteRowAttribute>> alignedRouteRowAttrs = new ArrayList<>(); int i = 0; int j = 0; while (i < routeRowAttributes1.size() && j < routeRowAttributes2.size()) { RouteRowAttribute routeRowAttribute1 = routeRowAttributes1.get(i); RouteRowAttribute routeRowAttribute2 = routeRowAttributes2.get(j); if (routeRowAttribute1.compareTo(routeRowAttribute2) < 0) { i++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, null)); } else if (routeRowAttribute1.compareTo(routeRowAttribute2) > 0) { j++; alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttribute2)); } else { i++; j++; alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttribute1, routeRowAttribute2)); } } while (i < routeRowAttributes1.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(routeRowAttributes1.get(i++), null)); } while (j < routeRowAttributes2.size()) { alignedRouteRowAttrs.add(Lists.newArrayList(null, routeRowAttributes2.get(j++))); } return alignedRouteRowAttrs; }  static Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> groupRoutes(
          SortedMap<String, SortedMap<String, GenericRib<T>>> ribs,
          Set<String> matchingNodes,
          @Nullable Prefix network,
          String vrfRegex,
          RoutingProtocolSpecifier protocolSpec,
          @Nullable Map<Ip, Set<String>> ipOwners); static List<DiffRoutesOutput> getRoutesDiff(
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInBase,
      Map<RouteRowKey, Map<RouteRowSecondaryKey, SortedSet<RouteRowAttribute>>> routesInRef);  }