package com.brentandjody.stenopad;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;

/**
 * Stoke object
 * represents a sequence of steno keys
 */
public class Stroke {

    private static final String STOKE_DELIMITER="/";
    private static final String IMPLICIT_HYPHENS=".*[AOEU\\*50].*";

    public Stroke() {
//TODO:
    }

    public String[] normalize(String input) {
        String[] strokes = input.split(STOKE_DELIMITER);
        List<String> normalized_strokes = new ArrayList<String>();
        for (String stroke : strokes) {
            if (stroke.contains("#")) {
                stroke = stroke.replace("#", "");
                if (stroke.matches(".*[0-9].*")) {
                    stroke = "#"+stroke;
                }
            }
            if (stroke.matches(IMPLICIT_HYPHENS)) {
                stroke.replace("-", "");
            }
            if (stroke.endsWith("-")) {
                stroke = stroke.substring(0,stroke.length() -1);
            }
            normalized_strokes.add(stroke);
        }
        String[] result = new String[normalized_strokes.size()];
        return normalized_strokes.toArray(result);
    }
}

private static final Hashtable<String,String> NUMBER_KEYS = new Hashtable<String, String>() {{
    put("S-", "1-");
    put("T-", "2-");
    put("P-", "3-");
    put("H-", "4-");
    put("A-", "5-");
    put("O-", "0-");
    put("-F", "-6");
    put("-P", "-7");
    put("-L", "-8");
    put("-T", "-9");
}};
    private List<String> convertNumbers(List<String> chord) {
        List<String> result = new ArrayList<String>();
        Boolean numeral = false;
        for (String thisKey : chord) {
            if (NUMBER_KEYS.containsKey(thisKey)) {
                result.add(NUMBER_KEYS.get(thisKey));
                numeral = true;
            } else {
                result.add(thisKey);
            }
        }
        if (numeral) {
            result.remove("#");
        }
        return result;

    }

    private String constructStroke(List<String> chord) {
        String result = "";
        String suffix = "";
        if (! Collections.disjoint(chord, Arrays.asList("A-", "O-", "5-", "0-", "-E", "-U", "*"))) {
            for (String key : chord) {
                result += key.replace("-","");
            }
        } else {
            for (String key : chord) {
                if (key.equals("#") || key.charAt(key.length()-1) == '-') {
                    result += key.replace("-", "");
                }
                if (key.charAt(0) == '-') {
                    suffix += key.replace("-", "");
                }
            }
            if (! suffix.isEmpty()) {
                result += "-"+suffix;
            }
        }
        return result;
    }

@@ -372,16 +372,1001 @@
 0%5D.*%22;%0A%0A
+    private static final Hashtable%3CString,String%3E NUMBER_KEYS = new Hashtable%3CString, String%3E() %7B%7B%0A        put(%22S-%22, %221-%22);%0A        put(%22T-%22, %222-%22);%0A        put(%22P-%22, %223-%22);%0A        put(%22H-%22, %224-%22);%0A        put(%22A-%22, %225-%22);%0A        put(%22O-%22, %220-%22);%0A        put(%22-F%22, %22-6%22);%0A        put(%22-P%22, %22-7%22);%0A        put(%22-L%22, %22-8%22);%0A        put(%22-T%22, %22-9%22);%0A    %7D%7D;%0A%0A    private static final Hashtable%3CString, Integer%3E STENO_KEYS = new Hashtable%3CString, Integer%3E() %7B%7B%0A        put(%22#%22, 0);%0A        put(%22S-%22, 1);%0A        put(%22T-%22, 2);%0A        put(%22K-%22, 3);%0A        put(%22P-%22, 4);%0A        put(%22W-%22, 5);%0A        put(%22H-%22, 6);%0A        put(%22R-%22, 7);%0A        put(%22A-%22, 8);%0A        put(%22O-%22, 9);%0A        put(%22*%22, 10);%0A        put(%22-E%22, 11);%0A        put(%22-U%22, 12);%0A        put(%22-F%22, 13);%0A        put(%22-R%22, 14);%0A        put(%22-P%22, 15);%0A        put(%22-B%22, 16);%0A        put(%22-L%22, 17);%0A        put(%22-G%22, 18);%0A        put(%22-T%22, 19);%0A        put(%22-S%22, 20);%0A        put(%22-D%22, 21);%0A        put(%22-Z%22, 22);%0A    %7D%7D;%0A%0A
     publ
@@ -1379,16 +1379,16 @@
 oke() %7B%0A
-
 //TODO:%0A
@@ -2227,316 +2227,8 @@
 %0A%7D%0A%0A
-private static final Hashtable%3CString,String%3E NUMBER_KEYS = new Hashtable%3CString, String%3E() %7B%7B%0A    put(%22S-%22, %221-%22);%0A    put(%22T-%22, %222-%22);%0A    put(%22P-%22, %223-%22);%0A    put(%22H-%22, %224-%22);%0A    put(%22A-%22, %225-%22);%0A    put(%22O-%22, %220-%22);%0A    put(%22-F%22, %22-6%22);%0A    put(%22-P%22, %22-7%22);%0A    put(%22-L%22, %22-8%22);%0A    put(%22-T%22, %22-9%22);%0A%7D%7D;
 %0A   

Work on Stoke