package Debrief.Wrappers.Track;

import Debrief.Wrappers.FixWrapper;
import MWC.GUI.Plottables;
import MWC.GenericData.HiResDate;

public class FixWrapperCollisionCheck {

	/**
	 * We are creating this method because the following ticket
	 * https://github.com/debrief/debrief/issues/4894
	 *
	 * FixWrapper were initially adding with a +1 time delay to avoid collisions.
	 *
	 * Collision check modifies the time in the fixWrapper given to adapt it to
	 * avoid collision.
	 *
	 * @param _fixWrapper       FixWrapper to modify
	 * @param _currentPlotables List of all the Editables
	 */
	public static void correctTimeCollision(final FixWrapper _fixWrapper, final Plottables _currentPlotables) {
		long timeToAdd = _fixWrapper.getTime().getMicros();
		while (_currentPlotables.contains(_fixWrapper)) {
			timeToAdd += 1000; // add 1 second
			_fixWrapper.getFix().setTime(new HiResDate(timeToAdd / 1000L));
		}
	}
}

@@ -26,16 +26,47 @@
 Track;%0A%0A
+import java.util.Enumeration;%0A%0A
 import D
@@ -93,16 +93,41 @@
 rapper;%0A
+import MWC.GUI.Editable;%0A
 import M
@@ -800,16 +800,290 @@
 cros();%0A
+%09%09%0A%09%09// First check if the exact instance is the list.%0A%09%09final Enumeration%3CEditable%3E elementsEnum = _currentPlotables.elements();%0A%09%09while (elementsEnum.hasMoreElements()) %7B%0A%09%09%09if (elementsEnum.nextElement() == _fixWrapper) %7B%0A%09%09%09%09// We have found it.%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A
 %09%09while 

Check if the exact item already exists, and don't correct it.