gt:         if (currentDct == null) {
context: package com.sheffield.leapmotion.output;
  
  import com.leapmotion.leap.*;
  import com.sheffield.leapmotion.App;
  import com.sheffield.leapmotion.Properties;
  import com.sheffield.leapmotion.controller.mocks.HandFactory;
  import com.sheffield.leapmotion.frame.util.QuaternionHelper;
  import com.sheffield.leapmotion.util.FileHandler;
  import com.sheffield.leapmotion.util.Serializer;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  
  /**
   * Created by thomas on 11/03/2016.
   */
  public class FrameDeconstructor {
  
      private String uniqueId = "";
      private String currentGesture = "";
      private String filenameStart = "";
      private String addition = "";
  
      public static long[] BREAK_TIMES = new long[]{Properties.RUNTIME};
  
      private boolean calculatingScreenshot = false;
  
  
      private File currentDct;
      private File currentDctGestures;
      private File currentSequence;
      private File currentHands;
      private File currentHandsSingleModel;
      private File currentHandJoints;
      private File currentPosition;
      private File currentRotation;
      private File currentGestures;
      private File currentGesturesCircle;
      private File currentGesturesSwipe;
      private File currentGesturesScreenTap;
      private File currentGesturesKeyTap;
      private File sequenceFile = null;
  
      private int breakIndex = 0;
  
      private ArrayList<String> handIds;
      private ArrayList<String> gestures;
  
  
      //1 state capture/second
      //private static final int STATE_CAPTURE_TIME = 300;
      private long lastStateCapture = 0;
      private File currentStab;
  
      public FrameDeconstructor() {
          handIds = new ArrayList<String>();
          gestures = new ArrayList<String>();
  
          BREAK_TIMES[0] = Properties.RUNTIME;
      }
  
      public void addHandId(String id){
          handIds.add(id);
      }
  
      public void addGesture(String gesture){
          if (gesture != null) {
              gestures.add(gesture);
          }
      }
  
      public void setUniqueId(String uId) {
          uniqueId = uId;
      }
      
      public void setCurrentGesture(String g) {
          gestures.add(g);
      }
  
      public void setFilenameStart(String fns) {
          filenameStart = fns;
      }
  
      public void setAddition(String add) {
          addition = add;
      }
  
      public void resetFiles(int breakIndex) {
          sequenceFile = null;
          currentHands = null;
          currentHandsSingleModel = null;
          currentRotation = null;
          currentPosition = null;
          currentSequence = null;
          currentGestures = null;
          currentDct = null;
          currentDctGestures = null;
  
          this.breakIndex = breakIndex;
      }
  
      public void outputRawFrameData(Frame frame) {
          try {
              boolean start = false;
  
              if (sequenceFile == null) {
                  sequenceFile = new File(FileHandler.generateFileWithName(filenameStart) + "/raw_frame_data.bin");
                  sequenceFile.getParentFile().mkdirs();
                  sequenceFile.createNewFile();
                  //com.sheffield.leapmotion.util.FileHandler.appendToFile(sequenceFile, "[");
                  start = true;
              }
              String content = Serializer.sequenceToJson(frame);
              if (start) {
                  FileHandler.writeToFile(sequenceFile, content);
              } else {
                  FileHandler.appendToFile(sequenceFile, "\n" + content);
              }
  
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
      }
  
      public void outputSequence() throws IOException {
          if (currentSequence == null) {
              currentSequence = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/sequence_hand_data");
              currentSequence.getParentFile().mkdirs();
              currentSequence.createNewFile();
          }
          FileHandler.appendToFile(currentSequence, uniqueId + ",");
      }
  
      public String getStabilisedTip(Hand h){
          String tips = uniqueId;
  
          tips += "," + h.stabilizedPalmPosition().getX() +
                  "," + h.stabilizedPalmPosition().getY() +
                  "," + h.stabilizedPalmPosition().getZ();
  
          Vector thumb = h.fingers().fingerType(Finger.Type.TYPE_THUMB).get(0).stabilizedTipPosition();
  
          tips += "," + thumb.getX() +
                  "," + thumb.getY() +
                  "," + thumb.getZ();
  
          for (Finger.Type ft : HandFactory.fingerTypes){
              Finger f = h.fingers().fingerType(ft).get(0);
              tips += "," + f.stabilizedTipPosition().getX() + "," +
                      f.stabilizedTipPosition().getY() + "," +
                      f.stabilizedTipPosition().getZ();
          }
          return tips;
      }
  
      public void outputStabilisedTip(Hand h) throws IOException {
  
          String tips = getStabilisedTip(h);
  
          if (currentStab == null) {
              currentStab= new File(FileHandler.generateFileWithName(filenameStart) + addition + "/stabilised_tip_pool.ARFF");
              currentStab.getParentFile().mkdirs();
              currentStab.createNewFile();
  
              FileHandler.writeToFile(currentStab, getHeaders(tips, "stabtips"));
          }
          FileHandler.appendToFile(currentStab, tips + "\n");
      }
  
      public void outputJointPositionModel(String frameAsString) throws IOException {
          if (currentHands == null) {
              currentHands = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/joint_positions_pool.ARFF");
              currentHands.getParentFile().mkdirs();
              currentHands.createNewFile();
  
              FileHandler.writeToFile(currentHands, getHeaders(frameAsString, "jointposition"));
          }
          FileHandler.appendToFile(currentHands, frameAsString + "\n");
      }
  
      public void outputFeaturelessHand(String id, Hand h) throws IOException {
          String frameAsString = HandFactory.handToFeaturelessString(id, h);
          if (currentHandsSingleModel == null) {
              currentHandsSingleModel = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/featureless_hand_pool.ARFF");
              currentHandsSingleModel.getParentFile().mkdirs();
              currentHandsSingleModel.createNewFile();
  
              FileHandler.writeToFile(currentHandsSingleModel, getHeaders(frameAsString, "jointposition"));
          }
          FileHandler.appendToFile(currentHandsSingleModel, frameAsString + "\n");
      }
  
      public void outputHandJointModel(Hand h) throws IOException {
  
          String frameAsString = HandFactory.handToHandJoint(uniqueId, h);
  
          if (currentHandJoints == null) {
              currentHandJoints = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/hand_joints_pool.ARFF");
              currentHandJoints.getParentFile().mkdirs();
              currentHandJoints.createNewFile();
  
              FileHandler.writeToFile(currentHandJoints, getHeaders(frameAsString, "handjoint"));
          }
          FileHandler.appendToFile(currentHandJoints, frameAsString + "\n");
      }
  
      public String getHandPosition(Hand h){
          String position = uniqueId + "," + h.palmPosition().getX() + ","
                  + h.palmPosition().getY() + "," + h.palmPosition().getZ() + "\n";
  
          return position;
      }
  
      public void outputHandPositionModel(Hand h) throws IOException {
  
          String position = getHandPosition(h);
  
          if (currentPosition == null) {
              currentPosition = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/hand_positions_pool.ARFF");
              currentPosition.getParentFile().mkdirs();
              currentPosition.createNewFile();
  
              FileHandler.writeToFile(currentPosition, getHeaders(position, "handposition"));
          }
          FileHandler.appendToFile(currentPosition, position);
      }
  
      public String getHandRotationModel(Hand h) {
          String rotation = uniqueId + ",";
          Vector[] vectors = new Vector[3];
  
          //h.basis().r
  
  //        vectors[0] = h.basis().getXBasis();
  //        vectors[1] = h.basis().getYBasis();
  //        vectors[2] = h.basis().getZBasis();
  
          vectors[0] = h.palmNormal().cross(h.direction()).normalized();
          vectors[1]  = h.palmNormal().opposite();
          vectors[2]  = h.direction().opposite();
  
  
  
          rotation += QuaternionHelper.toQuaternion(vectors).inverse().toCsv();
          rotation += "\n";
  
  
          return rotation;
      }
  
      public void outputHandRotationModel(Hand h) throws IOException {
          String rotation = getHandRotationModel(h);
  
          if (currentRotation == null) {
              currentRotation = new File(FileHandler.generateFileWithName(filenameStart) + addition + "/hand_rotations_pool.ARFF");
              currentRotation.getParentFile().mkdirs();
              currentRotation.createNewFile();
  
              FileHandler.writeToFile(currentRotation, getHeaders(rotation, "handrotation"));
          }
  
  
          FileHandler.appendToFile(currentRotation, rotation);
      }
  
  
      public String getHeaders(String data, String relation){
          int features = data.split(",").length;
  
  
          String header = "% 1. Leap Motion Hands\n"+
                  "% 2. Created by NuiMimic\n" +
                  "@RELATION " + relation + "\n" +
                  "\n" +
                  "@ATTRIBUTE id STRING\n";
  
          for (int i = 1; i < features; i++){
              header += "@ATTRIBUTE v" + i + " NUMERIC\n";
          }
  
  
          header += "@DATA\n";
  
          return header;
      }
  
      public String getHeadersGesture(String data, String relation){
          int features = data.split(",").length;
  
  
          String header = "% 1. Leap Motion Hands\n"+
                  "% 2. Created by NuiMimic\n" +
                  "@RELATION " + relation + "\n" +
                  "\n" +
                  "@ATTRIBUTE id STRING\n" +
                  "@ATTRIBUTE fingerType STRING\n";
  
          for (int i = 2; i < features; i++){
              header += "@ATTRIBUTE v" + i + " NUMERIC\n";
          }
  
  
          header += "@DATA\n";
  
          return header;
      }
  
      public boolean isCalculating() {
          return calculatingScreenshot;
      }
  
      public void outputCurrentState() throws IOException {
          if (calculatingScreenshot) {
              return;
          }
  
          calculatingScreenshot = true;
  