class MacroSubstitutor {

  String substituteMacro(String inputValue) {

    if (inputValue == null) {
      return inputValue;
    }

    int start = 0;
    int idx = inputValue.indexOf(START_MACRO);
    if (idx == -1) {
      return inputValue;
    }

    StringBuilder retStr = new StringBuilder();

    while (idx != -1) {
      retStr.append(inputValue.substring(start, idx));

      int macroIdx = idx;
      int end = inputValue.indexOf(END_MACRO, macroIdx);
      if (end == -1) {
        start = idx;
        idx = -1;
        continue;
      }

      String macro = inputValue.substring(macroIdx + 2, end);
      String macroVal = resolveMacroValue(macro);

      if (macroVal != null) {
        retStr.append(macroVal);
      }

      start = end + 1;
      idx = inputValue.indexOf(START_MACRO, start);
    }

    retStr.append(inputValue.substring(start));
    return retStr.toString();
  }

  public  MacroSubstitutor(
      int id, String serverName, String clusterName, String domainName, String machineName);

}