comparison src/org/tn5250j/encoding/CharMappings.java @ 112:77ac18bc1b2f

cleanup java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Jun 2014 13:03:01 -0700
parents cbdff98c45ea
children
comparison
equal deleted inserted replaced
111:6a0ad4d384ea 112:77ac18bc1b2f
34 /** 34 /**
35 * Character Mappings for EBCDIC to ASCII and ASCII to EBCDIC translations 35 * Character Mappings for EBCDIC to ASCII and ASCII to EBCDIC translations
36 */ 36 */
37 public class CharMappings { 37 public class CharMappings {
38 38
39 public static final String DFT_ENC = "37"; 39 public static final String DFT_ENC = "37";
40 public static final int NATIVE_CP = 0; 40 public static final int NATIVE_CP = 0;
41 public static final int TOOLBOX_CP = 1; 41 public static final int TOOLBOX_CP = 1;
42 42
43 private static final HashMap<String,ICodePage> map = new HashMap<String, ICodePage>(); 43 private static final HashMap<String, ICodePage> map = new HashMap<String, ICodePage>();
44 44
45 public static String[] getAvailableCodePages() { 45 public static String[] getAvailableCodePages() {
46 Set<String> cpset = new HashSet<String>(); // no double entries 46 Set<String> cpset = new HashSet<String>(); // no double entries
47 for (String cp : BuiltInCodePageFactory.getInstance().getAvailableCodePages()) {
48 cpset.add(cp);
49 }
50 for (String cp : ToolboxCodePageFactory.getInstance().getAvailableCodePages()) {
51 cpset.add(cp);
52 }
53 String[] cparray = cpset.toArray(new String[cpset.size()]);
54 Arrays.sort(cparray);
55 return cparray;
56 }
57 47
58 public static ICodePage getCodePage(String encoding) { 48 for (String cp : BuiltInCodePageFactory.getInstance().getAvailableCodePages()) {
59 if (map.containsKey(encoding)) { 49 cpset.add(cp);
60 return map.get(encoding); 50 }
61 }
62 51
63 ICodePage cp = BuiltInCodePageFactory.getInstance().getCodePage(encoding); 52 for (String cp : ToolboxCodePageFactory.getInstance().getAvailableCodePages()) {
64 if (cp != null) { 53 cpset.add(cp);
65 map.put(encoding, cp); 54 }
66 return cp;
67 }
68 55
69 cp = ToolboxCodePageFactory.getInstance().getCodePage(encoding); 56 String[] cparray = cpset.toArray(new String[cpset.size()]);
70 if (cp != null) { 57 Arrays.sort(cparray);
71 map.put(encoding, cp); 58 return cparray;
72 return cp; 59 }
73 }
74 60
75 cp = JavaCodePageFactory.getCodePage(encoding); 61 public static ICodePage getCodePage(String encoding) {
76 if (cp != null) { 62 if (map.containsKey(encoding)) {
77 map.put(encoding, cp); 63 return map.get(encoding);
78 return cp; 64 }
79 }
80 65
81 // unsupported codepage ==> return default 66 ICodePage cp = BuiltInCodePageFactory.getInstance().getCodePage(encoding);
82 return BuiltInCodePageFactory.getInstance().getCodePage(DFT_ENC); 67
83 } 68 if (cp != null) {
69 map.put(encoding, cp);
70 return cp;
71 }
72
73 cp = ToolboxCodePageFactory.getInstance().getCodePage(encoding);
74
75 if (cp != null) {
76 map.put(encoding, cp);
77 return cp;
78 }
79
80 cp = JavaCodePageFactory.getCodePage(encoding);
81
82 if (cp != null) {
83 map.put(encoding, cp);
84 return cp;
85 }
86
87 // unsupported codepage ==> return default
88 return BuiltInCodePageFactory.getInstance().getCodePage(DFT_ENC);
89 }
84 90
85 } 91 }