Changeset 38 in tmcsimulator-scriptbuilder


Ignore:
Timestamp:
08/03/2017 04:30:19 PM (9 years ago)
Author:
bmcguffin
Message:

Removed the newLine at the end of each openTag method.

Location:
trunk/src/scriptbuilder/structures
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scriptbuilder/structures/MyScriptHandler.java

    r37 r38  
    244244        incidentMap = new TreeMap<Integer, ScriptIncident>(); 
    245245        eventMap = new TreeMap<ELEMENT, I_ScriptEvent>(); 
     246        unitMap = new TreeMap<String, Unit>(); 
    246247        pcData = new TreeMap<ELEMENT, String>(); 
    247248        docPosition = new Stack<ELEMENT>(); 
     
    257258        return new Vector<ScriptIncident>(incidentMap.values()); 
    258259    } 
     260     
     261    /** 
     262     * Get the list of units that have been parsed from the script file. 
     263     * 
     264     * @returns Vector of Unit objects. 
     265     */ 
     266    public Vector<Unit> getUnits() 
     267    { 
     268        return new Vector<Unit>(unitMap.values()); 
     269    } 
    259270 
    260271    /** 
     
    265276    { 
    266277        //System.out.println("STUB: Start the document"); 
    267         for (ELEMENT e : ELEMENT.values()) 
    268         { 
    269             pcData.put(e, null); 
    270         } 
     278         
    271279    } 
    272280 
     
    601609    public void endElement(String uri, String localName, String qName) 
    602610    { 
    603  
    604611        currentElement = docPosition.pop(); 
    605612        I_ScriptEvent newEvent = null; 
     
    791798            } 
    792799 
    793             else if (qName.equals(ELEMENT.INCIDENT.tag)) 
     800            else if (currentElement == ELEMENT.INCIDENT) 
    794801            { 
    795802                currentIncName = parsedValue.toString(); 
     
    805812 
    806813            } 
    807             else if (qName.equals(ELEMENT.NEW_UNIT)) 
     814            else if (currentElement == ELEMENT.NEW_UNIT) 
    808815            { 
    809816                if (unitMap.get(NewUnitNum) == null) 
     
    879886                        unit.Timer = pcData.remove(ELEMENT.TIMER); 
    880887                    } 
     888                    unitMap.put(NewUnitNum, unit); 
    881889                } 
    882890            } 
  • trunk/src/scriptbuilder/structures/ScriptIncident.java

    r34 r38  
    254254    public String openTag(String s) 
    255255    { 
    256         return "<" + s + ">\n"; 
     256        return "<" + s + ">"; 
    257257    } 
    258258 
  • trunk/src/scriptbuilder/structures/SimulationScript.java

    r30 r38  
    1919import scriptbuilder.structures.ScriptIncident.IncidentFocusedEvent; 
    2020import scriptbuilder.structures.ScriptIncident.SliceChangedEvent; 
     21import scriptbuilder.structures.units.Unit; 
    2122 
    2223/** 
     
    5657    public List<ScriptIncident> incidents; 
    5758 
     59    /** 
     60     * The units which participate in Unit events. 
     61     */ 
     62    public List<Unit> units; 
     63 
    5864    //Somewhere in the code, something assumes that the list of incidents 
    5965    //contains exactly 10 items. Until I can find and un-break that, this will do. 
     
    8086        sh = new MyScriptHandler(this); 
    8187        incidents = new ArrayList<ScriptIncident>(); 
     88        units = new ArrayList<Unit>(); 
    8289        numberOfIncidents = 0; 
    8390 
    84         // Create the media event 
    85         /*incidents.add(new ScriptIncident(incidentColors[0], 100, "Media", 
    86          "An incident for the media in CAD.", 10800, this)); 
    87          numberOfIncidents++; 
    88          // Create the "other" event 
    89          incidents.add(new ScriptIncident(incidentColors[9], 999, "Other", 
    90          "An incident for small-scale events, false events, " 
    91          + "and noise.  All events added to this incident will " 
    92          + "receive a randomly generated incident number.", 
    93          10800, this)); 
    94          numberOfIncidents++;*/ 
    9591        //Backfill with null incidents 
    9692        for (int i = numberOfIncidents; i < INCIDENT_FILL_COUNT; i++) 
     
    9894            incidents.add(null); 
    9995        } 
    100         /* 
    101          Add some demo events 
    102          incidents.add(new ScriptIncident(incidentColors[1], 174, "Blueberry Truck", 
    103          "Blueberry truck crashed on the freeway.", 8800, this)); 
    104          numberOfIncidents++; 
    105          incidents.add(new ScriptIncident(incidentColors[2], 175, "Construction Crash", 
    106          "Crash at construction site on Red Road.", 6800, this)); 
    107          numberOfIncidents++; 
    108          incidents.add(new ScriptIncident(incidentColors[3], 176, "Car Freeway Flip", 
    109          "Car flipped across the lane divider on the freeway.", 7200, this)); 
    110          numberOfIncidents++; 
    111          incidents.add(new ScriptIncident(incidentColors[4], 177, "Two Lane Crash", 
    112          "Crash taking two lanes on Tree Road.", 4200, this)); 
    113          numberOfIncidents++; 
    114          incidents.add(new ScriptIncident(incidentColors[5], 178, "Stalled Truck", 
    115          "Truck stalled on the freeway.", 2800, this)); 
    116          numberOfIncidents++; 
    117          incidents.add(new ScriptIncident(incidentColors[6], 179, "Tomato Truck Spill", 
    118          "Tomato trucked spilt tomatos all over the freeway.", 3200, this)); 
    119          incidents.add(new ScriptIncident(incidentColors[7], 180, "Crash at Intersection", 
    120          "Crash at the intersection of Tree Road and Red Road.", 4300, this)); 
    121          incidents.add(new ScriptIncident(incidentColors[8], 181, "Bomb Threat", 
    122          "Bomb threat and Road X.", 6000, this)); 
    123          incidents.add(null); 
    124          incidents.add(null); 
    125          incidents.add(null); 
    126          Random rng = new Random(); 
    127          ScriptEventType[] eventTypes = ScriptEventType.values(); 
    128          if (numberOfIncidents > 0) 
    129          { 
    130          for (int i = 0; i < 300; i++) 
    131          { 
    132          int n = rng.nextInt(); 
    133          int s = rng.nextInt(); 
    134          int e = rng.nextInt(); 
    135          if (n < 0) 
    136          { 
    137          n *= -1; 
    138          } 
    139          if (s < 0) 
    140          { 
    141          s *= -1; 
    142          } 
    143          if (e < 0) 
    144          { 
    145          e *= -1; 
    146          } 
    147          incidents.get(n % numberOfIncidents).slices.get(s % (incidents.get(n % numberOfIncidents).slices.size())).addEvent(new ScriptEvent(eventTypes[e % eventTypes.length])); 
    148          }   
    149          incidents.get(1).setOffset(200); 
    150          incidents.get(2).setOffset(3400); 
    151          incidents.get(3).setOffset(1400); 
    152          incidents.get(4).setOffset(4400); 
    153          incidents.get(5).setOffset(1400); 
    154          incidents.get(6).setOffset(7600); 
    155          incidents.get(7).setOffset(2400); 
    156          incidents.get(8).setOffset(4800);  
    157          } 
    158          */ 
    15996    } 
    16097 
     
    207144 
    208145            Vector<ScriptIncident> inc = sh.getIncidents(); 
    209  
     146            units = sh.getUnits(); 
    210147            for (ScriptIncident sci : inc) 
    211148            { 
     
    246183    public String toXML() 
    247184    { 
     185        ArrayList<TimeSlice> slices = allSlices(); 
    248186        String output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"; 
    249         output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">"; 
    250         ArrayList<TimeSlice> slices = allSlices(); 
     187        output += "<!DOCTYPE TMC_SCRIPT SYSTEM \"script.dtd\">\n"; 
    251188        output += openTag(ELEMENT.TMC_SCRIPT.tag + " title=\"" + this.title + "\""); 
     189 
     190        if (units.size() > 0) 
     191        { 
     192            output += openTag(ELEMENT.SCRIPT_DATA.tag); 
     193            for (Unit unit : units) 
     194            { 
     195                output += unit.toXML(); 
     196            } 
     197            output += closeTag(ELEMENT.SCRIPT_DATA.tag); 
     198        } 
    252199        for (TimeSlice slice : slices) 
    253200        { 
     
    261208    public String openTag(String s) 
    262209    { 
    263         return "<" + s + ">\n"; 
     210        return "<" + s + ">"; 
    264211    } 
    265212 
     
    291238            for (ScriptIncident inc : incidents) 
    292239            { 
    293                  
     240 
    294241                if (inc != null && inc.slices.get(i) != null) 
    295242                { 
  • trunk/src/scriptbuilder/structures/TimeSlice.java

    r37 r38  
    260260    public String openTag(String s) 
    261261    { 
    262         return "<" + s + ">\n"; 
     262        return "<" + s + ">"; 
    263263    } 
    264264 
  • trunk/src/scriptbuilder/structures/events/ATMSEvaluationEvent.java

    r37 r38  
    6868    public String openTag(String s) 
    6969    { 
    70         return "<" + s + ">\n"; 
     70        return "<" + s + ">"; 
    7171    } 
    7272 
  • trunk/src/scriptbuilder/structures/events/ActivityLogEvaluationEvent.java

    r37 r38  
    6868    public String openTag(String s) 
    6969    { 
    70         return "<" + s + ">\n"; 
     70        return "<" + s + ">"; 
    7171    } 
    7272 
  • trunk/src/scriptbuilder/structures/events/AudioEvent.java

    r35 r38  
    3737    public String openTag(String s) 
    3838    { 
    39         return "<" + s + ">\n"; 
     39        return "<" + s + ">"; 
    4040    } 
    4141 
  • trunk/src/scriptbuilder/structures/events/CADEvaluationEvent.java

    r37 r38  
    6868    public String openTag(String s) 
    6969    { 
    70         return "<" + s + ">\n"; 
     70        return "<" + s + ">"; 
    7171    } 
    7272 
  • trunk/src/scriptbuilder/structures/events/CADEvent.java

    r35 r38  
    4040    public String openTag(String s) 
    4141    { 
    42         return "<" + s + ">\n"; 
     42        return "<" + s + ">"; 
    4343    } 
    4444 
  • trunk/src/scriptbuilder/structures/events/CCTVEvent.java

    r36 r38  
    3939    public String openTag(String s) 
    4040    { 
    41         return "<" + s + ">\n"; 
     41        return "<" + s + ">"; 
    4242    } 
    4343 
  • trunk/src/scriptbuilder/structures/events/CHPRadioEvent.java

    r35 r38  
    5454    public String openTag(String s) 
    5555    { 
    56         return "<" + s + ">\n"; 
     56        return "<" + s + ">"; 
    5757    } 
    5858 
  • trunk/src/scriptbuilder/structures/events/CMSEvaluationEvent.java

    r36 r38  
    8787    public String openTag(String s) 
    8888    { 
    89         return "<" + s + ">\n"; 
     89        return "<" + s + ">"; 
    9090    } 
    9191 
  • trunk/src/scriptbuilder/structures/events/FacilitatorEvaluationEvent.java

    r37 r38  
    6868    public String openTag(String s) 
    6969    { 
    70         return "<" + s + ">\n"; 
     70        return "<" + s + ">"; 
    7171    } 
    7272 
  • trunk/src/scriptbuilder/structures/events/MaintenanceRadioEvent.java

    r28 r38  
    4040    public String openTag(String s) 
    4141    { 
    42         return "<" + s + ">\n"; 
     42        return "<" + s + ">"; 
    4343    } 
    4444 
  • trunk/src/scriptbuilder/structures/events/ParamicsEvent.java

    r35 r38  
    3636    public String openTag(String s) 
    3737    { 
    38         return "<" + s + ">\n"; 
     38        return "<" + s + ">"; 
    3939    } 
    4040 
  • trunk/src/scriptbuilder/structures/events/RadioEvaluationEvent.java

    r37 r38  
    6969    public String openTag(String s) 
    7070    { 
    71         return "<" + s + ">\n"; 
     71        return "<" + s + ">"; 
    7272    } 
    7373 
  • trunk/src/scriptbuilder/structures/events/TMTRadioEvent.java

    r36 r38  
    3838    public String openTag(String s) 
    3939    { 
    40         return "<" + s + ">\n"; 
     40        return "<" + s + ">"; 
    4141    } 
    4242 
  • trunk/src/scriptbuilder/structures/events/TelephoneEvent.java

    r35 r38  
    5656    public String openTag(String s) 
    5757    { 
    58         return "<" + s + ">\n"; 
     58        return "<" + s + ">"; 
    5959    } 
    6060 
  • trunk/src/scriptbuilder/structures/events/TowEvent.java

    r36 r38  
    3535    public String openTag(String s) 
    3636    { 
    37         return "<" + s + ">\n"; 
     37        return "<" + s + ">"; 
    3838    } 
    3939 
  • trunk/src/scriptbuilder/structures/events/UnitEvent.java

    r35 r38  
    3535    public String openTag(String s) 
    3636    { 
    37         return "<" + s + ">\n"; 
     37        return "<" + s + ">"; 
    3838    } 
    3939 
  • trunk/src/scriptbuilder/structures/events/WitnessEvent.java

    r36 r38  
    4343    public String openTag(String s) 
    4444    { 
    45         return "<" + s + ">\n"; 
     45        return "<" + s + ">"; 
    4646    } 
    4747 
  • trunk/src/scriptbuilder/structures/units/Unit.java

    r1 r38  
    55 */ 
    66package scriptbuilder.structures.units; 
     7 
     8import scriptbuilder.structures.ELEMENT; 
     9import scriptbuilder.structures.I_XML_Writable; 
    710 
    811/** 
     
    1316 * @author Bryan McGuffin 
    1417 */ 
    15 public class Unit 
     18public class Unit implements I_XML_Writable 
    1619{ 
    1720 
    18     public String UnitNum = ""; 
    19  
    20     public String ID = ""; 
    21  
    22     public String Status = ""; 
    23  
    24     public String Master_Inc_Num = ""; 
    25  
    26     public String Primary = ""; 
    27  
    28     public String OOS = ""; 
    29  
    30     public String Type = ""; 
    31  
    32     public String Curr_Loc = ""; 
    33  
    34     public String Destination = ""; 
    35  
    36     public String Misc_Info = ""; 
    37  
    38     public String Stack = ""; 
    39  
    40     public String Area = ""; 
    41  
    42     public String Officer = ""; 
    43  
    44     public String Badge_Num = ""; 
    45  
    46     public String Timer = ""; 
    47  
    48     public String Office = ""; 
    49  
    50     public String P = ""; 
    51  
    52     public String Agy = ""; 
    53  
    54     public String Alias = ""; 
    55  
    56     public String Unit_Status = ""; 
    57  
     21    public String UnitNum; 
     22 
     23    public String ID; 
     24 
     25    public String Status; 
     26 
     27    public String Master_Inc_Num; 
     28 
     29    public String Primary; 
     30 
     31    public String OOS; 
     32 
     33    public String Type; 
     34 
     35    public String Curr_Loc; 
     36 
     37    public String Destination; 
     38 
     39    public String Misc_Info; 
     40 
     41    public String Stack; 
     42 
     43    public String Area; 
     44 
     45    public String Officer; 
     46 
     47    public String Badge_Num; 
     48 
     49    public String Timer; 
     50 
     51    public String Office; 
     52 
     53    public String P; 
     54 
     55    public String Agy; 
     56 
     57    public String Alias; 
     58 
     59    public String Unit_Status; 
     60 
     61    public Unit() 
     62    { 
     63        UnitNum = ""; 
     64 
     65        ID = ""; 
     66 
     67        Status = ""; 
     68 
     69        Master_Inc_Num = ""; 
     70 
     71        Primary = ""; 
     72 
     73        OOS = ""; 
     74 
     75        Type = ""; 
     76 
     77        Curr_Loc = ""; 
     78 
     79        Destination = ""; 
     80 
     81        Misc_Info = ""; 
     82 
     83        Stack = ""; 
     84 
     85        Area = ""; 
     86 
     87        Officer = ""; 
     88 
     89        Badge_Num = ""; 
     90 
     91        Timer = ""; 
     92 
     93        Office = ""; 
     94 
     95        P = ""; 
     96 
     97        Agy = ""; 
     98 
     99        Alias = ""; 
     100 
     101        Unit_Status = ""; 
     102    } 
     103 
     104    @Override 
     105    public String toXML() 
     106    { 
     107        String output = openTag(ELEMENT.NEW_UNIT.tag + " UnitNum=\"" + UnitNum + "\""); 
     108 
     109        if (!ID.equals("")) 
     110        { 
     111            output += openTag(ELEMENT.ID.tag) + ID + closeTag(ELEMENT.ID.tag); 
     112        } 
     113 
     114        if (!Status.equals("")) 
     115        { 
     116            output += openTag(ELEMENT.STATUS.tag) + Status + closeTag(ELEMENT.STATUS.tag); 
     117        } 
     118 
     119        if (!Master_Inc_Num.equals("")) 
     120        { 
     121            output += openTag(ELEMENT.MASTER_INC_NUM.tag) + Master_Inc_Num + closeTag(ELEMENT.MASTER_INC_NUM.tag); 
     122        } 
     123 
     124        if (!Primary.equals("")) 
     125        { 
     126            output += openTag(ELEMENT.PRIMARY.tag) + Primary + closeTag(ELEMENT.PRIMARY.tag); 
     127        } 
     128 
     129        if (!OOS.equals("")) 
     130        { 
     131            output += openTag(ELEMENT.OOS.tag) + OOS + closeTag(ELEMENT.OOS.tag); 
     132        } 
     133 
     134        if (!Type.equals("")) 
     135        { 
     136            output += openTag(ELEMENT.TYPE.tag) + Type + closeTag(ELEMENT.TYPE.tag); 
     137        } 
     138 
     139        if (!Curr_Loc.equals("")) 
     140        { 
     141            output += openTag(ELEMENT.CURR_LOC.tag) + Curr_Loc + closeTag(ELEMENT.CURR_LOC.tag); 
     142        } 
     143 
     144        if (!Destination.equals("")) 
     145        { 
     146            output += openTag(ELEMENT.DESTINATION.tag) + Destination + closeTag(ELEMENT.DESTINATION.tag); 
     147        } 
     148 
     149        if (!Misc_Info.equals("")) 
     150        { 
     151            output += openTag(ELEMENT.MISC_INFO.tag) + Misc_Info + closeTag(ELEMENT.MISC_INFO.tag); 
     152        } 
     153 
     154        if (!Stack.equals("")) 
     155        { 
     156            output += openTag(ELEMENT.STACK.tag) + Stack + closeTag(ELEMENT.STACK.tag); 
     157        } 
     158 
     159        if (!Area.equals("")) 
     160        { 
     161            output += openTag(ELEMENT.AREA.tag) + Area + closeTag(ELEMENT.AREA.tag); 
     162        } 
     163 
     164        if (!Badge_Num.equals("")) 
     165        { 
     166            output += openTag(ELEMENT.BADGE_NUM.tag) + Badge_Num + closeTag(ELEMENT.BADGE_NUM.tag); 
     167        } 
     168 
     169        if (!Officer.equals("")) 
     170        { 
     171            output += openTag(ELEMENT.OFFICER.tag) + Officer + closeTag(ELEMENT.OFFICER.tag); 
     172        } 
     173 
     174        if (!Office.equals("")) 
     175        { 
     176            output += openTag(ELEMENT.OFFICE.tag) + Office + closeTag(ELEMENT.OFFICE.tag); 
     177        } 
     178 
     179        if (!Timer.equals("")) 
     180        { 
     181            output += openTag(ELEMENT.TIMER.tag) + Timer + closeTag(ELEMENT.TIMER.tag); 
     182        } 
     183 
     184        if (!P.equals("")) 
     185        { 
     186            output += openTag(ELEMENT.P.tag) + P + closeTag(ELEMENT.P.tag); 
     187        } 
     188 
     189        if (!Agy.equals("")) 
     190        { 
     191            output += openTag(ELEMENT.AGY.tag) + Agy + closeTag(ELEMENT.AGY.tag); 
     192        } 
     193 
     194        if (!Alias.equals("")) 
     195        { 
     196            output += openTag(ELEMENT.ALIAS.tag) + Alias + closeTag(ELEMENT.ALIAS.tag); 
     197        } 
     198 
     199        if (!Unit_Status.equals("")) 
     200        { 
     201            output += openTag(ELEMENT.UNIT_STATUS.tag) + Unit_Status + closeTag(ELEMENT.UNIT_STATUS.tag); 
     202        } 
     203 
     204        output += closeTag(ELEMENT.NEW_UNIT.tag); 
     205        return output; 
     206    } 
     207 
     208    @Override 
     209    public String openTag(String s) 
     210    { 
     211        return "<" + s + ">"; 
     212    } 
     213 
     214    @Override 
     215    public String closeTag(String s) 
     216    { 
     217        return "</" + s + ">\n"; 
     218    } 
     219 
     220    @Override 
     221    public String emptyTag(String s) 
     222    { 
     223        return "<" + s + "/>\n"; 
     224    } 
    58225} 
Note: See TracChangeset for help on using the changeset viewer.