Changeset 266 in tmcsimulator


Ignore:
Timestamp:
02/16/2019 03:22:09 PM (7 years ago)
Author:
jdalbey
Message:

PostmileCoords?.java: Add cross street name attribute and modified toJson to include it.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/atmsdriver/model/Highways.java

    r260 r266  
    556556                            + stat.postmile; 
    557557                    PostmileCoords.Postmile currentPM = pmList.find(pmID); 
     558                    if (currentPM == null) 
     559                    {  
     560                    Logger.getLogger(Highways.class.getName()).log(Level.INFO,  
     561                            "Postmile Coords lookup couldn't find Station: "+pmID, 
     562                            " "); 
     563                    } 
    558564                    if (currentPM != null) 
    559565                    {     
    560                     //lineout.append("" + dir.getLetter() + stat.postmile); 
    561                     //lineout.append(stat.getColorByDirection(dir)); 
    562                     String outString = currentPM.toJson(); 
    563                     // replace the color code with the color name 
    564                     String colorName=""; 
    565                     switch (stat.getColorByDirection(stat.direction)) 
    566                     { 
    567                         case '@': colorName = "red";break; 
    568                         case '+': colorName = "yellow"; break; 
    569                         case '-': colorName = "lime";break; 
    570                         case ' ': colorName = "lime";break; 
    571                     } 
    572                     outString = outString.replace("desiredcolor",colorName); 
    573                     lineout.append(outString); 
    574                     lineout.append("  "); 
     566                        //lineout.append("" + dir.getLetter() + stat.postmile); 
     567                        //lineout.append(stat.getColorByDirection(dir)); 
     568                        String outString = currentPM.toJson(); 
     569                        // replace the color code with the color name 
     570                        String colorName=""; 
     571                        switch (stat.getColorByDirection(stat.direction)) 
     572                        { 
     573                            case '@': colorName = "red";break; 
     574                            case '+': colorName = "yellow"; break; 
     575                            case '-': colorName = "lime";break; 
     576                            case ' ': colorName = "lime";break; 
     577                        } 
     578                        outString = outString.replace("desiredcolor",colorName); 
     579                        lineout.append(outString); 
     580                        lineout.append("  "); 
    575581                    } 
    576582                } 
  • trunk/src/atmsdriver/model/PostmileCoords.java

    r260 r266  
    4848    public void load(Scanner scan) 
    4949    { 
     50        try 
     51        { 
    5052        String out = scan.next(); 
    5153        //  split into an array  
     
    6264            }   
    6365            String revisedpm = nameparts[0] + " " + nameparts[1] + " " + statepm; 
    64             Postmile pm = new Postmile(revisedpm,fields[1],fields[2]); 
     66            Postmile pm = new Postmile(revisedpm,fields[1],fields[2],fields[3]); 
    6567            postmileList.add(pm); 
     68        } 
     69        } 
     70        catch (Exception ex) 
     71        { 
     72            ex.printStackTrace(); 
    6673        } 
    6774    } 
     
    7784    final static class Postmile   
    7885    { 
    79         String name;  // the postmile name (Route,Direction,State postmile) 
     86        String name;  // the postmile name (Route,Direction,State postmile, e.g., 5 N 6.2) 
    8087        String latitude; // the latitude coordinate for this postmile 
    8188        String longitude; // the longitude coordinate for this postmile 
    82         public Postmile(String name, String lat, String longitude) 
     89        String street; // cross street name 
     90        public Postmile(String name, String lat, String longitude, String street) 
    8391        { 
    8492            this.name = name.trim(); 
    8593            this.latitude = lat.trim(); 
    8694            this.longitude = longitude.trim(); 
     95            this.street = street.trim(); 
    8796        } 
    8897        public boolean nameEquals(String target) 
     
    98107            boolean r2 = this.latitude.equals(that.latitude); 
    99108            boolean r3 = this.longitude.equals(that.longitude); 
    100             return r1 && r2 && r3; 
     109            boolean r4 = this.street.equals(that.street); 
     110            return r1 && r2 && r3 && r4; 
    101111        } 
    102112        @Override public String toString() 
    103113        { 
    104             return name + ": " + latitude +","+ longitude; 
     114            return name + ": " + latitude +","+ longitude +","+ street; 
    105115        } 
    106116        public String toJson() 
    107117        { 
    108             String kFeature = "\n{\n   \"type\": \"Feature\",\n   \"id\": \""; 
    109             String kPoint = "\", \n     \"geometry\":\n       {\n        \"type\": \"Point\",\n        \"coordinates\": ["; 
    110             String kProp = "]\n" + 
    111 "      },\n" + 
    112 "      \"properties\": \n" + 
    113 "        {\"color\": \"desiredcolor\""; 
    114             String kTail = "}\n" + 
    115 "    },"; 
    116             return kFeature + name + kPoint + longitude + "," + latitude + kProp + kTail; 
     118            String pattern =  "\n{\n   \"type\": \"Feature\",\n"  
     119                    + "   \"geometry\":\n       {\n        \"type\": \"Point\",\n" + 
     120                    "        \"coordinates\": [%s,%s]\n" + 
     121                    "       },\n" + 
     122                    "      \"properties\": \n" +          
     123                    "        {\"id\": \"%s\", " + 
     124                    "\"street\": \"%s\", " + 
     125                    "\"color\": \"desiredcolor\"" + 
     126                    "}\n},"; 
     127 
     128            return String.format(pattern, longitude, latitude, name, street); 
    117129        } 
    118130    } 
  • trunk/src/tmcsim/application.properties

    r260 r266  
    1 #Tue, 12 Feb 2019 10:44:52 -0800 
     1#Sat, 16 Feb 2019 16:50:48 -0800 
    22 
    3 Application.revision=259 
     3Application.revision=265 
    44 
    55Application.buildnumber=95 
  • trunk/test/atmsdriver/model/PostmileCoordsTest.java

    r248 r266  
    3737 
    3838        System.out.println("load"); 
    39         String line1 = "5 N 4.02, 33.33, -117.117\n5 S 3.56, 33.33, -117.117"; 
     39        String line1 = "5 N 4.02, 33.33, -117.117,Dyer Rd\n5 S 3.56, 33.33, -117.117,Dyer Rd"; 
    4040        Scanner scan = new Scanner(line1).useDelimiter("\\A");  
    4141        pmc = new PostmileCoords(); 
    4242        pmc.load(scan); 
    4343        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33",  
    44                 "-117.117"); 
     44                "-117.117","Dyer Rd"); 
    4545        assertEquals(pm,pmc.get(0)); 
    4646        assert(pmc.size() == 2); 
     
    4848    public void testLoadwithPrefix() throws FileNotFoundException 
    4949    { 
    50  
    5150        System.out.println("load"); 
    52         String line1 = "5 N R4.02, 33.33, -117.117\n5 S 3.56, 33.33, -117.117"; 
     51        String line1 = "5 N R4.02, 33.33, -117.117,Dyer Rd\n5 S 3.56, 33.33, -117.117,Dyer Rd"; 
    5352        Scanner scan = new Scanner(line1).useDelimiter("\\A");  
    5453        pmc = new PostmileCoords(); 
    5554        pmc.load(scan); 
    5655        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33",  
    57                 "-117.117"); 
     56                "-117.117","Dyer Rd"); 
    5857        assertEquals(pm,pmc.get(0)); 
    5958        assert(pmc.size() == 2); 
     
    7675        PostmileCoords.Postmile result = pmc.find("5 N 4.02"); 
    7776        assertNotNull(result); 
    78         PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", "-117.117"); 
     77        PostmileCoords.Postmile pm = new PostmileCoords.Postmile("5 N 4.02", "33.33", "-117.117","Dyer Rd"); 
    7978        assertEquals(pm,result); 
    8079        PostmileCoords.Postmile result2 = pmc.find("X"); 
    8180        assertNull(result2); 
     81        System.out.println(pm.toJson()); 
    8282    } 
    8383} 
Note: See TracChangeset for help on using the changeset viewer.