@Test public void testFrozenWithExtraEndingBrackets() { String input = "frozen<list>>>"; String res = Strings.removeFrozenBrackets(input); assertThat(res).isEqualTo("list>>"); }
public static String removeFrozenBrackets(String input) { String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START)); if (input.length() == unfrozen.length()) { return input; } StringBuilder out = new StringBuilder(); OpenBrackets openBrackets = new OpenBrackets(); for (char c : unfrozen.toCharArray()) { switch (c) { case FROZEN_START: openBrackets.addStartBracket(); openBrackets.increaseAll(); break; case '<': openBrackets.increaseAll(); out.append(c); break; case '>': openBrackets.decreaseAll(); if (!openBrackets.removeLastIfClosed()) { out.append(c); } break; default: out.append(c); break; } } return out.toString(); }
Strings { public static String removeFrozenBrackets(String input) { String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START)); if (input.length() == unfrozen.length()) { return input; } StringBuilder out = new StringBuilder(); OpenBrackets openBrackets = new OpenBrackets(); for (char c : unfrozen.toCharArray()) { switch (c) { case FROZEN_START: openBrackets.addStartBracket(); openBrackets.increaseAll(); break; case '<': openBrackets.increaseAll(); out.append(c); break; case '>': openBrackets.decreaseAll(); if (!openBrackets.removeLastIfClosed()) { out.append(c); } break; default: out.append(c); break; } } return out.toString(); } }
Strings { public static String removeFrozenBrackets(String input) { String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START)); if (input.length() == unfrozen.length()) { return input; } StringBuilder out = new StringBuilder(); OpenBrackets openBrackets = new OpenBrackets(); for (char c : unfrozen.toCharArray()) { switch (c) { case FROZEN_START: openBrackets.addStartBracket(); openBrackets.increaseAll(); break; case '<': openBrackets.increaseAll(); out.append(c); break; case '>': openBrackets.decreaseAll(); if (!openBrackets.removeLastIfClosed()) { out.append(c); } break; default: out.append(c); break; } } return out.toString(); } private  Strings(); }
Strings { public static String removeFrozenBrackets(String input) { String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START)); if (input.length() == unfrozen.length()) { return input; } StringBuilder out = new StringBuilder(); OpenBrackets openBrackets = new OpenBrackets(); for (char c : unfrozen.toCharArray()) { switch (c) { case FROZEN_START: openBrackets.addStartBracket(); openBrackets.increaseAll(); break; case '<': openBrackets.increaseAll(); out.append(c); break; case '>': openBrackets.decreaseAll(); if (!openBrackets.removeLastIfClosed()) { out.append(c); } break; default: out.append(c); break; } } return out.toString(); } private  Strings(); static String removeFrozenBrackets(String input); }
Strings { public static String removeFrozenBrackets(String input) { String unfrozen = FROZEN_PATTERN.matcher(input).replaceAll(String.valueOf(FROZEN_START)); if (input.length() == unfrozen.length()) { return input; } StringBuilder out = new StringBuilder(); OpenBrackets openBrackets = new OpenBrackets(); for (char c : unfrozen.toCharArray()) { switch (c) { case FROZEN_START: openBrackets.addStartBracket(); openBrackets.increaseAll(); break; case '<': openBrackets.increaseAll(); out.append(c); break; case '>': openBrackets.decreaseAll(); if (!openBrackets.removeLastIfClosed()) { out.append(c); } break; default: out.append(c); break; } } return out.toString(); } private  Strings(); static String removeFrozenBrackets(String input);  }