@Test(expected = WrongCharaterException.class) public void shouldThrownExceptionIfSuffixContainWrongCharater() { decoderEncoder.encode("1"); }
public Integer encode(String string) { if (string.length() > WORD_PART_LENGHT) throw new SuffixToLongException("Suffix length should not be greater then " + WORD_PART_LENGHT + " " + string); int result = 0; for (int i = 0; i < string.length(); i++) { int c = 0 + string.charAt(i) - RUSSIAN_SMALL_LETTER_OFFSET; if (c == 45 - RUSSIAN_SMALL_LETTER_OFFSET) { c = DASH_CODE; } if (c == EE_CHAR) c = E_CHAR; if (c < 0 || c > 33) throw new WrongCharaterException("Symblo " + string.charAt(i) + " is not small cirillic letter"); result = result * 34 + c; } for (int i = string.length(); i < WORD_PART_LENGHT; i++) { result *= 34; } return result; }
RussianLetterDecoderEncoder implements LetterDecoderEncoder { public Integer encode(String string) { if (string.length() > WORD_PART_LENGHT) throw new SuffixToLongException("Suffix length should not be greater then " + WORD_PART_LENGHT + " " + string); int result = 0; for (int i = 0; i < string.length(); i++) { int c = 0 + string.charAt(i) - RUSSIAN_SMALL_LETTER_OFFSET; if (c == 45 - RUSSIAN_SMALL_LETTER_OFFSET) { c = DASH_CODE; } if (c == EE_CHAR) c = E_CHAR; if (c < 0 || c > 33) throw new WrongCharaterException("Symblo " + string.charAt(i) + " is not small cirillic letter"); result = result * 34 + c; } for (int i = string.length(); i < WORD_PART_LENGHT; i++) { result *= 34; } return result; } }
RussianLetterDecoderEncoder implements LetterDecoderEncoder { public Integer encode(String string) { if (string.length() > WORD_PART_LENGHT) throw new SuffixToLongException("Suffix length should not be greater then " + WORD_PART_LENGHT + " " + string); int result = 0; for (int i = 0; i < string.length(); i++) { int c = 0 + string.charAt(i) - RUSSIAN_SMALL_LETTER_OFFSET; if (c == 45 - RUSSIAN_SMALL_LETTER_OFFSET) { c = DASH_CODE; } if (c == EE_CHAR) c = E_CHAR; if (c < 0 || c > 33) throw new WrongCharaterException("Symblo " + string.charAt(i) + " is not small cirillic letter"); result = result * 34 + c; } for (int i = string.length(); i < WORD_PART_LENGHT; i++) { result *= 34; } return result; }  }
RussianLetterDecoderEncoder implements LetterDecoderEncoder { public Integer encode(String string) { if (string.length() > WORD_PART_LENGHT) throw new SuffixToLongException("Suffix length should not be greater then " + WORD_PART_LENGHT + " " + string); int result = 0; for (int i = 0; i < string.length(); i++) { int c = 0 + string.charAt(i) - RUSSIAN_SMALL_LETTER_OFFSET; if (c == 45 - RUSSIAN_SMALL_LETTER_OFFSET) { c = DASH_CODE; } if (c == EE_CHAR) c = E_CHAR; if (c < 0 || c > 33) throw new WrongCharaterException("Symblo " + string.charAt(i) + " is not small cirillic letter"); result = result * 34 + c; } for (int i = string.length(); i < WORD_PART_LENGHT; i++) { result *= 34; } return result; }  Integer encode(String string); int[] encodeToArray(String s); String decodeArray(int[] array); String decode(Integer suffixN); boolean checkCharacter(char c); boolean checkString(String word); String cleanString(String s); }
RussianLetterDecoderEncoder implements LetterDecoderEncoder { public Integer encode(String string) { if (string.length() > WORD_PART_LENGHT) throw new SuffixToLongException("Suffix length should not be greater then " + WORD_PART_LENGHT + " " + string); int result = 0; for (int i = 0; i < string.length(); i++) { int c = 0 + string.charAt(i) - RUSSIAN_SMALL_LETTER_OFFSET; if (c == 45 - RUSSIAN_SMALL_LETTER_OFFSET) { c = DASH_CODE; } if (c == EE_CHAR) c = E_CHAR; if (c < 0 || c > 33) throw new WrongCharaterException("Symblo " + string.charAt(i) + " is not small cirillic letter"); result = result * 34 + c; } for (int i = string.length(); i < WORD_PART_LENGHT; i++) { result *= 34; } return result; }  Integer encode(String string); int[] encodeToArray(String s); String decodeArray(int[] array); String decode(Integer suffixN); boolean checkCharacter(char c); boolean checkString(String word); String cleanString(String s); static final int RUSSIAN_SMALL_LETTER_OFFSET; static final int WORD_PART_LENGHT; static final int EE_CHAR; static final int E_CHAR; static final int DASH_CHAR; static final int DASH_CODE; }