public static Map<String, List<String>> convertMapOfCommaDelimitedToMapOfList(Map<String, String> collectionAliasMap) { return collectionAliasMap.entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, e -> splitCollections(e.getValue()), (a, b) -> {throw new IllegalStateException(String.format(Locale.ROOT, "Duplicate key %s", b));}, LinkedHashMap::new)); }
/** * Creates a new Aliases instance with the same data as the current one but with a modification based on the * parameters. * <p> * Note that the state in zookeeper is unaffected by this method and the change must still be persisted via * {@link ZkStateReader.AliasesManager#applyModificationAndExportToZk(UnaryOperator)} * * @param alias the alias to update, must not be null * @param collections the comma separated list of collections for the alias, null to remove the alias */ public Aliases cloneWithCollectionAlias(String alias, String collections) { if (alias == null) { throw new NullPointerException("Alias name cannot be null"); } Map<String, Map<String, String>> newColProperties; Map<String, List<String>> newColAliases = new LinkedHashMap<>(this.collectionAliases);//clone to modify if (collections == null) { // REMOVE: newColProperties = new LinkedHashMap<>(this.collectionAliasProperties);//clone to modify newColProperties.remove(alias); newColAliases.remove(alias); } else { newColProperties = this.collectionAliasProperties;// no changes // java representation is a list, so split before adding to maintain consistency newColAliases.put(alias, splitCollections(collections)); // note: unmodifiableList } return new Aliases(newColAliases, newColProperties, zNodeVersion); }