comparison src/org/tn5250j/framework/tn5250/KeyStrokenizer.java @ 112:77ac18bc1b2f

cleanup java formatting
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Jun 2014 13:03:01 -0700
parents 1e931ef5f776
children e2a56e383bad
comparison
equal deleted inserted replaced
111:6a0ad4d384ea 112:77ac18bc1b2f
32 private int index; 32 private int index;
33 private int length; 33 private int length;
34 34
35 35
36 36
37 public KeyStrokenizer() { 37 public KeyStrokenizer() {
38 sb = new StringBuffer();
39 setKeyStrokes(null);
40 }
38 41
39 sb = new StringBuffer(); 42 public void setKeyStrokes(String strokes) {
40 setKeyStrokes(null); 43 if (strokes != null) {
41 } 44 keyStrokes.setLength(0);
45 Log.d(TAG, "set " + keyStrokes);
46 length = strokes.length();
47 }
48 else {
49 keyStrokes = new StringBuffer();
50 length = 0;
51 }
42 52
43 public void setKeyStrokes (String strokes) { 53 keyStrokes.append(strokes);
54 index = 0;
55 }
44 56
45 if (strokes != null) { 57 public boolean hasMoreKeyStrokes() {
46 keyStrokes.setLength(0); 58 return length > index;
47 Log.d(TAG,"set "+ keyStrokes); 59 }
48 length = strokes.length();
49 }
50 else {
51 60
52 keyStrokes = new StringBuffer(); 61 public String nextKeyStroke() {
53 length = 0; 62 String s = "";
63 boolean gotOne = false;
54 64
55 } 65 if (length > index) {
56 keyStrokes.append(strokes); 66 sb.setLength(0);
57 index = 0; 67 char c = keyStrokes.charAt(index);
58 68
59 } 69 switch (c) {
70 case '[':
71 sb.append(c);
72 index++;
60 73
61 public boolean hasMoreKeyStrokes() { 74 // we need to throw an error here
62 return length > index; 75 if (index >= length) {
63 } 76 Log.w(TAG, " mnemonic key was incomplete :1 " +
77 "at position " + index + " len " + length);
78 }
79 else {
80 c = keyStrokes.charAt(index);
64 81
65 public String nextKeyStroke() { 82 if (c == '[')
83 index++;
84 else {
85 while (!gotOne) {
86 if (c == ']') { // did we find an ending
87 sb.append(c);
88 index++;
89 gotOne = true;
90 }
91 else {
92 sb.append(c);
93 index++;
66 94
67 String s = ""; 95 // we need to throw an error here because we did not
68 boolean gotOne = false; 96 // find an ending for the potential mnemonic
69 if(length > index) { 97 if (index >= length) {
70 sb.setLength(0); 98 Log.w(TAG,
99 " mnemonic key was incomplete ending not found :2 " +
100 "at position " + index);
101 }
71 102
72 char c = keyStrokes.charAt(index); 103 c = keyStrokes.charAt(index);
73 switch(c) { 104 }
74 case '[': 105 }
75 sb.append(c); 106 }
76 index++; 107 }
77 108
78 // we need to throw an error here 109 break;
79 if(index >= length) {
80 Log.w(TAG," mnemonic key was incomplete :1 " +
81 "at position " + index + " len " + length );
82 }
83 else {
84 c = keyStrokes.charAt(index);
85 110
86 if(c == '[') 111 case ']':
87 index++; 112 index++;
88 else {
89 while(!gotOne) {
90 113
91 if(c == ']') { // did we find an ending 114 if (index >= length) {
92 sb.append(c); 115 Log.w(TAG,
93 index++; 116 " mnemonic key was incomplete ending not found :3 " +
94 gotOne = true; 117 "at position " + index);
118 sb.append(c);
119 index++;
120 }
121 else {
122 c = keyStrokes.charAt(index);
123
124 if (c == ']') {
125 sb.append(c);
126 index++;
95 } 127 }
96 else { 128 else {
97 sb.append(c); 129 Log.w(TAG,
98 index++; 130 " mnemonic key was incomplete beginning not found :4 " +
99 // we need to throw an error here because we did not 131 "at position " + index);
100 // find an ending for the potential mnemonic
101 if(index >= length) {
102 Log.w(TAG,
103 " mnemonic key was incomplete ending not found :2 " +
104 "at position " + index);
105 }
106 c = keyStrokes.charAt(index);
107 } 132 }
108 } 133 }
109 }
110 }
111 break;
112 134
113 case ']': 135 break;
114 index++;
115 if(index >= length) {
116 Log.w(TAG,
117 " mnemonic key was incomplete ending not found :3 " +
118 "at position " + index);
119 sb.append(c);
120 index++;
121 136
122 } 137 default:
123 else { 138 sb.append(c);
124 c = keyStrokes.charAt(index); 139 index++;
125 if(c == ']') { 140 break;
126 sb.append(c); 141 }
127 index++;
128 }
129 else {
130 Log.w(TAG,
131 " mnemonic key was incomplete beginning not found :4 " +
132 "at position " + index);
133 }
134 }
135 break;
136 default:
137 sb.append(c);
138 index++;
139 break;
140 }
141 if(sb != null) {
142 s = new String(sb);
143 }
144 142
145 } 143 if (sb != null) {
146 Log.d(TAG,"next "+ keyStrokes); 144 s = new String(sb);
145 }
146 }
147 147
148 return s; 148 Log.d(TAG, "next " + keyStrokes);
149 } 149 return s;
150 }
150 151
151 public String getUnprocessedKeyStroked() { 152 public String getUnprocessedKeyStroked() {
152 if(index >= length) { 153 if (index >= length) {
153 return null; 154 return null;
154 } 155 }
155 return keyStrokes.substring(index); 156
156 } 157 return keyStrokes.substring(index);
158 }
157 159
158 } 160 }