// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Color.java
// public enum Color {
// 	GREEN, YELLOW, RED
// };
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Observation.java
// public class Observation extends DTO {
// 	public final static String TOPIC = "osgi/trains/observation";
// 
// 	public enum Type {
// 		CHANGE, //
// 		/**
// 		 * Detected an RFID
// 		 */
// 		LOCATED, 
// 		/**
// 		 * Assignment changed
// 		 */
// 		ASSIGNMENT, 
// 		/**
// 		 * Assignment reached
// 		 */
// 		ASSIGNMENT_REACHED,
// 		/**
// 		 * Signal changed color
// 		 */
// 		SIGNAL,
// 		/**
// 		 * Switched changed alternate state
// 		 */
// 		SWITCH,
// 		/**
// 		 * A segment is blocked 
// 		 */
// 		BLOCKED,
// 		/**
// 		 * A segment is dark
// 		 */
// 		DARK,
// 		/**
// 		 * A train emergency occurs
// 		 */
// 		EMERGENCY
// 		
// 	}
// 
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	public Color signal;
// 	public String assignment;
// 	public long time;
// 	public long id;
// 	public String message;
// 	public boolean alternate;
// 	public boolean blocked;
// 	public boolean dark;
// 	public boolean emergency;
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Segment.java
// public class Segment extends DTO {
// 
// 	public enum Type {
// 		STRAIGHT, CURVED, SWITCH, SIGNAL, LOCATOR, BLOCK;
// 	}
// 	
// 
// 	/**
// 	 * Our Identity
// 	 */
// 	public String id;
// 	
// 	/**
// 	 * Type of the segment
// 	 */
//  	public Type type;
// 
// 	/**
//  	* Name of the track.This is the name required to get permission 
//  	* from the Track Manager. If this name starts with X then no admission is required. This 
//  	* is generally for switches.
//  	*/
//  	public String track;
//  	
// 	/**
// 	 * Sequence of the segment in the track
// 	 */
// 	public int sequence;
// 
// 	/**
// 	 * Length of the segment in millimeters, can be zero. It an be zero because
// 	 * the relation between the controllers and the switches and the signals is
// 	 * not always 1:1 mappable to controllers. Therefore zero sized segments can
// 	 * be used to map correctly.
// 	 */
// 	public int length;
// 
// 	/**
// 	 * Short code for RFID tag attached to this segment, or 0 for none.
// 	 */
// 	public int tagCode;
// 
// 	/**
// 	 * The associated controller
// 	 */
// 	public int controller = -1;
// 
// 	/**
// 	 * The next segment. Only a switch can have an additional to. The second to
// 	 * is the one selected if the switch is set to its alternative.
// 	 */
// 	public String to[];
// 	
// 	/**
// 	 * The previous segment. Only a switch can have an additional from. The second from
// 	 * is the one selected if the switch is set to its alternative.
// 	 */
// 	public String from[];
// 
// }


import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import osgi.enroute.dto.api.TypeReference;
import osgi.enroute.trains.cloud.api.Color;
import osgi.enroute.trains.cloud.api.Observation;
import osgi.enroute.trains.cloud.api.Segment;
import osgi.enroute.trains.cloud.api.TrackConfiguration;
				while(route.size() > marker){
					route.remove(marker);
				}
			}

			return false;

		}

		public Collection<SegmentHandler<T>> move(boolean forward) {
			return Collections.singleton(forward ? next : prev);
		}

		void fixup() {
			segment.to = toIds(move(true));
			segment.from = toIds(move(false));
			segment.length = length();
		}

		protected int length() {
			return 0;
		}

		protected boolean isRoot() {
			return segment.id.equals(rootSegment);
		}

		/**
		 * Events should be handled in subclasses if they have relevant events
		 */
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Color.java
// public enum Color {
// 	GREEN, YELLOW, RED
// };
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Observation.java
// public class Observation extends DTO {
// 	public final static String TOPIC = "osgi/trains/observation";
// 
// 	public enum Type {
// 		CHANGE, //
// 		/**
// 		 * Detected an RFID
// 		 */
// 		LOCATED, 
// 		/**
// 		 * Assignment changed
// 		 */
// 		ASSIGNMENT, 
// 		/**
// 		 * Assignment reached
// 		 */
// 		ASSIGNMENT_REACHED,
// 		/**
// 		 * Signal changed color
// 		 */
// 		SIGNAL,
// 		/**
// 		 * Switched changed alternate state
// 		 */
// 		SWITCH,
// 		/**
// 		 * A segment is blocked 
// 		 */
// 		BLOCKED,
// 		/**
// 		 * A segment is dark
// 		 */
// 		DARK,
// 		/**
// 		 * A train emergency occurs
// 		 */
// 		EMERGENCY
// 		
// 	}
// 
// 	public Type type;
// 	public String segment;
// 	public String train;
// 	public Color signal;
// 	public String assignment;
// 	public long time;
// 	public long id;
// 	public String message;
// 	public boolean alternate;
// 	public boolean blocked;
// 	public boolean dark;
// 	public boolean emergency;
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Segment.java
// public class Segment extends DTO {
// 
// 	public enum Type {
// 		STRAIGHT, CURVED, SWITCH, SIGNAL, LOCATOR, BLOCK;
// 	}
// 	
// 
// 	/**
// 	 * Our Identity
// 	 */
// 	public String id;
// 	
// 	/**
// 	 * Type of the segment
// 	 */
//  	public Type type;
// 
// 	/**
//  	* Name of the track.This is the name required to get permission 
//  	* from the Track Manager. If this name starts with X then no admission is required. This 
//  	* is generally for switches.
//  	*/
//  	public String track;
//  	
// 	/**
// 	 * Sequence of the segment in the track
// 	 */
// 	public int sequence;
// 
// 	/**
// 	 * Length of the segment in millimeters, can be zero. It an be zero because
// 	 * the relation between the controllers and the switches and the signals is
// 	 * not always 1:1 mappable to controllers. Therefore zero sized segments can
// 	 * be used to map correctly.
// 	 */
// 	public int length;
// 
// 	/**
// 	 * Short code for RFID tag attached to this segment, or 0 for none.
// 	 */
// 	public int tagCode;
// 
// 	/**
// 	 * The associated controller
// 	 */
// 	public int controller = -1;
// 
// 	/**
// 	 * The next segment. Only a switch can have an additional to. The second to
// 	 * is the one selected if the switch is set to its alternative.
// 	 */
// 	public String to[];
// 	
// 	/**
// 	 * The previous segment. Only a switch can have an additional from. The second from
// 	 * is the one selected if the switch is set to its alternative.
// 	 */
// 	public String from[];
// 
// }


// Path: osgi.enroute.trains.util/src/osgi/enroute/trains/track/util/Tracks.java
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import osgi.enroute.dto.api.TypeReference;
import osgi.enroute.trains.cloud.api.Color;
import osgi.enroute.trains.cloud.api.Observation;
import osgi.enroute.trains.cloud.api.Segment;
import osgi.enroute.trains.cloud.api.TrackConfiguration;

				while(route.size() > marker){
					route.remove(marker);
				}
			}

			return false;

		}

		public Collection<SegmentHandler<T>> move(boolean forward) {
			return Collections.singleton(forward ? next : prev);
		}

		void fixup() {
			segment.to = toIds(move(true));
			segment.from = toIds(move(false));
			segment.length = length();
		}

		protected int length() {
			return 0;
		}

		protected boolean isRoot() {
			return segment.id.equals(rootSegment);
		}

		/**
		 * Events should be handled in subclasses if they have relevant events
		 */
		public boolean event(Observation e) {