source: proiecte/ptvs/src/vnsim/vehicular/simulator/Location.java @ 31

Last change on this file since 31 was 31, checked in by (none), 14 years ago
File size: 1.4 KB
Line 
1/************************************************************************************
2 * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University
3 * All rights reserved.
4 * Refer to LICENSE for terms and conditions of use.
5 ***********************************************************************************/
6package vnsim.vehicular.simulator;
7
8import vnsim.map.object.*;
9
10public class Location implements Comparable, java.io.Serializable {
11
12        /** <code>serialVersionUID</code> */
13        private static final long serialVersionUID = -5883719321862303634L;
14       
15        public int roadIdx;
16        public int ptIdx;
17
18        public boolean equals(Location loc) {
19//              if(loc.roadIdx==this.roadIdx && loc.ptIdx==this.ptIdx) return true;
20                Road r1=(Road)Globals.map.roads.get(loc.roadIdx);
21                Point pt1=(Point)r1.points.get(loc.ptIdx);
22                Road r2=(Road)Globals.map.roads.get(this.roadIdx);
23                Point pt2=(Point)r2.points.get(this.ptIdx);
24                return pt1.equals(pt2);
25        }
26       
27        public Location(int roadIdx, int ptIdx) {
28                this.roadIdx=roadIdx;
29                this.ptIdx=ptIdx;
30        }
31
32        public int compareTo(Object loc) {
33                Location l=(Location) loc;
34                if(roadIdx==l.roadIdx) {
35                        if(ptIdx>l.ptIdx) {
36                                return 1;
37                        } else if(ptIdx<l.ptIdx) {
38                                return -1;
39                        } else return 0;
40                } else {
41                        if(roadIdx<l.roadIdx) {
42                                return -1;
43                        } else 
44                                return 1;
45                }
46        }
47
48        public String toString(){
49                String ret="";
50                ret=ret+"[Rd "+roadIdx+";Pt "+ptIdx+"]";
51                return ret;
52        }
53}
Note: See TracBrowser for help on using the repository browser.