@Test(dataProvider = "encoder_inputs") public void encode(String input, String expectedOutput) { String output = encoder.encode(input); assertEquals(output, expectedOutput); if (input != null && input.equals(output)) assertSame(input, output, "When no change occurs, the input object should be passed through as is."); }
public String encode(String input) { if (input == null) return ENCODED_NULL; if (input.equals("")) return ENCODED_BLANK; boolean dirty = false; int length = input.length(); StringBuilder output = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '$') { output.append("$$"); dirty = true; continue; } int chAsInt = (int) ch; if (safe.get(chAsInt)) { output.append(ch); continue; } output.append(String.format("$%04x", chAsInt)); dirty = true; } return dirty ? output.toString() : input; }
URLEncoderImpl implements URLEncoder { public String encode(String input) { if (input == null) return ENCODED_NULL; if (input.equals("")) return ENCODED_BLANK; boolean dirty = false; int length = input.length(); StringBuilder output = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '$') { output.append("$$"); dirty = true; continue; } int chAsInt = (int) ch; if (safe.get(chAsInt)) { output.append(ch); continue; } output.append(String.format("$%04x", chAsInt)); dirty = true; } return dirty ? output.toString() : input; } }
URLEncoderImpl implements URLEncoder { public String encode(String input) { if (input == null) return ENCODED_NULL; if (input.equals("")) return ENCODED_BLANK; boolean dirty = false; int length = input.length(); StringBuilder output = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '$') { output.append("$$"); dirty = true; continue; } int chAsInt = (int) ch; if (safe.get(chAsInt)) { output.append(ch); continue; } output.append(String.format("$%04x", chAsInt)); dirty = true; } return dirty ? output.toString() : input; }  }
URLEncoderImpl implements URLEncoder { public String encode(String input) { if (input == null) return ENCODED_NULL; if (input.equals("")) return ENCODED_BLANK; boolean dirty = false; int length = input.length(); StringBuilder output = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '$') { output.append("$$"); dirty = true; continue; } int chAsInt = (int) ch; if (safe.get(chAsInt)) { output.append(ch); continue; } output.append(String.format("$%04x", chAsInt)); dirty = true; } return dirty ? output.toString() : input; }  String encode(String input); String decode(String input); }
URLEncoderImpl implements URLEncoder { public String encode(String input) { if (input == null) return ENCODED_NULL; if (input.equals("")) return ENCODED_BLANK; boolean dirty = false; int length = input.length(); StringBuilder output = new StringBuilder(length * 2); for (int i = 0; i < length; i++) { char ch = input.charAt(i); if (ch == '$') { output.append("$$"); dirty = true; continue; } int chAsInt = (int) ch; if (safe.get(chAsInt)) { output.append(ch); continue; } output.append(String.format("$%04x", chAsInt)); dirty = true; } return dirty ? output.toString() : input; }  String encode(String input); String decode(String input);  }