Mercurial > 510Connectbot
changeset 107:afe6962769b9
use hash map rather than linear search thru arrays
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 11:43:08 -0700 |
parents | 12425771714d |
children | ae3092cd9cbf |
files | src/org/tn5250j/TN5250jConstants.java src/org/tn5250j/framework/tn5250/Screen5250.java |
diffstat | 2 files changed, 127 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/src/org/tn5250j/TN5250jConstants.java Wed Jun 18 10:38:46 2014 -0700 +++ b/src/org/tn5250j/TN5250jConstants.java Wed Jun 18 11:43:08 2014 -0700 @@ -20,6 +20,7 @@ */ package org.tn5250j; +import java.util.HashMap; public interface TN5250jConstants { @@ -27,7 +28,7 @@ public static final String tn5250jRelease = "0"; public static final String tn5250jVersion = ".7"; public static final String tn5250jSubVer= ".3"; - + public static final String VERSION_INFO = tn5250jRelease + tn5250jVersion + tn5250jSubVer; // STATE @@ -184,51 +185,128 @@ public static final int PF23 = 0xBB; public static final int PF24 = 0xBC; - public static final String mnemonicData[] = { - "[backspace]", "[backtab]", "[up]", "[down]", "[left]", - "[right]", "[delete]", "[tab]", "[eof]", "[eraseeof]", - "[erasefld]", "[insert]", "[home]", "[keypad0]", "[keypad1]", - "[keypad2]", "[keypad3]", "[keypad4]", "[keypad5]", "[keypad6]", - "[keypad7]", "[keypad8]", "[keypad9]", "[keypad.]", "[keypad,]", - "[keypad-]", "[fldext]", "[field+]", "[field-]", "[bof]", - "[enter]","[pf1]","[pf2]","[pf3]","[pf4]", - "[pf5]","[pf6]","[pf7]","[pf8]","[pf9]", - "[pf10]","[pf11]","[pf12]","[pf13]","[pf14]", - "[pf15]","[pf16]","[pf17]","[pf18]","[pf19]", - "[pf20]","[pf21]","[pf22]","[pf23]","[pf24]", - "[clear]", "[help]", "[pgup]", "[pgdown]", "[rollleft]", - "[rollright]", "[hostprint]", "[pa1]", "[pa2]", "[pa3]", - "[sysreq]","[reset]","[nextword]", "[prevword]", "[copy]", - "[paste]","[attn]","[markup]", "[markdown]", "[markleft]", - "[markright]","[dupfield]","[newline]","[jumpnext]","[jumpprev]", - "[opennew]","[togcon]","[hotspots]","[gui]","[dspmsgs]", - "[dspattr]","[print]","[cursor]","[debug]","[close]", - "[transfer]","[e-mail]","[runscript]","[spoolfile]","[quick-mail]", - "[open-same]","[fastcursordown]","[fastcursorup]","[fastcursorright]","[fastcursorleft]" - }; + public static final HashMap<String,Integer> mnemonicMap = new HashMap<String,Integer>(); + static { + mnemonicMap.put("[backspace]", 1001); + mnemonicMap.put("[backtab]", 1002); + mnemonicMap.put("[up]", 1003); + mnemonicMap.put("[down]", 1004); + mnemonicMap.put("[left]", 1005); + + mnemonicMap.put("[right]", 1006); + mnemonicMap.put("[delete]", 1007); + mnemonicMap.put("[tab]", 1008); + mnemonicMap.put("[eof]", 1009); + mnemonicMap.put("[eraseeof]", 1010); + + mnemonicMap.put("[erasefld]", 1011); + mnemonicMap.put("[insert]", 1012); + mnemonicMap.put("[home]", 1013); + mnemonicMap.put("[keypad0]", 1014); + mnemonicMap.put("[keypad1]", 1015); + + mnemonicMap.put("[keypad2]", 1016); + mnemonicMap.put("[keypad3]", 1017); + mnemonicMap.put("[keypad4]", 1018); + mnemonicMap.put("[keypad5]", 1019); + mnemonicMap.put("[keypad6]", 1020); + + mnemonicMap.put("[keypad7]", 1021); + mnemonicMap.put("[keypad8]", 1022); + mnemonicMap.put("[keypad9]", 1023); + mnemonicMap.put("[keypad.]", 1024); + mnemonicMap.put("[keypad,]", 1025); + + mnemonicMap.put("[keypad-]", 1026); + mnemonicMap.put("[fldext]", 1027); + mnemonicMap.put("[field+]", 1028); + mnemonicMap.put("[field-]", 1029); + mnemonicMap.put("[bof]", 1030); + + mnemonicMap.put("[enter]", 0xF1); + mnemonicMap.put("[pf1]", 0x31); + mnemonicMap.put("[pf2]", 0x32); + mnemonicMap.put("[pf3]", 0x33); + mnemonicMap.put("[pf4]", 0x34); + + mnemonicMap.put("[pf5]", 0x35); + mnemonicMap.put("[pf6]", 0x36); + mnemonicMap.put("[pf7]", 0x37); + mnemonicMap.put("[pf8]", 0x38); + mnemonicMap.put("[pf9]", 0x39); + + mnemonicMap.put("[pf10]", 0x3A); + mnemonicMap.put("[pf11]", 0x3B); + mnemonicMap.put("[pf12]", 0x3C); + mnemonicMap.put("[pf13]", 0xB1); + mnemonicMap.put("[pf14]", 0xB2); - public static final int mnemonicValue[] = { - 1001, 1002, 1003, 1004, 1005, - 1006, 1007, 1008, 1009, 1010, - 1011, 1012, 1013, 1014, 1015, - 1016, 1017, 1018, 1019, 1020, - 1021, 1022, 1023, 1024, 1025, - 1026, 1027, 1028, 1029, 1030, - 0xF1, 0x31, 0x32, 0x33, 0x34, - 0x35, 0x36, 0x37, 0x38, 0x39, - 0x3A, 0x3B, 0x3C, 0xB1, 0xB2, - 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, - 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, - 0xBD, 0xF3, 0xF4, 0xF5, 0xD9, - 0xDA, 0xF6, 0x6C, 0x6E, 0x6B, - 1031, 1032, 1033, 1034, 1035, - 1036, 1037, 1038, 1039, 1040, - 1041, 1042, 1043, 5000, 5001, - 5002, 5003, 5004, 5005, 5006, - 5007, 5008, 5009, 5010, 5011, - 5012, 5013, 5014, 5015, 5016, - 5017, 5018, 5019, 5020, 5021 - }; + mnemonicMap.put("[pf15]", 0xB3); + mnemonicMap.put("[pf16]", 0xB4); + mnemonicMap.put("[pf17]", 0xB5); + mnemonicMap.put("[pf18]", 0xB6); + mnemonicMap.put("[pf19]", 0xB7); + + mnemonicMap.put("[pf20]", 0xB8); + mnemonicMap.put("[pf21]", 0xB9); + mnemonicMap.put("[pf22]", 0xBA); + mnemonicMap.put("[pf23]", 0xBB); + mnemonicMap.put("[pf24]", 0xBC); + + mnemonicMap.put("[clear]", 0xBD); + mnemonicMap.put("[help]", 0xF3); + mnemonicMap.put("[pgup]", 0xF4); + mnemonicMap.put("[pgdown]", 0xF5); + mnemonicMap.put("[rollleft]", 0xD9); + + mnemonicMap.put("[rollright]", 0xDA); + mnemonicMap.put("[hostprint]", 0xF6); + mnemonicMap.put("[pa1]", 0x6C); + mnemonicMap.put("[pa2]", 0x6E); + mnemonicMap.put("[pa3]", 0x6B); + + mnemonicMap.put("[sysreq]", 1031); + mnemonicMap.put("[reset]", 1032); + mnemonicMap.put("[nextword]", 1033); + mnemonicMap.put("[prevword]", 1034); + mnemonicMap.put("[copy]", 1035); + + mnemonicMap.put("[paste]", 1036); + mnemonicMap.put("[attn]", 1037); + mnemonicMap.put("[markup]", 1038); + mnemonicMap.put("[markdown]", 1039); + mnemonicMap.put("[markleft]", 1040); + + mnemonicMap.put("[markright]", 1041); + mnemonicMap.put("[dupfield]", 1042); + mnemonicMap.put("[newline]", 1043); + mnemonicMap.put("[jumpnext]", 5000); + mnemonicMap.put("[jumpprev]", 5001); + + mnemonicMap.put("[opennew]", 5002); + mnemonicMap.put("[togcon]", 5003); + mnemonicMap.put("[hotspots]", 5004); + mnemonicMap.put("[gui]", 5005); + mnemonicMap.put("[dspmsgs]", 5006); + + mnemonicMap.put("[dspattr]", 5007); + mnemonicMap.put("[print]", 5008); + mnemonicMap.put("[cursor]", 5009); + mnemonicMap.put("[debug]", 5010); + mnemonicMap.put("[close]", 5011); + + mnemonicMap.put("[transfer]", 5012); + mnemonicMap.put("[e-mail]", 5013); + mnemonicMap.put("[runscript]", 5014); + mnemonicMap.put("[spoolfile]", 5015); + mnemonicMap.put("[quick-mail]", 5016); + + mnemonicMap.put("[open-same]", 5017); + mnemonicMap.put("[fastcursordown]", 5018); + mnemonicMap.put("[fastcursorup]", 5019); + mnemonicMap.put("[fastcursorright]", 5020); + mnemonicMap.put("[fastcursorleft]", 5021); + }; public static final String MNEMONIC_CLEAR = "[clear]"; public static final String MNEMONIC_ENTER = "[enter]"; @@ -426,7 +504,7 @@ public static final char COLOR_FG_LIGHT_MAGENTA = 0xD; public static final char COLOR_FG_BROWN = 0xE; public static final char COLOR_FG_WHITE_HIGH = 0xF; - + public static final int EXTENDED_5250_REVERSE = 0x10; public static final int EXTENDED_5250_UNDERLINE = 0x08; public static final int EXTENDED_5250_BLINK = 0x04;
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java Wed Jun 18 10:38:46 2014 -0700 +++ b/src/org/tn5250j/framework/tn5250/Screen5250.java Wed Jun 18 11:43:08 2014 -0700 @@ -553,23 +553,15 @@ } /** - * Searches the mnemonicData array looking for the specified string. If it - * is found it will return the value associated from the mnemonicValue + * converts mnemonic string values into aid integers * * @see #sendKeys - * @param mnem - * string mnemonic value + * @param mnem string mnemonic value * @return key value of Mnemonic */ private int getMnemonicValue(String mnem) { - - for (int x = 0; x < mnemonicData.length; x++) { - - if (mnemonicData[x].equals(mnem)) - return mnemonicValue[x]; - } + if (mnemonicMap.containsKey(mnem)) return mnemonicsMap.get(mnem); return 0; - } protected void setPrehelpState(boolean setErrorCode, boolean lockKeyboard,