@Test public void testRepetition() { assertEquals("wewewe", EncodingUtils.repeat("we", 3)); }
public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1: return repeat(str.charAt(0), repeat); case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } }
EncodingUtils { public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1: return repeat(str.charAt(0), repeat); case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } } }
EncodingUtils { public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1: return repeat(str.charAt(0), repeat); case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } } private  EncodingUtils(); }
EncodingUtils { public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1: return repeat(str.charAt(0), repeat); case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } } private  EncodingUtils(); static String escapeBackticks(String s); static String escapeSingleQuotes(String s); static String escapeIdentifier(String s); static String encodeObjectToString(Serializable obj); static T decodeStringToObject(String base64String, Class<T> baseClass); static T decodeStringToObject(String base64String, Class<T> baseClass, ClassLoader classLoader); static Class<?> loadClass(String qualifiedName, ClassLoader classLoader); static Class<?> loadClass(String qualifiedName); static String encodeBytesToBase64(byte[] bytes); static byte[] decodeBase64ToBytes(String base64); static String encodeStringToBase64(String string); static String decodeBase64ToString(String base64); static byte[] md5(String string); static String hex(String string); static String hex(byte[] bytes); static String objectToString(Object object); static String repeat(final String str, final int repeat); static String repeat(final char ch, final int repeat); static String escapeJava(String str); }
EncodingUtils { public static String repeat(final String str, final int repeat) { if (str == null) { return null; } if (repeat <= 0) { return EMPTY; } final int inputLength = str.length(); if (repeat == 1 || inputLength == 0) { return str; } if (inputLength == 1 && repeat <= PAD_LIMIT) { return repeat(str.charAt(0), repeat); } final int outputLength = inputLength * repeat; switch (inputLength) { case 1: return repeat(str.charAt(0), repeat); case 2: final char ch0 = str.charAt(0); final char ch1 = str.charAt(1); final char[] output2 = new char[outputLength]; for (int i = repeat * 2 - 2; i >= 0; i--, i--) { output2[i] = ch0; output2[i + 1] = ch1; } return new String(output2); default: final StringBuilder buf = new StringBuilder(outputLength); for (int i = 0; i < repeat; i++) { buf.append(str); } return buf.toString(); } } private  EncodingUtils(); static String escapeBackticks(String s); static String escapeSingleQuotes(String s); static String escapeIdentifier(String s); static String encodeObjectToString(Serializable obj); static T decodeStringToObject(String base64String, Class<T> baseClass); static T decodeStringToObject(String base64String, Class<T> baseClass, ClassLoader classLoader); static Class<?> loadClass(String qualifiedName, ClassLoader classLoader); static Class<?> loadClass(String qualifiedName); static String encodeBytesToBase64(byte[] bytes); static byte[] decodeBase64ToBytes(String base64); static String encodeStringToBase64(String string); static String decodeBase64ToString(String base64); static byte[] md5(String string); static String hex(String string); static String hex(byte[] bytes); static String objectToString(Object object); static String repeat(final String str, final int repeat); static String repeat(final char ch, final int repeat); static String escapeJava(String str);  }