Changeset 1408 for trunk/src/org/expeditee/io/ExpWriter.java
- Timestamp:
- 06/21/19 12:12:55 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/io/ExpWriter.java
r1326 r1408 28 28 import java.lang.reflect.Method; 29 29 import java.util.Iterator; 30 import java.util.LinkedHashMap; 30 31 import java.util.LinkedList; 31 32 import java.util.List; … … 53 54 protected String _framename; 54 55 55 pr ivatestatic final char TERMINATOR = 'Z';56 protected static final char TERMINATOR = 'Z'; 56 57 57 58 public ExpWriter() { … … 87 88 try { 88 89 _FrameTags.remove('A'); 89 _ItemTags.put('S', Item.class.getMethod("getTypeAndID",90 getItemTags().put('S', Item.class.getMethod("getTypeAndID", 90 91 new Class[] {})); 91 92 } catch (Exception e) { … … 130 131 writeTerminator(); 131 132 writeLine(SessionStats.getFrameEventList(frame)); 132 133 return;134 133 } 135 134 … … 137 136 } 138 137 139 pr ivatevoid writeHeader(Frame toWrite) throws IOException {138 protected void writeHeader(Frame toWrite) throws IOException { 140 139 Iterator<Character> it = _FrameTags.keySet().iterator(); 141 140 Object[] param = {}; … … 185 184 // } 186 185 187 pr ivatevoid writeLine(String tag, String line) throws IOException {186 protected void writeLine(String tag, String line) throws IOException { 188 187 writeLine(tag + " " + line); 189 188 } … … 227 226 } 228 227 229 pr ivateList<Item> _lineEnds = new LinkedList<Item>();228 protected List<Item> _lineEnds = new LinkedList<Item>(); 230 229 231 230 // Writes out a LineEnd to the file … … 306 305 } 307 306 308 private void writeClass(Object toWrite) throws IOException { 309 Iterator<Character> it = _ItemTags.keySet().iterator(); 310 Iterator<String> itExt = _ItemTagsExt.keySet().iterator(); 311 Object[] param = {}; 312 307 protected void writeClass(Item toWrite) throws IOException { 308 writeTags(toWrite, new Object[] {}, getItemTags()); 309 writeTags(toWrite, new Object[] {}, getItemTagsExt()); 310 } 311 312 protected <T> void writeTags(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags) { 313 Iterator<T> it = tags.keySet().iterator(); 313 314 while (it.hasNext()) { 314 Character tag = it.next(); 315 Method toRun = _ItemTags.get(tag); 316 Class<?> declarer = toRun.getDeclaringClass(); 317 if (declarer.isAssignableFrom(toWrite.getClass())) { 318 try { 319 Object o = toRun.invoke(toWrite, param); 320 o = Conversion.ConvertToExpeditee(toRun, o); 321 if (o != null) { 322 if (o instanceof List) { 323 for (Object line : (List) o) { 324 writeLine(tag.toString(), line.toString()); 325 } 326 } else 327 writeLine(tag.toString(), o.toString()); 328 } 329 } catch (Exception e) { 330 e.printStackTrace(); 315 T tag = it.next(); 316 writeTag(toWrite, param, tags, tag); 317 } 318 } 319 320 protected <T> void writeTag(Item toWrite, Object[] param, LinkedHashMap<T, Method> tags, T tag) { 321 Method toRun = tags.get(tag); 322 Class<?> declarer = toRun.getDeclaringClass(); 323 if (declarer.isAssignableFrom(toWrite.getClass())) { 324 try { 325 Object o = toRun.invoke(toWrite, param); 326 o = Conversion.ConvertToExpeditee(toRun, o); 327 if (o != null) { 328 if (o instanceof List) { 329 for (Object line : (List) o) { 330 writeLine(tag.toString(), line.toString()); 331 } 332 } else 333 writeLine(tag.toString(), o.toString()); 331 334 } 332 } 333 } 334 335 while (itExt.hasNext()) { 336 String tag = itExt.next(); 337 Method toRun = _ItemTagsExt.get(tag); 338 Class<?> declarer = toRun.getDeclaringClass(); 339 if (declarer.isAssignableFrom(toWrite.getClass())) { 340 try { 341 Object o = toRun.invoke(toWrite, param); 342 o = Conversion.ConvertToExpeditee(toRun, o); 343 if (o != null) { 344 if (o instanceof List) { 345 for (Object line : (List) o) { 346 writeLine(tag.toString(), line.toString()); 347 } 348 } else 349 writeLine(tag.toString(), o.toString()); 350 } 351 } catch (Exception e) { 352 e.printStackTrace(); 353 } 335 } catch (Exception e) { 336 e.printStackTrace(); 354 337 } 355 338 }
Note:
See TracChangeset
for help on using the changeset viewer.