⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 roadfinder.java

📁 openmap java写的开源数字地图程序. 用applet实现,可以像google map 那样放大缩小地图.
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        Set ptSet = new HashSet();        for (int i = 0; i < bestRoute.roads.length; i++) {            road = bestRoute.roads[i];            if (!from.equals(road.getFirstIntersection())                    && !from.equals(road.getSecondIntersection())) {                logger.severe("huh? " + from                        + " is not an intersection on road " + road);            }            Point pt = createPoint(proj.forward(from.getLocation()));            if (doLoopCheck) {                if (ptSet.contains(pt)) {                    logger.warning("pt set has duplicate at " + pt);                }                ptSet.add(pt);            }            newPoints.add(pt);            to = road.getOtherIntersection(from);            if (doLoopCheck) {                if (loopSet.contains(to)) {                    logger.warning("road has a cycle at " + to);                }                loopSet.add(to);            }            // check to see if we need to reverse the order of the            // road points,            // which may not be ordered the same as the previous road            boolean reverse = from.equals(road.getSecondIntersection());            Segment path = getPathSegment(proj, road, reverse);            if (logger.isLoggable(Level.INFO))                logger.info("created path " + path);            segments.add(path);            from = to;        }        Point pt = createPoint(proj.forward(to.getLocation()));        if (ptSet.contains(pt)) {            logger.warning("pt set has duplicate at " + pt);        }        newPoints.add(pt);        if (logger.isLoggable(Level.INFO))            logger.info(" now " + newPoints.size() + " points and "                    + segments.size() + " segments.");    }    /**     * Converts a road into a path segment - reverse parameter     * guarantees the ordering of the points is consistent across     * multiple path segments in the whole route.     *      * @return PathSegment converted from a road     */    protected Segment getPathSegment(Projection proj, Road road, boolean reverse) {        RoadPoint[] roadPoints = road.getRoadPoints();        List newPoints = new ArrayList();        if (reverse) {            for (int i = roadPoints.length - 1; i > 0; i--) {                newPoints.add(createPoint(proj.forward(roadPoints[i].getLocation())));            }        } else {            for (int i = 0; i < roadPoints.length; i++) {                newPoints.add(createPoint(proj.forward(roadPoints[i].getLocation())));            }        }        return createSegment(newPoints);    }    /**     * Allows subclasses to redefine segments     */    protected Segment createSegment(List newPoints) {        return new Segment(newPoints);    }    /**     * Allows subclasses to redefine points returned     */    protected Point createPoint(Point pt) {        return new Point(pt);    }    public Projection getProjection() {        return layer.getProjection();    }    /**     * Check the integrity of our data structures.     *      * Scan the known intersections. Note intersections with no roads.     * Scan the roads of the intersection: Each road has two     * intersections. If the road has already been encountered, then     * we recorded its "other" intersection and that must match this     * intersection. If it doesn't match, record an error. If it does     * match reset its recorded other intersection to be a special     * marker indicating that both ends of the road have been     * accounted for. If the road has not already been encountered,     * then record its "other" intersection. Scan the known roads.     * Every road should accounted for in the "other" intersection     * table and should be marked as having both intersections     * accounted for. Note the roads which were not found in the first     * scan and the roads which were found, but for which both     * intersections were not found. Remark every road. Finally scan     * the other intersection table for entries which were not marked     * as being in the roads vector.     */    protected void checkIntegrity() {        // CharArrayWriter errorWriter = new CharArrayWriter();        // PrintWriter errors = new PrintWriter(errorWriter);        PrintStream errors = System.err;        Hashtable otherIntersections = new Hashtable();        Object bothIntersections = new Object();        Object inRoadsVector = new Object();        for (Enumeration e = intersections.elements(); e.hasMoreElements();) {            Intersection intersection = (Intersection) e.nextElement();            int nRoads = intersection.getRoadCount();            if (nRoads == 0) {                errors.println("Dangling intersection");                errors.println("  Intersection = " + intersection);                continue;            }            for (int i = 0; i < nRoads; i++) {                Road road = intersection.getRoad(i);                Object other = otherIntersections.get(road);                if (other == null) {                    otherIntersections.put(road,                            road.getOtherIntersection(intersection));                } else if (other == intersection) {                    otherIntersections.put(road, bothIntersections);                } else {                    errors.println("Misconnected");                    errors.println("          Road = " + road);                    errors.println("    Road.Other = " + other);                    errors.println("  Intersection = " + intersection);                }            }        }        for (Enumeration e = roads.elements(); e.hasMoreElements();) {            Road road = (Road) e.nextElement();            Object other = otherIntersections.get(road);            if (other == null) {                errors.println("Road not found in intersections");                errors.println("          Road = " + road);            } else if (other != bothIntersections) {                errors.println("Road incompletely connected");                errors.println("          Road = " + road);                errors.println("    Road.Other = " + other);            } else if (other == inRoadsVector) {                errors.println("Road doubly listed");                errors.println("          Road = " + road);            }            otherIntersections.put(road, inRoadsVector);        }        for (Enumeration e = otherIntersections.keys(); e.hasMoreElements();) {            Road road = (Road) e.nextElement();            Object other = otherIntersections.get(road);            if (other != inRoadsVector) {                errors.println("Road not listed");                errors.println("          Road = " + road);            }        }        // String errString = errorWriter.toString();        // if (errString.equals(""))        // return;        // JTextArea text = new JTextArea(errString);        // JScrollPane scrollPane = new JScrollPane(text);        // final JFrame dialog = new JFrame("Errors");        // JButton ok = new JButton("OK");        // ok.addActionListener(new ActionListener() {        // public void actionPerformed(ActionEvent e) {        // dialog.dispose();        // }        // });        // dialog.getContentPane().add(scrollPane,        // BorderLayout.CENTER);        // dialog.getContentPane().add(ok, BorderLayout.SOUTH);        // dialog.setSize(new java.awt.Dimension(640, 480));        // dialog.setVisible(true);    }    static class RoadVector {        Road[] roads = new Road[0];        private int look = 0;        private int roadCount = 0;        public void clear() {            for (int i = 0; i < roads.length; i++)                roads[i] = null;            look = 0;            roadCount = 0;        }        public void add(Road r) {            int id = r.getID();            if (id >= roads.length) {                Road[] oldRoads = roads;                roads = new Road[id + 100 + roads.length];                System.arraycopy(oldRoads, 0, roads, 0, oldRoads.length);                for (int i = oldRoads.length; i < roads.length; i++)                    roads[i] = null;            }            if (roads[id] == null)                roadCount++;            roads[id] = r;        }        public void remove(Road r) {            int id = r.getID();            if (roads[id] != null) {                roads[id] = null;                if (id < look)                    look = id;                --roadCount;            }        }        public int findUnusedID() {            while (look < roads.length && roads[look] != null) {                look++;            }            return look;        }        public Road elementAt(int n) {            return roads[n];        }        public Enumeration elements() {            return new Enumeration() {                private int i = 0;                public boolean hasMoreElements() {                    for (; i < roads.length; i++) {                        if (roads[i] != null)                            return true;                    }                    return false;                }                public Object nextElement() {                    return roads[i++];                }            };        }        public int size() {            return roadCount;        }    }    public static class Intersections {        private Hashtable intersections = new Hashtable();        public void put(Intersection intersection) {            int suffix = 0;            String name = intersection.getName();            while (intersections.containsKey(name)) {                suffix++;                name = intersection.getName() + "," + suffix;            }            intersection.setName(name);            intersections.put(name, intersection);        }        public void remove(Intersection intersection) {            intersections.remove(intersection.getName());        }        public Intersection get(String name) {            return (Intersection) intersections.get(name);        }        public Enumeration elements() {            return intersections.elements();        }        public boolean contains(Intersection intersection) {            return intersections.get(intersection.getName()) == intersection;        }        public void clear() {            intersections.clear();        }        public int size() {            return intersections.size();        }    };    public static class RoadClasses extends Hashtable {        float bestConvoySpeed = 0.0f;        float worstConvoySpeed = Float.MAX_VALUE;        public void put(RoadClass roadClass) {            put(roadClass.getName(), roadClass);            if (roadClass.getConvoySpeed() > bestConvoySpeed)                bestConvoySpeed = roadClass.getConvoySpeed();            if (roadClass.getConvoySpeed() < worstConvoySpeed)                worstConvoySpeed = roadClass.getConvoySpeed();        }        public float getBestConvoySpeed() {            return bestConvoySpeed;        }        public float getWorstConvoySpeed() {            return worstConvoySpeed;        }    };    /** BOZO remove me */    public boolean isEditing() {        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -