@Test public void test() { Map<String, String> map = new HashMap<String, String>(); map.put("telnet-port", "" + 9999); map.put("aaa--bbb", "fff"); map.put("123", "123"); map.put("123-", "123"); map.put("123-abc", "123"); map.put("xxx-", "xxx"); map = StringUtils.removeDashKey(map); Assertions.assertThat(map).containsEntry("telnetPort", "" + 9999); Assertions.assertThat(map).containsEntry("aaa-Bbb", "fff"); Assertions.assertThat(map).containsEntry("123", "123"); Assertions.assertThat(map).containsEntry("123-", "123"); Assertions.assertThat(map).containsEntry("123Abc", "123"); Assertions.assertThat(map).containsEntry("xxx-", "xxx"); }
public static Map<String, String> removeDashKey(Map<String, String> map) { Map<String, String> result = new HashMap<String, String>(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); if (key.contains("-")) { StringBuilder sb = new StringBuilder(key.length()); for (int i = 0; i < key.length(); i++) { if (key.charAt(i) == '-' && (i + 1 < key.length()) && Character.isAlphabetic(key.charAt(i + 1))) { ++i; char upperChar = Character.toUpperCase(key.charAt(i)); sb.append(upperChar); } else { sb.append(key.charAt(i)); } } key = sb.toString(); } result.put(key, entry.getValue()); } return result; }
StringUtils { public static Map<String, String> removeDashKey(Map<String, String> map) { Map<String, String> result = new HashMap<String, String>(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); if (key.contains("-")) { StringBuilder sb = new StringBuilder(key.length()); for (int i = 0; i < key.length(); i++) { if (key.charAt(i) == '-' && (i + 1 < key.length()) && Character.isAlphabetic(key.charAt(i + 1))) { ++i; char upperChar = Character.toUpperCase(key.charAt(i)); sb.append(upperChar); } else { sb.append(key.charAt(i)); } } key = sb.toString(); } result.put(key, entry.getValue()); } return result; } }
StringUtils { public static Map<String, String> removeDashKey(Map<String, String> map) { Map<String, String> result = new HashMap<String, String>(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); if (key.contains("-")) { StringBuilder sb = new StringBuilder(key.length()); for (int i = 0; i < key.length(); i++) { if (key.charAt(i) == '-' && (i + 1 < key.length()) && Character.isAlphabetic(key.charAt(i + 1))) { ++i; char upperChar = Character.toUpperCase(key.charAt(i)); sb.append(upperChar); } else { sb.append(key.charAt(i)); } } key = sb.toString(); } result.put(key, entry.getValue()); } return result; }  }
StringUtils { public static Map<String, String> removeDashKey(Map<String, String> map) { Map<String, String> result = new HashMap<String, String>(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); if (key.contains("-")) { StringBuilder sb = new StringBuilder(key.length()); for (int i = 0; i < key.length(); i++) { if (key.charAt(i) == '-' && (i + 1 < key.length()) && Character.isAlphabetic(key.charAt(i + 1))) { ++i; char upperChar = Character.toUpperCase(key.charAt(i)); sb.append(upperChar); } else { sb.append(key.charAt(i)); } } key = sb.toString(); } result.put(key, entry.getValue()); } return result; }  static Map<String, String> removeDashKey(Map<String, String> map); }
StringUtils { public static Map<String, String> removeDashKey(Map<String, String> map) { Map<String, String> result = new HashMap<String, String>(); for (Entry<String, String> entry : map.entrySet()) { String key = entry.getKey(); if (key.contains("-")) { StringBuilder sb = new StringBuilder(key.length()); for (int i = 0; i < key.length(); i++) { if (key.charAt(i) == '-' && (i + 1 < key.length()) && Character.isAlphabetic(key.charAt(i + 1))) { ++i; char upperChar = Character.toUpperCase(key.charAt(i)); sb.append(upperChar); } else { sb.append(key.charAt(i)); } } key = sb.toString(); } result.put(key, entry.getValue()); } return result; }  static Map<String, String> removeDashKey(Map<String, String> map);  }