/** * Evaluate the expression for a given cluster. Looks up the service name in the cluster to find all nodes that run * the service, then formats and joins all results into a string. * * @param cluster the cluster to evaluate for. * @param clusterNodes the nodes of the cluster to evaluate for. * @param node the node of the cluster to evaluate the expression for. * @return the replacement string for the expression, or null if the service required for replacement is not in * the cluster. * @throws IncompleteClusterException if a node is missing the property that is required for the lookup type. */ public String evaluate(Cluster cluster, Set<Node> clusterNodes, Node node) throws IncompleteClusterException { StringBuilder builder = new StringBuilder(); List<String> parts = evaluator.evaluate(cluster, clusterNodes, node); if (parts == null) { return null; } if (!parts.isEmpty()) { format(parts.get(0), builder); for (int i = 1; i < parts.size(); i++) { builder.append(separator); format(parts.get(i), builder); } } return builder.toString(); }