CellInfoUtil { public static Map<Cell, String> extractCellRoutingFromCellSpecification(List<Cell> cells, String cellRoutingSpecification) { Map<String, Cell> cellsByName = CollectionsExt.indexBy(cells, Cell::getName); return Arrays.stream(cellRoutingSpecification.split(CELL_ROUTE_DELIM)) .filter(cellRoutingSpec -> cellRoutingSpec.contains(CELL_ROUTE_RULE_DELIM)) .map(CellRoutingSpec::new) .filter(spec -> isCellConfigured(cellsByName, spec)) .collect(Collectors.toMap( spec -> cellsByName.get(spec.getCellName()), CellRoutingSpec::getRoutingRule, CellInfoUtil::mergeKeepingFirst, LinkedHashMap::new )); }  static List<Cell> extractCellsFromCellSpecification(String cellsSpecification); static Map<Cell, String> extractCellRoutingFromCellSpecification(List<Cell> cells, String cellRoutingSpecification);  }
@Test public void duplicatedRoutingRulesAreIgnored() { Cell cell = new Cell("cell1", "1"); String cellsSpec = "cell1=(app1.*);cell1=(app2.*)"; Map<Cell, String> routingRules = CellInfoUtil.extractCellRoutingFromCellSpecification( Collections.singletonList(cell), cellsSpec ); assertThat(routingRules).isNotNull(); assertThat(routingRules).hasSize(1); assertThat(routingRules.get(cell)).isEqualTo("(app1.*)"); }