Warning: Can't use blame annotator:
svn blame failed on trunk/src/atmsdriver/model/PostmileCoords.java: ("Can't find a temporary directory: Internal error", 20014)

source: tmcsimulator/trunk/src/atmsdriver/model/PostmileCoords.java @ 260

Revision 260, 3.6 KB checked in by jdalbey, 7 years ago (diff)

Highways.java: adjust json colors to brighten the hue for easier reading.

RevLine 
1
2package atmsdriver.model;
3
4import java.util.ArrayList;
5import java.util.Iterator;
6import java.util.List;
7import java.util.Scanner;
8
9/**
10 * PostmileCoords is a collection of Postmiles (id and LatLong Coordinates).
11 * @author jdalbey
12 */
13public class PostmileCoords implements Iterable
14{
15    private List<Postmile> postmileList;
16    public PostmileCoords()
17    {
18        postmileList = new ArrayList<Postmile>();
19    }
20    /** Accessor to value at given index */
21    public Postmile get(int idx)
22    {
23        return postmileList.get(idx);
24    }
25    /** Return the size */
26    public int size()
27    {
28        return postmileList.size();
29    }
30    /** Find the postmile with the given name */
31    public Postmile find(String target)
32    {
33        int idx = 0;
34        while (idx < postmileList.size() && !postmileList.get(idx).nameEquals(target))
35        {
36            idx++;
37        }
38        if (idx < postmileList.size())
39        {
40            return postmileList.get(idx);
41        }
42        else
43        {
44            return null;
45        }
46    }
47    /** Load the postmile list from external file */
48    public void load(Scanner scan)
49    {
50        String out = scan.next();
51        //  split into an array
52        String[] results = out.split("\\n");
53        for (String item : results)
54        {
55            String[] fields = item.split(",");
56            String[] nameparts = fields[0].split(" ");
57            String statepm = nameparts[2];
58            // some postmiles come with a prefix, which we ignore
59            if (Character.isLetter(statepm.charAt(0)))
60            {
61                statepm = statepm.substring(1);
62            } 
63            String revisedpm = nameparts[0] + " " + nameparts[1] + " " + statepm;
64            Postmile pm = new Postmile(revisedpm,fields[1],fields[2]);
65            postmileList.add(pm);
66        }
67    }
68
69    @Override
70    public Iterator iterator()
71    {
72        return postmileList.iterator();
73    }
74    /**
75     *  Postmile is a postmile id and its LatLong Coordinates.
76     */
77    final static class Postmile 
78    {
79        String name;  // the postmile name (Route,Direction,State postmile)
80        String latitude; // the latitude coordinate for this postmile
81        String longitude; // the longitude coordinate for this postmile
82        public Postmile(String name, String lat, String longitude)
83        {
84            this.name = name.trim();
85            this.latitude = lat.trim();
86            this.longitude = longitude.trim();
87        }
88        public boolean nameEquals(String target)
89        {
90            return this.name.equals(target);
91        }
92        @Override public boolean equals(Object aThat) 
93        {
94            if (this == aThat) return true;
95            if (!(aThat instanceof Postmile)) return false;
96            Postmile that = (Postmile) aThat;
97            boolean r1 = this.name.equals(that.name);
98            boolean r2 = this.latitude.equals(that.latitude);
99            boolean r3 = this.longitude.equals(that.longitude);
100            return r1 && r2 && r3;
101        }
102        @Override public String toString()
103        {
104            return name + ": " + latitude +","+ longitude;
105        }
106        public String toJson()
107        {
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;
117        }
118    }
119}
Note: See TracBrowser for help on using the repository browser.