View Javadoc

1   /*
2    * @(#)SimpleTrackLink.java Jun 19, 2004
3    * 
4    * Copyright (c) 2003, 2004 Delft University of Technology Jaffalaan 5, 2628 BX
5    * Delft, the Netherlands All rights reserved.
6    * 
7    * This software is proprietary information of Delft University of Technology
8    * The code is published under the General Public License
9    */
10  
11  package nl.tudelft.simulation.traffic.track;
12  
13  import java.rmi.RemoteException;
14  
15  import javax.media.j3d.BoundingSphere;
16  import javax.media.j3d.Bounds;
17  import javax.vecmath.Point3d;
18  
19  import nl.tudelft.simulation.language.d3.DirectedPoint;
20  import nl.tudelft.simulation.logger.Logger;
21  import nl.tudelft.simulation.traffic.track.util.TrackList;
22  
23  /***
24   * This is a simple track link, with one predecessor and one successor. <br>
25   * <br>
26   * (c) copyright 2003-2004 <a href="http://www.simulation.tudelft.nl">Delft
27   * University of Technology </a>, the Netherlands. <br>
28   * See for project information <a href="http://www.simulation.tudelft.nl">
29   * www.simulation.tudelft.nl </a> <br>
30   * License of use: <a href="http://www.gnu.org/copyleft/gpl.html">General Public
31   * License (GPL) </a>, no warranty <br>
32   * 
33   * @version Jun 19, 2004 <br>
34   * @author <a
35   * href="http://www.tbm.tudelft.nl/webstaf/alexandv/index.htm">Alexander
36   * Verbraeck </a>
37   */
38  public class SimpleTrackLink extends DirectedPoint
39          implements
40              TrackLinkInterface
41  {
42      /*** the link name */
43      private String name;
44  
45      /*** the predecessor track */
46      private TrackInterface predecessor = null;
47  
48      /*** the successor track */
49      private TrackInterface successor = null;
50  
51      /***
52       * Construct a new SimpleTrackLink
53       * 
54       * @param name
55       * @param location
56       *  
57       */
58      public SimpleTrackLink(final String name, final DirectedPoint location)
59      {
60          super(location);
61          this.name = name;
62      }
63  
64      /***
65       * Construct a new SimpleTrackLink
66       * 
67       * @param name
68       * @param point
69       *  
70       */
71      public SimpleTrackLink(final String name, final Point3d point)
72      {
73          super(point);
74          this.name = name;
75      }
76  
77      /***
78       * Construct a new SimpleTrackLink
79       * 
80       * @param name
81       * @param x
82       * @param y
83       * @param z
84       *  
85       */
86      public SimpleTrackLink(final String name, final double x, final double y,
87              final double z)
88      {
89          super(x, y, z);
90          this.name = name;
91      }
92  
93      /***
94       * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#addSuccessor(TrackInterface)
95       */
96      public void addSuccessor(final TrackInterface successor)
97      {
98          if (this.successor != null)
99              Logger.warning(this, "addSuccessor", "Successor for " + this.name
100                     + " already defined as " + this.successor + ", while "
101                     + successor + " added");
102         this.successor = successor;
103     }
104 
105     /***
106      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#addPredecessor(TrackInterface)
107      */
108     public void addPredecessor(final TrackInterface predecessor)
109     {
110         if (this.predecessor != null)
111             Logger.warning(this, "addPredecessor", "Predecessor for "
112                     + this.name + " already defined as " + this.predecessor
113                     + ", while " + predecessor + " added");
114         this.predecessor = predecessor;
115     }
116 
117     /***
118      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#setActiveSuccessor(TrackInterface,
119      * TrackInterface)
120      */
121     public void setActiveSuccessor(final TrackInterface predecessor,
122             final TrackInterface successor)
123     {
124         if (!predecessor.equals(this.predecessor))
125             Logger.warning(this, "setActiveSuccessor", "Predecessor "
126                     + predecessor + " for " + this.name
127                     + " not in list of predecessor");
128         if (!successor.equals(this.successor))
129             Logger.warning(this, "setActiveSuccessor", "Active successor "
130                     + successor + " for " + this.name
131                     + " not in list of successors");
132     }
133 
134     /***
135      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getActiveSuccessor(TrackInterface)
136      */
137     public TrackInterface getActiveSuccessor(final TrackInterface predecessor)
138     {
139         if (!predecessor.equals(this.predecessor))
140             Logger.warning(this, "getActiveSuccessor", "Predecessor "
141                     + predecessor + " for " + this.name
142                     + " not in list of predecessors");
143         return this.successor;
144     }
145 
146     /***
147      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getSuccessors()
148      */
149     public TrackList getSuccessors()
150     {
151         TrackList trackList = new TrackList();
152         trackList.add(this.successor);
153         return trackList;
154     }
155 
156     /***
157      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getPredecessors()
158      */
159     public TrackList getPredecessors()
160     {
161         TrackList trackList = new TrackList();
162         trackList.add(this.predecessor);
163         return trackList;
164     }
165 
166     /***
167      * @see nl.tudelft.simulation.traffic.track.TrackLinkInterface#getPosition()
168      */
169     public Point3d getPosition()
170     {
171         return this;
172     }
173 
174     /***
175      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getBounds()
176      */
177     public Bounds getBounds()
178     {
179         return new BoundingSphere(this, 1.0);
180     }
181 
182     /***
183      * @see nl.tudelft.simulation.dsol.animation.LocatableInterface#getLocation()
184      */
185     public DirectedPoint getLocation() throws RemoteException
186     {
187         return this;
188     }
189 
190     /***
191      * @see java.lang.Object#toString()
192      */
193     public String toString()
194     {
195         return this.name;
196     }
197 }