ConfigUtils { public static String getDefMd5(List<String> lines) { List<String> linesCopy = new ArrayList<>(lines); for (Iterator<String> it = linesCopy.iterator(); it.hasNext(); ) { String line = it.next().trim(); if (! line.startsWith("#") && ! line.equals("")) { if (line.startsWith("version")) { it.remove(); } break; } } StringBuilder sb = new StringBuilder(); for (String line : linesCopy) { line = line.trim(); Matcher m = intPattern.matcher(line); if (m.matches()) { line = line.replaceFirst("\\[,", "[" + intFormattedMin + ","); line = line.replaceFirst(",\\]", "," + intFormattedMax + "]"); } m = doublePattern.matcher(line); if (m.matches()) { line = line.replaceFirst("\\[,", "[" + doubleFormattedMin + ","); line = line.replaceFirst(",\\]", "," + doubleFormattedMax + "]"); } if (line.contains("#")) { line = line.substring(0, line.indexOf("#")); line = line.trim(); } if (line.length() > 0) { line = stripSpaces(line); m = spaceBeforeCommaPatter.matcher(line); line = m.replaceAll(","); sb.append(line).append("\n"); } } return getMd5(sb.toString()); }  static String getMd5(ConfigPayload payload); static String getMd5(String input); static String getMd5(Utf8Array input); static String getMd5(byte[] input); static String stripSpaces(String str); static String getDefMd5(List<String> lines); static String getDefNamespace(Reader in); static Tuple2<String, String> getNameAndNamespaceFromString(String nameDotNamespace); static ConfigDefinitionKey createConfigDefinitionKeyFromZKString(String nodeName); static ConfigDefinitionKey createConfigDefinitionKeyFromDefFile(File file); static String escapeConfigFormatValue(String input); static String getDefMd5FromRequest(String defMd5, List<String> defContent); static String getCanonicalHostName(); static String getEnvValue(String defaultValue, String... envVars); static boolean isGenerationNewer(long newGen, long oldGen);  }
@Test public void testGetDefMd5() { String expectedMd5 = "a29038b17c727dabc572a967a508dc1f"; List<String> lines = new ArrayList<>(); lines.add("a"); lines.add("foo=1 # a comment"); lines.add("int a default=1 range = [,]"); lines.add(""); lines.add("double b default=1.0 range = [,]"); lines.add("collectiontype enum { SINGLE, ARRAY, WEIGHTEDSET } default=SINGLE"); assertThat(ConfigUtils.getDefMd5(lines), is(expectedMd5)); lines.clear(); lines.add("a "); lines.add("foo=1"); lines.add("int a default=1 range = [-2147483648,2147483647]"); lines.add("double b default=1.0 range = [-100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000," + "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000]"); lines.add("collectiontype enum { SINGLE , ARRAY , WEIGHTEDSET } default=SINGLE"); assertThat(ConfigUtils.getDefMd5(lines), is(expectedMd5)); }