Rev | Line | |
---|
[31] | 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 | ***********************************************************************************/ |
---|
| 6 | package vnsim.vehicular.simulator.intersections; |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | import java.io.Serializable; |
---|
| 10 | |
---|
| 11 | import vnsim.map.object.Globals; |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | public class TrafficLightInfo implements Serializable { |
---|
| 16 | |
---|
| 17 | /** <code>serialVersionUID</code> */ |
---|
| 18 | private static final long serialVersionUID = -5883719321862303634L; |
---|
| 19 | |
---|
| 20 | //[secs] |
---|
| 21 | public int greenStart; |
---|
| 22 | public int greenEnd; |
---|
| 23 | public int yellowStart; |
---|
| 24 | public int yellowEnd; |
---|
| 25 | |
---|
| 26 | public static int TIMEYELLOW=3; |
---|
| 27 | //any other time is red |
---|
| 28 | |
---|
| 29 | public TrafficLightInfo(int greenStart, int greenEnd) { |
---|
| 30 | this.greenStart=greenStart; |
---|
| 31 | this.greenEnd=greenEnd; |
---|
| 32 | yellowStart=greenEnd; |
---|
| 33 | yellowEnd=yellowStart+TIMEYELLOW; |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | public TrafficLightInfo(int greenStart, int greenEnd, int yellowTime) { |
---|
| 37 | this.greenStart=greenStart; |
---|
| 38 | this.greenEnd=greenEnd; |
---|
| 39 | yellowStart=greenEnd; |
---|
| 40 | yellowEnd=yellowStart + yellowTime; |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | public int getColor(double timeSec) { |
---|
| 44 | //1=RED, 2=YELLOW, 3=GREEN |
---|
| 45 | if(timeSec>=greenStart && timeSec<greenEnd) |
---|
| 46 | return Globals.GREEN; |
---|
| 47 | if(timeSec>=yellowStart && timeSec<yellowEnd) |
---|
| 48 | return Globals.YELLOW; |
---|
| 49 | return Globals.RED; |
---|
| 50 | } |
---|
| 51 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.