Example #1
0
  private synchronized void init() throws SQLException {
    if (isClosed) return;

    // do tables exists?
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(TABLE_NAMES_SELECT_STMT);

    ArrayList<String> missingTables = new ArrayList(TABLES.keySet());
    while (rs.next()) {
      String tableName = rs.getString("name");
      missingTables.remove(tableName);
    }

    for (String missingTable : missingTables) {
      try {
        Statement createStmt = conn.createStatement();
        // System.out.println("Adding table "+ missingTable);
        createStmt.executeUpdate(TABLES.get(missingTable));
        createStmt.close();

      } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
    }
  }
  public void setup() {
    size(600, 400);
    smooth();
    f = createFont("Georgia", 12, true);

    obstacles = new ArrayList();
    boids = new ArrayList();

    // A little algorithm to pick a bunch of random obstacles that don't overlap
    for (int i = 0; i < 100; i++) {
      float x = random(width);
      float y = random(height);
      float r = random(50 - i / 2, 50);
      boolean ok = true;
      for (int j = 0; j < obstacles.size(); j++) {
        Obstacle o = (Obstacle) obstacles.get(j);
        if (dist(x, y, o.loc.x, o.loc.y) < o.radius + r + 20) {
          ok = false;
        }
      }
      if (ok) obstacles.add(new Obstacle(x, y, r));
    }

    // Starting with three boids
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.2f));
    boids.add(new Boid(new PVector(random(width), random(height)), 3f, 0.1f));
    boids.add(new Boid(new PVector(random(width), random(height)), 2f, 0.05f));
  }
Example #3
0
  /*
  	Read in all the files and loop through all the files
  	We already have the hashed version of the documents
  	First, we cut up the first document into chunks (using the CDC algorhtim) and store it
  	Then we cut up the second document (usually a different version of the same document) and see how many chunks match
  */
  private static void runBytes(
      int window,
      long divisor1,
      long divisor2,
      long divisor3,
      long remainder,
      Long minBoundary,
      Long maxBoundary)
      throws Exception {

    storeChunks(
        fileArray.get(0),
        hashed_File_List.get(0),
        divisor1,
        divisor2,
        divisor3,
        remainder,
        minBoundary,
        maxBoundary); // here we run 2min, ck how similar the documents are to the one already in
                      // the system
    runTddd(
        fileArray.get(1),
        hashed_File_List.get(1),
        divisor1,
        divisor2,
        divisor3,
        remainder,
        minBoundary,
        maxBoundary); // here we run 2min, ck how similar the documents are to the one already in
                      // the system
  } // end of the function
Example #4
0
  /*
  	-- This is a helper method run datasets such as emacs, gcc etc

  */
  private static void runOtherDataSets() throws Exception {
    System.out.println("Running tddd " + directory);
    ReadFile.readFile(directory, fileList); // read the two files
    System.out.println(fileList.get(0) + " " + fileList.get(1));
    preliminaryStep(directory);
    startCDC();
  }
 private void safeBeginParagraph() {
   if (!myParagraphStarted) {
     myParagraphStarted = true;
     myBufferIsEmpty = true;
     beginParagraph(ZLTextParagraph.Kind.TEXT_PARAGRAPH);
     if (!myParagraphStored) {
       // final ArrayList models = Model.getBookTextModels();
       // myParagraphVector.add(new Pair(((ZLTextPlainModel)
       // models.get(models.size()-1)/*BookTextModel*/).getParagraphsNumber() - 1, models.size() -
       // 1));
       myParagraphStored = true;
     }
     for (Iterator it = myDelayedControls.iterator(); it.hasNext(); ) {
       Pair pit = (Pair) it.next();
       addControl((Byte) pit.myFirst, (Boolean) pit.mySecond);
     }
     // if (myForcedEntry != null) {
     //	addControl(myForcedEntry);
     // } else {
     addControl(FBTextKind.REGULAR, true);
     // }
     for (Iterator it = myDelayedHyperlinks.iterator(); it.hasNext(); ) {
       addHyperlinkControl(FBTextKind.INTERNAL_HYPERLINK, (String) it.next());
     }
     myDelayedHyperlinks.clear();
   }
 }
    public void trace(float x, float y) {

      println(x);

      if (frameCounter > 2 && mousePressed) {
        coords.add(new PVector(x, y));
        frameCounter = 0;
        if (coordCounter > 0) {
          PVector tempCoord = (PVector) coords.get(coordCounter - 1);
          line(x, y, tempCoord.x, tempCoord.y);
        }
        coordCounter++;
      }
      // println(coordCounter);

      for (int i = 0; i < coords.size(); i++) {
        PVector tempCoordnear = (PVector) coords.get(i);
        float coordDist = dist(x, y, tempCoordnear.x, tempCoordnear.y);
        if (coordDist < distance) {
          stroke(255, 0, 0);
          line(x, y, tempCoordnear.x, tempCoordnear.y);
        }
      }
      frameCounter++;
    }
Example #7
0
  /*
  	-- This is a helper methid to run the morph files
  */
  private static void runMorphDataSet() throws Exception {

    String morph_directory =
        "../../thesis-datasets/morph/"; // directory where all the morph code is stored
    File d = new File(morph_directory);
    // get all the files from a directory
    File[] fList = d.listFiles();
    List<String> dir_list = new ArrayList<String>();
    for (File file : fList) {
      if (file.isDirectory()) {
        dir_list.add(file.getName());
      }
    }
    for (String dir : dir_list) {
      directory = morph_directory + dir + "/";
      System.out.println("Running TDDD " + directory);
      ReadFile.readFile(directory, fileList); // read the two files
      System.out.println(fileList.get(0) + " " + fileList.get(1));
      preliminaryStep(directory);
      startCDC();
      fileList.clear();
      fileArray.clear();
      hashed_File_List.clear();
    }
  }
Example #8
0
    public ArrayList getPastObjectStates() {
      ArrayList alPast = new ArrayList();
      for (int i = intTimeIdx; i > 0 && i > intTimeIdx - 100; i--) {
        alPast.add(this.alObjectStateArchive.get(i));
      }

      return alPast;
    }
Example #9
0
    // Does a deepcopy of an array list
    public static ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        alNew.add(((CelestialObject) al.get(i)).clone());
      }

      return alNew;
    }
Example #10
0
    // Does a deepcopy of an array list
    public ArrayList cloneArrayList(ArrayList al) {
      ArrayList alNew = new ArrayList(al.size());
      for (int i = 0; i < al.size(); i++) {
        PVector pv = (PVector) al.get(i);
        alNew.add(new PVector(pv.x, pv.y));
      }

      return alNew;
    }
    public void avoid(ArrayList obstacles) {

      // Make a vector that will be the position of the object
      // relative to the Boid rotated in the direction of boid's velocity
      PVector closestRotated = new PVector(sight + 1, sight + 1);
      float closestDistance = 99999;
      Obstacle avoid = null;

      // Let's look at each obstacle
      for (int i = 0; i < obstacles.size(); i++) {
        Obstacle o = (Obstacle) obstacles.get(i);

        float d = PVector.dist(loc, o.loc);
        PVector dir = vel.get();
        dir.normalize();
        PVector diff = PVector.sub(o.loc, loc);

        // Now we use the dot product to rotate the vector that points from boid to obstacle
        // Velocity is the new x-axis
        PVector rotated = new PVector(diff.dot(dir), diff.dot(getNormal(dir)));

        // Is the obstacle in our path?
        if (PApplet.abs(rotated.y) < (o.radius + r)) {
          // Is it the closest obstacle?
          if ((rotated.x > 0) && (rotated.x < closestRotated.x)) {
            closestRotated = rotated;
            avoid = o;
          }
        }
      }

      // Can we actually see the closest one?
      if (PApplet.abs(closestRotated.x) < sight) {

        // The desired vector should point away from the obstacle
        // The closer to the obstacle, the more it should steer
        PVector desired =
            new PVector(closestRotated.x, -closestRotated.y * sight / closestRotated.x);
        desired.normalize();
        desired.mult(closestDistance);
        desired.limit(maxspeed);
        // Rotate back to the regular coordinate system
        rotateVector(desired, vel.heading2D());

        // Draw some debugging stuff
        if (debug) {
          stroke(0);
          line(loc.x, loc.y, loc.x + desired.x * 10, loc.y + desired.y * 10);
          avoid.highlight(true);
        }

        // Apply Reynolds steering rules
        desired.sub(vel);
        desired.limit(maxforce);
        acc.add(desired);
      }
    }
  public void draw() {

    background(255);

    for (int i = 0; i < balls.size(); i++) {
      Ball ball = (Ball) balls.get(i);
      ball.calc();
      ball.display();
    }
  }
Example #13
0
 public void mouseClicked() {
   ArrayList objects = timeline.getStatefulObjects();
   for (int i = 0; i < objects.size(); i++) {
     CelestialObject obj = (CelestialObject) objects.get(i);
     if (obj.isMouseOver()) {
       println(obj.getName() + " clicked!");
       break;
     }
   }
 }
Example #14
0
  /** Update all of the Ball's and draw them */
  public void update() {

    if (balls.size() != 0) {

      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.update();
        b.attract = kelly;
        b.drawBall();
      }
    }
  }
Example #15
0
    public ArrayList getFutureObjectStates() {
      ArrayList alFutureArchive = new ArrayList();
      ArrayList alFutureObjects = cloneArrayList(alStatefulObjects);

      for (int i = 0; i < 100; i++) {
        sim.calculateForces(alFutureObjects);

        alFutureArchive.add(cloneArrayList(alFutureObjects));
      }

      return alFutureArchive;
    }
Example #16
0
  public static String[] getZipList(String zipFile) throws ZipException, IOException {
    File file = new File(zipFile);
    ZipFile zip = new ZipFile(file);
    Enumeration<? extends ZipEntry> zipFileEntries = zip.entries();
    ArrayList<String> files = new ArrayList<String>();

    // Process each entry
    while (zipFileEntries.hasMoreElements()) {
      // grab a zip file entry
      ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
      String currentEntry = entry.getName();
      files.add(currentEntry);
    }
    return files.toArray(new String[files.size()]);
  }
Example #17
0
  public void draw() {
    background(0);
    fill(255);

    if (!paused) timeline.moveForward();

    if (dragging) drawOrbits(timeline.getFutureObjectStates());
    else drawOrbits(timeline.getPastObjectStates());

    ArrayList objects = timeline.getStatefulObjects();
    for (int i = 0; i < objects.size(); i++) {
      CelestialObject obj = (CelestialObject) objects.get(i);
      obj.display();
    }
  }
  public void draw() {
    // background(255);
    fill(255);
    rect(-4, -4, width + 4, height + 4);

    for (int i = skaters.size() - 1; i >= 0; i--) {

      Skater skater = (Skater) skaters.get(i);

      // if (mousePressed) {
      skater.trace(mouseX, mouseY); // blob[i].x etc.

      println(i);
    }
  }
Example #19
0
 private boolean startLauncher(File dir) {
   try {
     Runtime rt = Runtime.getRuntime();
     ArrayList<String> command = new ArrayList<String>();
     command.add("java");
     command.add("-jar");
     command.add("Launcher.jar");
     String[] cmdarray = command.toArray(new String[command.size()]);
     Process proc = rt.exec(cmdarray, null, dir);
     return true;
   } catch (Exception ex) {
     System.err.println("Unable to start the Launcher program.\n" + ex.getMessage());
     return false;
   }
 }
 private void safeAddHyperlinkControl(String id) {
   if (myParagraphStarted) {
     addHyperlinkControl(FBTextKind.INTERNAL_HYPERLINK, id);
   } else {
     myDelayedHyperlinks.add(id);
   }
 }
Example #21
0
  private static void startCDC() throws IOException, Exception {
    long remainder = 7;
    for (int i = startBoundary; i <= endBoundary; i += increment) {
      long minBoundary = min_multiplier * i; // we will set the mod value as the minimum boundary
      long maxBoundary = max_multiplier * i; // we will set this as the maximum boundary
      long divisor1 = i; // this will be used to mod the results
      long divisor2 = i / 2 + 1; // the backup divisor is half the original divisor
      long divisor3 = i / 4 + 1;
      totalSize =
          fileArray.get(1)
              .length; // note we only care about the size of the second file since that's the file
                       // we are measuring
      System.out.print(divisor1 + " " + divisor2 + " " + divisor3 + " ");
      runBytes(
          window,
          divisor1,
          divisor2,
          divisor3,
          remainder,
          minBoundary,
          maxBoundary); // run the karb rabin algorithm
      // this is the block size per boundary
      double blockSize = (double) totalSize / (double) numOfPieces;
      double ratio = (double) coverage / (double) totalSize;
      System.out.println(blockSize + " " + ratio);

      // clear the hashTable, and counters so we can reset the values for the next round of
      // boundaries
      coverage = 0;
      numOfPieces = 0;
      table.clear();
      HashClass.duplicate_counter = 0;
      HashClass.max_list_length = 0;
    }
  }
 private void safeAddControl(byte kind, boolean start) {
   if (myParagraphStarted) {
     addControl((Byte) kind, (Boolean) start);
   } else {
     myDelayedControls.add(new Pair(kind, start));
   }
 }
Example #23
0
  /** If a key is pressed perform the respective actions */
  public void keyPressed() {

    // Add 'stems' to the balls
    if (keyCode == SHIFT) {
      stems = !stems;
      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.STEM = stems;
      }
    }
    // toggle repaint background
    else if (key == 'b') REPAINT = !REPAINT;
    // Empty the ArrayList of Balls
    else if (key == 'x') balls.clear();
    // Add a ball
    else if (key == 'f') addBall();
  }
  private void processTextRecord(int size, ArrayList /*<Integer>*/ pars) {
    int start = 0;
    int end = 0;

    for (Iterator it = pars.iterator(); it.hasNext(); ) {
      start = end;
      end = start + (Integer) it.next();
      if (end > size) {
        return;
      }
      myParagraphStored = false;
      processTextParagraph(myCharBuffer, start, end);
      if (!myParagraphStored) {
        myParagraphVector.add(new Pair(-1, -1));
      }
    }
  }
Example #25
0
    public int moveForward() {
      //    println("forward!");
      intTimeIdx++;

      // if the future values have already been calculated, just fetch them instead of calculating
      // them again
      if (alObjectStateArchive.size() > intTimeIdx)
        setCurrentState(cloneArrayList((ArrayList) alObjectStateArchive.get(intTimeIdx)));
      else {
        //      println("calculating...");
        sim.calculateForces(alStatefulObjects);
        alObjectStateArchive.add(cloneArrayList(alStatefulObjects));
      }

      sliderTimeline.setValue(intTimeIdx);

      return intTimeIdx;
    }
  public void setup() {
    size(800, 600);
    smooth();

    strokeWeight(1);

    skaters = new ArrayList();

    skaters.add(new Skater());
  }
    public void draw() {
      if (_pointLists.size() <= 0) return;

      pushStyle();
      noFill();

      PVector vec;
      PVector firstVec;
      PVector screenPos = new PVector();
      int colorIndex = 0;

      // draw the hand lists
      Iterator<Map.Entry> itrList = _pointLists.entrySet().iterator();
      while (itrList.hasNext()) {
        strokeWeight(2);
        stroke(_colorList[colorIndex % (_colorList.length - 1)]);

        ArrayList curList = (ArrayList) itrList.next().getValue();

        // draw line
        firstVec = null;
        Iterator<PVector> itr = curList.iterator();
        beginShape();
        while (itr.hasNext()) {
          vec = itr.next();
          if (firstVec == null) firstVec = vec;
          // calc the screen pos
          context.convertRealWorldToProjective(vec, screenPos);
          vertex(screenPos.x, screenPos.y);
        }
        endShape();

        // draw current pos of the hand
        if (firstVec != null) {
          strokeWeight(8);
          context.convertRealWorldToProjective(firstVec, screenPos);
          point(screenPos.x, screenPos.y);
        }
        colorIndex++;
      }

      popStyle();
    }
Example #28
0
 static public ArrayList<File> findFilesInFolder(File folder, String extension,
                                                 boolean recurse) {
   ArrayList<File> files = new ArrayList<File>();
   
   if (folder.listFiles() == null) return files;
   
   for (File file : folder.listFiles()) {
     if (file.getName().startsWith(".")) continue; // skip hidden files
     
     if (file.getName().endsWith("." + extension))
       files.add(file);
       
     if (recurse && file.isDirectory()) {
       files.addAll(findFilesInFolder(file, extension, true));
     }
   }
   
   return files;
 }
Example #29
0
  public void mouseDragged() {
    if (paused) {
      ArrayList objects = timeline.getStatefulObjects();
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        if (obj.isMouseOver()) {
          dragging = true;
          PVector pos = obj.getPosition();
          pos.x = mouseX;
          pos.y = mouseY;

          timeline.reset();
          timeline.setCurrentState(objects);
          sliderTimeline.setValue(0);
          break;
        }
      }
    }
  }
Example #30
0
    public void calculateForces(ArrayList objects) {
      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj = (CelestialObject) objects.get(i);
        ArrayList forces = obj.getForces();
        float totalForceX = 0;
        float totalForceY = 0;

        for (int j = 0; j < forces.size(); j++) {
          totalForceX += ((PVector) forces.get(j)).x;
          totalForceY += ((PVector) forces.get(j)).y;
        }

        PVector newAccel = new PVector(totalForceX / obj.getMass(), totalForceY / obj.getMass());

        obj.setAcceleration(newAccel);
      }

      for (int i = 0; i < objects.size(); i++) {
        CelestialObject obj1 = (CelestialObject) objects.get(i);
        float forceX = 0;
        float forceY = 0;
        obj1.clearForces();

        if (obj1.getClass() == Star.class) {
          println(obj1.getVelocity());
          continue;
        }

        for (int j = 0; j < objects.size(); j++) {
          CelestialObject obj2 = (CelestialObject) objects.get(j);

          if (i == j) continue;

          PVector pvDistance = PVector.sub(obj2.getPosition(), obj1.getPosition());
          //    println("distance: x:" + pvDistance.x + " y:" + pvDistance.y);
          float distance = sqrt(sq(pvDistance.y) + sq(pvDistance.x));
          float angle = degrees(atan2(pvDistance.y, pvDistance.x));

          float force = (G * obj1.getMass() * obj2.getMass()) / sq(distance);
          forceX = force * cos(radians(angle));
          forceY = force * sin(radians(angle));
          //        println("FORCES on " + obj1.getName() + ":" + forceX + "," + forceY);
          obj1.addForce(new PVector(forceX, forceY));

          println();
        }
      }
    }