@Test public void testGrams() { assertArrayEquals(separateGrams("hello", 1), new String[]{"h", "e", "l", "l", "o"}); assertArrayEquals(separateGrams("hello", 2), new String[]{"he", "el", "ll", "lo"}); assertArrayEquals(separateGrams("hello", 3), new String[]{"hel", "ell", "llo"}); assertArrayEquals(separateGrams("hello", 4), new String[]{"hell", "ello"}); assertArrayEquals(separateGrams("hello", 5), new String[]{"hello"}); assertArrayEquals(separateGrams("hello", 6), EMPTY_STRING_ARRAY); }
public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; }
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } }
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private  Strings(); }
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private  Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); }
Strings { public static String[] separateGrams(String word, int gramSize) { if (gramSize < 1) { throw new IllegalArgumentException("Gram size cannot be smaller than 1"); } if (gramSize > word.length()) { return EMPTY_STRING_ARRAY; } String[] grams = new String[word.length() - gramSize + 1]; for (int i = 0; i <= word.length() - gramSize; i++) { grams[i] = word.substring(i, i + gramSize); } return grams; } private  Strings(); static boolean isNullOrEmpty(String str); static boolean hasText(String s); static boolean allHasText(String... strings); static boolean allNullOrEmpty(String... strings); static String leftTrim(String s); static String rightTrim(String str); static boolean containsNone(String str, String invalidCharsStr); static boolean containsOnly(String str, String allowedChars); static String repeat(char c, int count); static String repeat(String str, int count); static String reverse(String str); static String insertFromLeft(String str, int interval, String stringToInsert); static String insertFromRight(String str, int interval, String stringToInsert); static String rightPad(String str, int size); static String rightPad(String str, int size, char padChar); static String rightPad(String str, int size, String padStr); static String leftPad(String str, int size); static String leftPad(String str, int size, char padChar); static String subStringUntilFirst(String str, String s); static String subStringUntilLast(String str, String s); static String subStringAfterFirst(String str, String s); static String subStringAfterLast(String str, String s); static String leftPad(String str, int size, String padStr); static String whiteSpacesToSingleSpace(String str); static String eliminateWhiteSpaces(String str); static String[] separateGrams(String word, int gramSize); static final String EMPTY_STRING; static final String[] EMPTY_STRING_ARRAY; }