Skip to content

Instantly share code, notes, and snippets.

@drunkel
Last active February 10, 2016 07:33
Show Gist options
  • Save drunkel/9700a233abe81a8ee834 to your computer and use it in GitHub Desktop.
Save drunkel/9700a233abe81a8ee834 to your computer and use it in GitHub Desktop.
Morse code mapping from character to pattern string in java (because nobody should ever have to type this out again)
public class MorseMapping {
public static final Map<Character, String> MORSE_MAPPING;
static {
MORSE_MAPPING = new HashMap<>();
MORSE_MAPPING.put('A', ".-");
MORSE_MAPPING.put('B', "-...");
MORSE_MAPPING.put('C', "-.-.");
MORSE_MAPPING.put('D', "-..");
MORSE_MAPPING.put('E', ".");
MORSE_MAPPING.put('F', "..-.");
MORSE_MAPPING.put('G', "--.");
MORSE_MAPPING.put('H', "....");
MORSE_MAPPING.put('I', "..");
MORSE_MAPPING.put('J', ".---");
MORSE_MAPPING.put('K', "-.-");
MORSE_MAPPING.put('L', ".-..");
MORSE_MAPPING.put('M', "--");
MORSE_MAPPING.put('N', "-.");
MORSE_MAPPING.put('O', "---");
MORSE_MAPPING.put('P', ".--.");
MORSE_MAPPING.put('Q', "--.-");
MORSE_MAPPING.put('R', ".-.");
MORSE_MAPPING.put('S', "...");
MORSE_MAPPING.put('T', "-");
MORSE_MAPPING.put('U', "..-");
MORSE_MAPPING.put('V', "...-");
MORSE_MAPPING.put('W', ".--");
MORSE_MAPPING.put('X', "-..-");
MORSE_MAPPING.put('Y', "-.--");
MORSE_MAPPING.put('Z', "--..");
MORSE_MAPPING.put('1', ".----");
MORSE_MAPPING.put('2', "..---");
MORSE_MAPPING.put('3', "...--");
MORSE_MAPPING.put('4', "....-");
MORSE_MAPPING.put('5', ".....");
MORSE_MAPPING.put('6', "-....");
MORSE_MAPPING.put('7', "--...");
MORSE_MAPPING.put('8', "---..");
MORSE_MAPPING.put('9', "----.");
MORSE_MAPPING.put('0', "-----");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment