Changeset 465 in tmcsimulator for trunk/src/tmcsim/cadsimulator/Coordinator.java
- Timestamp:
- 07/26/2019 05:12:05 AM (7 years ago)
- File:
-
- 1 edited
-
trunk/src/tmcsim/cadsimulator/Coordinator.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tmcsim/cadsimulator/Coordinator.java
r448 r465 8 8 import java.text.DateFormat; 9 9 import java.text.SimpleDateFormat; 10 import java.util.ArrayList; 11 import java.util.Collections; 10 12 import java.util.Date; 11 13 import java.util.LinkedList; 14 import java.util.List; 12 15 import java.util.Observer; 13 16 import java.util.TreeMap; … … 744 747 Logger.getLogger(Coordinator.class.getName()).log(Level.SEVERE, null, ex); 745 748 } 746 // Initialize an output buffer 747 StringBuffer output = new StringBuffer(); 749 // Write output list to a file 750 try 751 { 752 PrintWriter writer = new PrintWriter(new FileWriter(kCADcommentLog)); 753 // process the list of comments obtained from helper method 754 for (String item: getSortedComments(incList)) 755 { 756 writer.print(item.substring(9)); 757 } 758 writer.close(); 759 } catch (Exception exc) 760 { 761 exc.printStackTrace(); 762 } 763 } 764 765 /** Extract a list of comments from the current incidents, ordered 766 * by timestamp. Fixes defect #175. 767 * Package private to allow unit testing. 768 * 769 * @param incidentList the incidents from which comments are desired 770 * @return list of comments, ready to be output. 771 */ 772 List<String> getSortedComments(Vector<Incident> incidentList) 773 { 774 // Initialize a list of for outputing CAD comments 775 ArrayList<String> commentList = new ArrayList<String>(); 748 776 // Process all the incidents 749 for (Incident incident: inc List)777 for (Incident incident: incidentList) 750 778 { 751 779 // Retrieve the table of comments/notes the users created … … 755 783 { 756 784 // Combine the fields into one output entry 785 String timestamp = (String)notesTable.getValueAt(row,1); 757 786 String initials = (String) notesTable.getValueAt(row,2); // user initials 758 787 // If there are user intials, include this item. 759 788 // Zero length initials mean it's a scripted item, ignore it. 789 StringBuffer output = new StringBuffer(); 760 790 if (initials.length() > 0) 761 {//CAD Log Entry, Incident #187, Sharon: REQUEST EXTRA ANCHOVIES 762 output.append("CAD log, "); 791 {//17:03:19 CAD Log Entry, Incident #187, Sharon: REQUEST EXTRA ANCHOVIES 792 output.append(timestamp); 793 output.append(" CAD log, "); 763 794 output.append("Incident #" + incident.logNum + ", "); 764 795 output.append(initials + ": "); 765 796 output.append(notesTable.getValueAt(row,4) + "\n"); // notes 797 commentList.add(output.toString()); // Add this comment to the list 766 798 } 767 799 } 768 800 } 769 // Write output buffer to a file 770 try 771 { 772 PrintWriter writer = new PrintWriter(new FileWriter(kCADcommentLog)); 773 writer.print(output); 774 writer.close(); 775 } catch (Exception exc) 776 { 777 exc.printStackTrace(); 778 } 779 } 780 801 // Order the comments by timestamp instead of incident number. 802 Collections.sort(commentList, new java.util.Comparator<String>() 803 { 804 // provide a comparator that can compare number strings 805 public int compare(String o1, String o2) 806 { 807 return extractInt(o1) - extractInt(o2); 808 } 809 // extract an integer from a String 810 int extractInt(String s) 811 { // remove all non-digits 812 String num = s.replaceAll("\\D", ""); 813 // return 0 if no digits found, else return the number 814 return num.isEmpty() ? 0 : Integer.parseInt(num); 815 } 816 }); 817 return commentList; 818 } 781 819 /** Write the currentSimTime to a file. 782 820 This will be read asynchronously by web clients, e.g.,
Note: See TracChangeset
for help on using the changeset viewer.
