<commit_before>package eagle.sdkInterface;

import java.util.HashMap;
import java.util.Stack;

import eagle.navigation.positioning.Position;
import eagle.navigation.positioning.PositionDisplacement;
import eagle.navigation.positioning.PositionGPS;
import eagle.navigation.positioning.PositionMetric;
import eagle.sdkInterface.sensorAdaptors.AdaptorAccelerometer;
import eagle.sdkInterface.sensorAdaptors.AdaptorBearing;
import eagle.sdkInterface.sensorAdaptors.AdaptorCamera;
import eagle.sdkInterface.sensorAdaptors.AdaptorGPS;
import eagle.sdkInterface.sensorAdaptors.AdaptorGyroscope;
import eagle.sdkInterface.sensorAdaptors.AdaptorLIDAR;
import eagle.sdkInterface.sensorAdaptors.AdaptorMagnetic;
import eagle.sdkInterface.sensorAdaptors.AdaptorRPLIDAR;
import eagle.sdkInterface.sensorAdaptors.AdaptorUltrasonic;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorAccelerometerEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorBearingEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorCameraEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorGPSEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorGyroscopeEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorLIDAREventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorMagneticEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorRPLIDAREventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorUltrasonicEventCallback;

/**
 * SDK Adaptor Flight Stack Class
 *
 * @author <NAME> [<EMAIL>]
 * @version 0.0.1
 * @since 30/09/2015
 * <p/>
 * Date Modified	30/09/2015 - Nicholas
 */
public class SDKAdaptorTaskStack {
    private Stack<SDKAdaptorTask> sdkAdaptorTasks;
    private SDKAdaptor sdkAdaptor;
    private Thread sdkAdaptorTaskStackThread;

    public SDKAdaptorTaskStack(SDKAdaptor sdkAdaptor) {
        this.sdkAdaptor = sdkAdaptor;
        sdkAdaptorTasks = new Stack<SDKAdaptorTask>();
    }

    public void push(SDKAdaptorTask sdkAdaptorTask){
        sdkAdaptorTasks.push(sdkAdaptorTask);
    }

    public void push(int delay) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Delay(delay));
    }

    public void push(Position position) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Position(position).Speed(sdkAdaptor.getMaxSpeed()));
    }

    public void push(Position position, double metersPerSecond) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Position(position).Speed(metersPerSecond));
    }

    public void run(final SDKAdaptorCallback sdkAdaptorCallback) {
        if (sdkAdaptorCallback == null)
            throw new IllegalArgumentException("Callback Required");
        else {
            sdkAdaptorTaskStackThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    while (!sdkAdaptorTasks.empty()) {
                        SDKAdaptorTask sdkAdaptorTask = sdkAdaptorTasks.pop();
                        if (sdkAdaptorTask.position != null) {
                            if (sdkAdaptorTask.position instanceof PositionGPS) {
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                            Thread.currentThread().interrupt();
                                        }
                                    }
                                }, (PositionGPS) sdkAdaptorTask.position);
                            } else if (sdkAdaptorTask.position instanceof PositionDisplacement) {
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                            Thread.currentThread().interrupt();
                                        }
                                    }
                                }, (PositionDisplacement) sdkAdaptorTask.position);
                            } else if (sdkAdaptorTask.position instanceof PositionMetric) {
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                            Thread.currentThread().interrupt();
                                        }
                                    }
                                }, (PositionMetric) sdkAdaptorTask.position);
                            }
                        }
                        if (sdkAdaptorTask.delay > 0)
                            sdkAdaptor.delay(sdkAdaptorTask.delay);
                        if (sdkAdaptorTask.sensorEventAccelerometer != null) {
                            for (AdaptorAccelerometer adaptorAccelerometer : sdkAdaptorTask.sensorEventAccelerometer.keySet())
                                sdkAdaptorTask.sensorEventAccelerometer.get(adaptorAccelerometer).onSensorEvent(adaptorAccelerometer.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventBearing != null) {
                            for (AdaptorBearing adaptorBearing : sdkAdaptorTask.sensorEventBearing.keySet())
                                sdkAdaptorTask.sensorEventBearing.get(adaptorBearing).onSensorEvent(adaptorBearing.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventCamera != null) {
                            for (AdaptorCamera adaptorCamera : sdkAdaptorTask.sensorEventCamera.keySet())
                                sdkAdaptorTask.sensorEventCamera.get(adaptorCamera).onSensorEvent(adaptorCamera.getData());
                        }
                        if (sdkAdaptorTask.sensorEventGPS != null) {
                            for (AdaptorGPS adaptorGPS : sdkAdaptorTask.sensorEventGPS.keySet())
                                sdkAdaptorTask.sensorEventGPS.get(adaptorGPS).onSensorEvent(adaptorGPS.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventGyroscope != null) {
                            for (AdaptorGyroscope adaptorGyroscope : sdkAdaptorTask.sensorEventGyroscope.keySet())
                                sdkAdaptorTask.sensorEventGyroscope.get(adaptorGyroscope).onSensorEvent(adaptorGyroscope.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventLIDAR != null) {
                            for (AdaptorLIDAR adaptorLIDAR : sdkAdaptorTask.sensorEventLIDAR.keySet())
                                sdkAdaptorTask.sensorEventLIDAR.get(adaptorLIDAR).onSensorEvent(adaptorLIDAR.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventMagnetic != null) {
                            for (AdaptorMagnetic adaptorMagnetic : sdkAdaptorTask.sensorEventMagnetic.keySet())
                                sdkAdaptorTask.sensorEventMagnetic.get(adaptorMagnetic).onSensorEvent(adaptorMagnetic.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventRPLIDAR != null) {
                            for (AdaptorRPLIDAR adaptorRPLIDAR : sdkAdaptorTask.sensorEventRPLIDAR.keySet())
                                sdkAdaptorTask.sensorEventRPLIDAR.get(adaptorRPLIDAR).onSensorEvent(adaptorRPLIDAR.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventUltrasonic != null) {
                            for (AdaptorUltrasonic adaptorUltrasonic : sdkAdaptorTask.sensorEventUltrasonic.keySet())
                                sdkAdaptorTask.sensorEventUltrasonic.get(adaptorUltrasonic).onSensorEvent(adaptorUltrasonic.getCalibratedData());
                        }
                    }
                    sdkAdaptorCallback.onResult(true, "Stack Execution Successful");
                }
            });
            sdkAdaptorTaskStackThread.start();
        }
    }

    public void interupt() {<commit_msg>ENHANCE: Stack now Thread Tollerable<commit_after>package eagle.sdkInterface;

import java.util.HashMap;
import java.util.Stack;

import eagle.navigation.positioning.Position;
import eagle.navigation.positioning.PositionDisplacement;
import eagle.navigation.positioning.PositionGPS;
import eagle.navigation.positioning.PositionMetric;
import eagle.sdkInterface.sensorAdaptors.AdaptorAccelerometer;
import eagle.sdkInterface.sensorAdaptors.AdaptorBearing;
import eagle.sdkInterface.sensorAdaptors.AdaptorCamera;
import eagle.sdkInterface.sensorAdaptors.AdaptorGPS;
import eagle.sdkInterface.sensorAdaptors.AdaptorGyroscope;
import eagle.sdkInterface.sensorAdaptors.AdaptorLIDAR;
import eagle.sdkInterface.sensorAdaptors.AdaptorMagnetic;
import eagle.sdkInterface.sensorAdaptors.AdaptorRPLIDAR;
import eagle.sdkInterface.sensorAdaptors.AdaptorUltrasonic;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorAccelerometerEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorBearingEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorCameraEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorGPSEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorGyroscopeEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorLIDAREventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorMagneticEventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorRPLIDAREventCallback;
import eagle.sdkInterface.sensorAdaptors.sensorAdaptorCallbacks.AdaptorUltrasonicEventCallback;

/**
 * SDK Adaptor Flight Stack Class
 *
 * @author <NAME> [<EMAIL>]
 * @version 0.0.1
 * @since 30/09/2015
 * <p/>
 * Date Modified	30/09/2015 - Nicholas
 */
public class SDKAdaptorTaskStack {
    private Stack<SDKAdaptorTask> sdkAdaptorTasks;
    private SDKAdaptor sdkAdaptor;
    private Thread sdkAdaptorTaskStackThread;

    public SDKAdaptorTaskStack(SDKAdaptor sdkAdaptor) {
        this.sdkAdaptor = sdkAdaptor;
        sdkAdaptorTasks = new Stack<SDKAdaptorTask>();
    }

    public void push(SDKAdaptorTask sdkAdaptorTask) {
        sdkAdaptorTasks.push(sdkAdaptorTask);
    }

    public void push(int delay) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Delay(delay));
    }

    public void push(Position position) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Position(position).Speed(sdkAdaptor.getMaxSpeed()));
    }

    public void push(Position position, double metersPerSecond) {
        sdkAdaptorTasks.push(new SDKAdaptorTask().Position(position).Speed(metersPerSecond));
    }

    public void run(final SDKAdaptorCallback sdkAdaptorCallback) {
        if (sdkAdaptorCallback == null)
            throw new IllegalArgumentException("Callback Required");
        else {
            sdkAdaptorTaskStackThread = new Thread(new Runnable() {
                @Override
                public void run() {
                    final Boolean[] onResult = {null, null};
                    while (!sdkAdaptorTasks.empty()) {
                        onResult[0] = null;
                        onResult[1] = null;
                        SDKAdaptorTask sdkAdaptorTask = sdkAdaptorTasks.pop();
                        if (sdkAdaptorTask.position != null) {
                            if (sdkAdaptorTask.position instanceof PositionGPS) {
                                onResult[0] = false;
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        onResult[0] = true;
                                        onResult[1] = booleanResult;
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                        }
                                    }
                                }, (PositionGPS) sdkAdaptorTask.position);
                            } else if (sdkAdaptorTask.position instanceof PositionDisplacement) {
                                onResult[0] = false;
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        onResult[0] = true;
                                        onResult[1] = booleanResult;
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                        }
                                    }
                                }, (PositionDisplacement) sdkAdaptorTask.position);
                            } else if (sdkAdaptorTask.position instanceof PositionMetric) {
                                onResult[0] = false;
                                sdkAdaptor.flyTo(new SDKAdaptorCallback() {
                                    @Override
                                    public void onResult(boolean booleanResult, String stringResult) {
                                        onResult[0] = true;
                                        onResult[1] = booleanResult;
                                        if (!booleanResult) {
                                            sdkAdaptorCallback.onResult(booleanResult, stringResult);
                                            onResult[0] = true;
                                        }
                                    }
                                }, (PositionMetric) sdkAdaptorTask.position);
                            }
                        }
                        if (sdkAdaptorTask.delay > 0) {
                            try {
                                Thread.sleep(sdkAdaptorTask.delay);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        if (sdkAdaptorTask.sensorEventAccelerometer != null) {
                            for (AdaptorAccelerometer adaptorAccelerometer : sdkAdaptorTask.sensorEventAccelerometer.keySet())
                                sdkAdaptorTask.sensorEventAccelerometer.get(adaptorAccelerometer).onSensorEvent(adaptorAccelerometer.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventBearing != null) {
                            for (AdaptorBearing adaptorBearing : sdkAdaptorTask.sensorEventBearing.keySet())
                                sdkAdaptorTask.sensorEventBearing.get(adaptorBearing).onSensorEvent(adaptorBearing.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventCamera != null) {
                            for (AdaptorCamera adaptorCamera : sdkAdaptorTask.sensorEventCamera.keySet())
                                sdkAdaptorTask.sensorEventCamera.get(adaptorCamera).onSensorEvent(adaptorCamera.getData());
                        }
                        if (sdkAdaptorTask.sensorEventGPS != null) {
                            for (AdaptorGPS adaptorGPS : sdkAdaptorTask.sensorEventGPS.keySet())
                                sdkAdaptorTask.sensorEventGPS.get(adaptorGPS).onSensorEvent(adaptorGPS.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventGyroscope != null) {
                            for (AdaptorGyroscope adaptorGyroscope : sdkAdaptorTask.sensorEventGyroscope.keySet())
                                sdkAdaptorTask.sensorEventGyroscope.get(adaptorGyroscope).onSensorEvent(adaptorGyroscope.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventLIDAR != null) {
                            for (AdaptorLIDAR adaptorLIDAR : sdkAdaptorTask.sensorEventLIDAR.keySet())
                                sdkAdaptorTask.sensorEventLIDAR.get(adaptorLIDAR).onSensorEvent(adaptorLIDAR.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventMagnetic != null) {
                            for (AdaptorMagnetic adaptorMagnetic : sdkAdaptorTask.sensorEventMagnetic.keySet())
                                sdkAdaptorTask.sensorEventMagnetic.get(adaptorMagnetic).onSensorEvent(adaptorMagnetic.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventRPLIDAR != null) {
                            for (AdaptorRPLIDAR adaptorRPLIDAR : sdkAdaptorTask.sensorEventRPLIDAR.keySet())
                                sdkAdaptorTask.sensorEventRPLIDAR.get(adaptorRPLIDAR).onSensorEvent(adaptorRPLIDAR.getCalibratedData());
                        }
                        if (sdkAdaptorTask.sensorEventUltrasonic != null) {
                            for (AdaptorUltrasonic adaptorUltrasonic : sdkAdaptorTask.sensorEventUltrasonic.keySet())
                                sdkAdaptorTask.sensorEventUltrasonic.get(adaptorUltrasonic).onSensorEvent(adaptorUltrasonic.getCalibratedData());
                        }

                        while(onResult[0]!=null){
                            if (!onResult[0]){
                                try {
                                    Thread.sleep(1);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }else{
                                onResult[0] = null;
                                if (!onResult[1]);
                                    interupt();
                            }
                        }
                    }
                    sdkAdaptorCallback.onResult(true, "Stack Execution Successful");
                }
            });
            sdkAdaptorTaskStackThread.start();
        }
    }

    public void interupt() {
{'fraction_non_alphanumeric': 0.07067488508148767, 'fraction_numerical': 0.0029774341830338487, 'mean_word_length': 1.6723897264098269, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 73, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3111243', 'n_tokens_mistral': 5052, 'n_tokens_neox': 4723, 'n_words': 624}