import java.util.HashMap;
import java.util.Map;

public class RotationalCipher {

  private int shift;
  private Map<Character, Character> cipher;

  private static int ALPHABET_LENGTH = 26;
  private static char[] LOWERCASE_ALPHABET = "abcdefghijklmnopqrstuvwxyz".toCharArray();
  private static char[] UPPERCASE_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();

  public RotationalCipher(int shift) {
    this.shift = shift;
    this.cipher = generateCipher();
  }

  public String rotate(String text) {
    StringBuilder encrypted = new StringBuilder(text.length());

    for(char c: text.toCharArray()) {
      encrypted.append(encryptChar(c));
    }

    return encrypted.toString();
  }

  private Map<Character, Character> generateCipher() {
    char[] lowercaseRotatedAlphabet = rotateAlphabet(LOWERCASE_ALPHABET);
    char[] uppercaseRotatedAlphabet = rotateAlphabet(UPPERCASE_ALPHABET);

    Map<Character, Character> cipher = new HashMap<>();

    for (int i = 0; i < ALPHABET_LENGTH; i++) {
      cipher.put(lowercaseRotatedAlphabet[i], LOWERCASE_ALPHABET[i]);
      cipher.put(uppercaseRotatedAlphabet[i], UPPERCASE_ALPHABET[i]);
    }

    return cipher;
  }

  private char[] rotateAlphabet(char[] alphabet) {
    char[] rotated = new char[alphabet.length];

    for (int i = 0; i < alphabet.length; i++) {
      rotated[(i + shift) % alphabet.length] = alphabet[i];
    }

    return rotated;
  }

  private Character encryptChar(Character c) {
    return cipher.containsKey(c) ? this.cipher.get(c) : c;
  }

}

@@ -444,21 +444,42 @@
 ipher = 
-gener
+new HashMap%3C%3E();%0A    popul
 ateCiphe
@@ -716,36 +716,32 @@
 %0A  %7D%0A%0A  private 
-Map%3C
 Character, Chara
@@ -737,44 +737,40 @@
 cter
-, Character%3E gene
+ encryptChar(Cha
 ra
+c
 te
-Cipher(
+r c
 ) %7B%0A    
 char
@@ -769,304 +769,126 @@
     
-char%5B%5D lowercaseRotatedAlphabet = rotateAlphabet(LOWERCASE_ALPHABET);%0A    char%5B%5D uppercaseRotatedAlphabet = rotateAlphabet(UPPERCASE_ALPHABET);%0A%0A    Map%3CCharacter, Character%3E cipher = new HashMap%3C%3E();%0A%0A    for (int i = 0; i %3C ALPHABET_LENGTH; i++) %7B%0A      cipher.put(lowercaseRotatedAlphabet%5Bi%5D, 
+return cipher.containsKey(c) ? this.cipher.get(c) : c;%0A  %7D%0A%0A  private void populateCipher() %7B%0A    addAlphabetToCipher(
 LOWE
@@ -905,460 +905,240 @@
 ABET
-%5Bi%5D
 );%0A    
-  cipher.put(uppercaseRotatedAlphabet%5Bi%5D, UPPERCASE_ALPHABET%5Bi%5D);%0A    %7D%0A%0A    return cipher;%0A  %7D%0A%0A  private char%5B%5D rotateAlphabet(char%5B%5D alphabet) %7B%0A    char%5B%5D rotated = new char%5Balphabet.length%5D;%0A%0A    for (int i = 0; i %3C alphabet.length; i++) %7B%0A      rotated%5B(i + shift) %25 alphabet.length%5D = alphabet%5Bi%5D;%0A    %7D%0A%0A    return rotated;%0A  %7D%0A%0A  private Character encryptChar(Character c) %7B%0A    return cipher.containsKey(c) ? this.cipher.get(c) : c;
+addAlphabetToCipher(UPPERCASE_ALPHABET);%0A  %7D%0A%0A  private void addAlphabetToCipher(char%5B%5D alphabet) %7B%0A    for (int i = 0; i %3C alphabet.length; i++) %7B%0A      cipher.put(alphabet%5Bi%5D, alphabet%5B(i + shift) %25 alphabet.length%5D);%0A    %7D
 %0A  %7D

Refactor cipher creation