LogFormatter extends Formatter { static StringBuilder swapIdsForNames(StringBuilder hasIds) { StringBuilder result = hasIds; boolean hasVMKey = false; boolean hasClusterKey = false; IntWrapper vmKeyState = new IntWrapper(); IntWrapper clusterKeyState = new IntWrapper(); int nextInbetweenText = -1; do { if (vmKeyState._nextKey >= 0) { vmKeyState._nextKey = hasIds.indexOf(VMID_PREFIX, vmKeyState._nextKey); } if (clusterKeyState._nextKey >= 0) { clusterKeyState._nextKey = hasIds.indexOf(CLUSTERID_PREFIX, clusterKeyState._nextKey); } hasVMKey = vmKeyState._nextKey >= 0; hasClusterKey = clusterKeyState._nextKey >= 0; if (hasVMKey || hasClusterKey) { if (result == hasIds) { result = new StringBuilder(); } if (nextInbetweenText == -1) { nextInbetweenText = 0; } if (hasVMKey && (!hasClusterKey || (vmKeyState._nextKey < clusterKeyState._nextKey))) { nextInbetweenText = substituteIdForName(hasIds, result, _vmIdToNameMapper, vmKeyState, VMID_PREFIX, VMID_POSTFIX, nextInbetweenText); } else if (hasClusterKey && (!hasVMKey || (clusterKeyState._nextKey < vmKeyState._nextKey))) { nextInbetweenText = substituteIdForName(hasIds, result, _clusterIdToNameMapper, clusterKeyState, CLUSTERID_PREFIX, CLUSTERID_POSTFIX, nextInbetweenText); } } } while (hasVMKey || hasClusterKey); if (result != hasIds) { result.append(hasIds.substring(nextInbetweenText)); } return result; } protected  LogFormatter(boolean decorated);  LogFormatter(); @Override String format(LogRecord record); static String constructListOfLoggableVms(Set<String> vmIds); static String constructListOfLoggableClusters(Set<String> clusterIds); static boolean isDetailLogging(Logger logger); static final Map<String, String> _vmIdToNameMapper; static final Map<String, String> _clusterIdToNameMapper; static final String VMID_PREFIX; static final String VMID_POSTFIX; static final String CLUSTERID_PREFIX; static final String CLUSTERID_POSTFIX; static final String NEWLINE; }
@Test public void substitutionTests() { for (String key : testData.keySet()) { String value = testData.get(key); String actual = LogFormatter.swapIdsForNames(new StringBuilder(value)).toString(); assertEquals(value, actual); } }