class RoutesAnswererUtil {

  static Multiset<Row> getBgpRibRoutes(
      Table<String, String, Set<Bgpv4Route>> bgpRoutes,
      RibProtocol ribProtocol,
      Set<String> matchingNodes,
      @Nullable Prefix network,
      RoutingProtocolSpecifier protocolSpec,
      String vrfRegex) {
    Multiset<Row> rows = HashMultiset.create();
    Map<String, ColumnMetadata> columnMetadataMap = getTableMetadata(ribProtocol).toColumnMap();
    Pattern compiledVrfRegex = Pattern.compile(vrfRegex);
    matchingNodes.forEach(
        hostname ->
            bgpRoutes
                .row(hostname)
                .forEach(
                    (vrfName, routes) -> {
                      if (compiledVrfRegex.matcher(vrfName).matches()) {
                        routes.stream()
                            .filter(
                                route ->
                                    (network == null || network.equals(route.getNetwork()))
                                        && protocolSpec
                                            .getProtocols()
                                            .contains(route.getProtocol()))
                            .forEach(
                                route ->
                                    rows.add(
                                        bgpRouteToRow(
                                            hostname, vrfName, route, columnMetadataMap)));
                      }
                    }));
    return rows;
  }

}