public static void main(String[] args) throws IOException {
    Path baseDir = null;
    String localPath = null;
    String preservePath = null;
    String sIgnoreTablesFilename = null;
    String sNoPreserveFilename = null;
    String sDateString = null;
    long size = 0;

    // UNIX dates for right now
    long now = new java.util.Date().getTime() / 1000;
    long maxDate = now;

    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("--hdfs-path")) {
        baseDir = new Path(args[++i]);
        continue;
      }
      if (args[i].equals("--local-path")) {
        localPath = args[++i];
        continue;
      }
      if (args[i].equals("--preserve-path")) {
        preservePath = args[++i];
        continue;
      }
      if (args[i].equals("--no-preserve")) {
        sNoPreserveFilename = args[++i];
        continue;
      }
      if (args[i].equals("--ignore-tables")) {
        sIgnoreTablesFilename = args[++i];
        continue;
      }
      if (args[i].equals("--sleep")) {
        try {
          m_nSleepSeconds = Integer.parseInt(args[++i]);
        } catch (Exception e) {
          System.err.println("ERROR: " + e.toString() + "\n");
          usage();
        }
        continue;
      }
      if (args[i].equals("--dry-run")) {
        m_bDryRun = true;
        continue;
      }
      if (args[i].equals("--date")) {
        sDateString = args[++i];
        continue;
      }
      if (args[i].equals("--max-date")) {
        maxDate = Long.parseLong(args[++i]);
        continue;
      }
      if (args[i].equals("--max-bytes")) {
        size = Long.parseLong(args[++i]);
        continue;
      }

      System.err.println("ERROR: unknown arg " + args[i]);
      usage();
    }

    if (baseDir == null || localPath == null || preservePath == null || sDateString == null) {
      usage();
    }

    long minDate;

    if ("yesterday".equals(sDateString)) {
      // figure out yesterday's dates
      Calendar cal = Calendar.getInstance();
      cal.roll(Calendar.DAY_OF_YEAR, -1);

      // yesterday midnight
      cal.set(Calendar.HOUR_OF_DAY, 0);
      cal.set(Calendar.MINUTE, 0);
      cal.set(Calendar.SECOND, 0);
      cal.set(Calendar.MILLISECOND, 0);

      minDate = cal.getTimeInMillis() / 1000;

      // yesterday end of day
      cal.set(Calendar.HOUR_OF_DAY, 23);
      cal.set(Calendar.MINUTE, 59);
      cal.set(Calendar.SECOND, 59);
      cal.set(Calendar.MILLISECOND, 999);

      maxDate = cal.getTimeInMillis() / 1000;
    } else if ("last-week".equals(sDateString)) {
      minDate = maxDate - (7 * 24 * 60 * 60);
    } else if ("last-day".equals(sDateString)) {
      minDate = maxDate - (24 * 60 * 60);
    } else {
      // UNIX date since epoch of last backup
      minDate = Long.parseLong(sDateString);
    }

    long tmpDate = 0;
    BackupHdfs bak = new BackupHdfs();

    // initialize the list of tables to ignore
    if (sIgnoreTablesFilename != null) {
      bak.initializeTablesToIgnore(sIgnoreTablesFilename);
    }

    // initialize list of files to not preserve
    if (sNoPreserveFilename != null) {
      bak.initializeNoPreserve(sNoPreserveFilename);
    }

    ArrayList<Path> pathList = new ArrayList<Path>(2000);
    HashMap<Path, Long> hmTimestamps = new HashMap<Path, Long>();

    Configuration conf = new Configuration();
    FileSystem fs = FileSystem.get(conf);

    // If the HDFS path is a dir continue
    if (fs.getFileStatus(baseDir).isDir()) {
      Calendar cal = Calendar.getInstance();

      System.err.println("");
      cal.setTimeInMillis(minDate * 1000);
      System.err.println("min date = " + cal.getTime().toString());

      cal.setTimeInMillis(maxDate * 1000);
      System.err.println("max date = " + cal.getTime().toString());

      System.err.println("");
      System.err.println("Searching filesystem: " + baseDir.toUri().getPath());

      bak.checkDir(fs, minDate, maxDate, baseDir, pathList, hmTimestamps);

      System.err.println("");
      System.err.println("Skipped " + m_nIgnoredTables + " files due to ignored tables");

      System.err.println("");
      System.err.println("Number of files to backup = " + pathList.size());

      System.err.println("Total bytes to backup = " + prettyPrintBytes(m_nTotalBytes));

      System.err.println("");
      System.err.println("sorting list of files...");
      Collections.sort(pathList, new DateComparator(hmTimestamps));
      System.err.println("done");

      System.err.println("");
      System.err.println("starting backup...");
      tmpDate = bak.backupFiles(localPath, preservePath, fs, pathList, size);

      bak.closeFiles();

      System.err.println("");
      System.err.println("backup completed...");
    }

    if (tmpDate == 0) {
      // If not size limit reached print out date for right now
      System.out.println(maxDate);
    } else {
      // Print out date for last file backed up
      System.err.println("Size limit reached.");
      System.out.println(tmpDate);
    }

    System.exit(0);
  }
  public void draw() {
    background(255);

    // Turn off highlighting for all obstalces
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.highlight(false);
    }

    // Act on all boids
    for (int i = 0; i < boids.size(); i++) {
      Boid b = (Boid) boids.get(i);
      b.avoid(obstacles);
      b.run();
    }

    // Display the obstacles
    for (int i = 0; i < obstacles.size(); i++) {
      Obstacle o = (Obstacle) obstacles.get(i);
      o.display();
    }

    // Instructions
    textFont(f);
    fill(0);
    text(
        "Hit space bar to toggle debugging lines.\nClick the mouse to generate a new boids.",
        10,
        height - 30);
  }
Example #3
0
 public void drawOrbits(ArrayList alObjectsArchive) {
   //  println("SIZE:" + alObjectsArchive.size());
   //  ArrayList alObjectsArchive = timeline.getObjectStateArchive();
   ArrayList alPrevPos = new ArrayList();
   ArrayList alColors = new ArrayList();
   alColors.add(color(255, 0, 0));
   alColors.add(color(255, 255, 0));
   alColors.add(color(255, 0, 255));
   //  for (int i = timeline.getTimeIdx(); i >= 0 && i > (timeline.getTimeIdx() - 1 - 100); i--)
   for (int i = 0; i < alObjectsArchive.size(); i++) {
     ArrayList objects = (ArrayList) alObjectsArchive.get(i);
     for (int j = 0; j < objects.size(); j++) {
       CelestialObject obj = (CelestialObject) objects.get(j);
       //      CelestialObject obj = (CelestialObject)objects.get(1);
       PVector pos = obj.getPosition();
       //      stroke(0, 0, 255);
       stroke((Integer) alColors.get(j));
       if (alPrevPos.size() == objects.size()) {
         PVector prevPos = (PVector) alPrevPos.get(j);
         line(prevPos.x, prevPos.y, pos.x, pos.y);
         alPrevPos.set(j, pos);
       } else alPrevPos.add(pos);
     }
   }
 }
Example #4
0
  /**
   * Parse a method declaration. The declaration should be in the following format:
   *
   * <p>fully-qualified-method-name (args)
   *
   * <p>where the arguments are comma separated and all arguments other than primitives should have
   * fully qualified names. Arrays are indicating by trailing brackets. For example:
   *
   * <p>int int[] int[][] java.lang.String java.util.Date[]
   *
   * <p>The arguments are translated into BCEL types and a MethodDef is returned.
   */
  private MethodDef parse_method(StrTok st) {

    // Get the method name
    String method_name = st.need_word();

    // Get the opening paren
    st.need("(");

    // Read the arguments
    ArrayList<String> args = new ArrayList<String>();
    String tok = st.nextToken();
    if (tok != ")") {
      st.pushBack();
      do {
        tok = st.need_word();
        args.add(tok);
      } while (st.nextToken() == ",");
      st.pushBack();
      st.need(")");
    }

    // Convert the arguments to Type
    Type[] targs = new Type[args.size()];
    for (int ii = 0; ii < args.size(); ii++) {
      targs[ii] = BCELUtil.classname_to_type(args.get(ii));
    }

    return new MethodDef(method_name, targs);
  }
Example #5
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;
    }
    public void valueChanged(ListSelectionEvent evt) {
      if (!evt.getValueIsAdjusting()) {
        JFileChooser chooser = getFileChooser();
        FileSystemView fsv = chooser.getFileSystemView();
        JList list = (JList) evt.getSource();

        int fsm = chooser.getFileSelectionMode();
        boolean useSetDirectory = usesSingleFilePane && (fsm == JFileChooser.FILES_ONLY);

        if (chooser.isMultiSelectionEnabled()) {
          File[] files = null;
          Object[] objects = list.getSelectedValues();
          if (objects != null) {
            if (objects.length == 1
                && ((File) objects[0]).isDirectory()
                && chooser.isTraversable(((File) objects[0]))
                && (useSetDirectory || !fsv.isFileSystem(((File) objects[0])))) {
              setDirectorySelected(true);
              setDirectory(((File) objects[0]));
            } else {
              ArrayList<File> fList = new ArrayList<File>(objects.length);
              for (Object object : objects) {
                File f = (File) object;
                boolean isDir = f.isDirectory();
                if ((chooser.isFileSelectionEnabled() && !isDir)
                    || (chooser.isDirectorySelectionEnabled() && fsv.isFileSystem(f) && isDir)) {
                  fList.add(f);
                }
              }
              if (fList.size() > 0) {
                files = fList.toArray(new File[fList.size()]);
              }
              setDirectorySelected(false);
            }
          }
          chooser.setSelectedFiles(files);
        } else {
          File file = (File) list.getSelectedValue();
          if (file != null
              && file.isDirectory()
              && chooser.isTraversable(file)
              && (useSetDirectory || !fsv.isFileSystem(file))) {

            setDirectorySelected(true);
            setDirectory(file);
            if (usesSingleFilePane) {
              chooser.setSelectedFile(null);
            }
          } else {
            setDirectorySelected(false);
            if (file != null) {
              chooser.setSelectedFile(file);
            }
          }
        }
      }
    }
Example #7
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;
    }
Example #8
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();
      }
    }
  }
  public static void main(String[] args) {
    try {
      BufferedReader br = new BufferedReader(new FileReader(args[0]));
      int tIndex = 0;
      int pIndex = 0;

      // This will probably change soon (name and implementation)
      NgramParser tnp = new NgramParser(args[1]);

      ArrayList<String> triplet = tnp.getTriplet();
      ArrayList<String> polarity = tnp.getPolarity();

      FileWriter sw = new FileWriter(args[2]);
      String line = null;

      while (((line = br.readLine()) != null)
          && (tIndex < triplet.size())
          && (pIndex < polarity.size())) {
        if (line.matches("^[\\d]*:")) {
          // System.out.println(line);
          sw.write(line + "\n");
        } else {
          Scanner sc = new Scanner(line);
          String trip = sc.findInLine(Pattern.compile("[a-zA-Z]+#[a-z]+[#]?[0-9]*"));
          // if (trip != null && trip.equals(triplet.get(tIndex))) {
          System.out.println(trip);
          if (trip != null && !trip.toLowerCase().contains("no#cl")) {
            // System.out.println(triplet.get(tIndex) + ":" +polarity.get(pIndex));
            String pol = polarity.get(pIndex);
            sw.write(line + " " + pol + "\n");
            sc.close();
            tIndex++;
            pIndex++;
          } else {
            String pol = "neg";
            sw.write("no#a#1" + " " + pol + "\n");
            sc.close();
          }
        }

        // sw.flush();
      }

      sw.close();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #10
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();
        }
      }
    }
    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++;
    }
  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));
  }
  public static void main(String[] args) {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

    try {

      Scanner sc = new Scanner(new File("/home/santosh/Desktop/testData"));

      int testCases = sc.nextInt();
      int i = 0;
      ArrayList<ArrayList<Integer>> inputArraysList = new ArrayList<ArrayList<Integer>>();
      ArrayList<Integer> list;
      while (i++ < testCases) {

        int n = sc.nextInt();
        int k = 0;
        list = new ArrayList<Integer>();
        while (k < n) {
          list.add(sc.nextInt());
          k++;
        }
        inputArraysList.add(list);
      }

      // System.out.println(inputArraysList.size());
      for (ArrayList<Integer> arr : inputArraysList) {
        countPairs(arr.toArray(new Integer[arr.size()]));
      }

    } catch (Exception e) {

    }
  }
Example #14
0
 /**
  * Returns all editors.
  *
  * @return editors
  */
 EditorArea[] editors() {
   final ArrayList<EditorArea> edits = new ArrayList<EditorArea>();
   for (final Component c : tabs.getComponents()) {
     if (c instanceof EditorArea) edits.add((EditorArea) c);
   }
   return edits.toArray(new EditorArea[edits.size()]);
 }
    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);
      }
    }
Example #16
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 #17
0
 public String toString() {
   StringBuilder sb = new StringBuilder();
   for (int i = 0; i < urls.size(); i++) {
     if (i > 0) {
       sb.append("|");
     }
     sb.append(
         String.format("%d,%d=\"%s\"", locations.get(i)[0], locations.get(i)[1], urls.get(i)));
   }
   return sb.toString();
 }
  public JilterStatus eoh() {
    logger.debug("jilter eoh()");
    // includeBCC is false if RCPT TO does not contain at least one field in TO, FROM and CC
    // this is a safety check as sometimes, RCPT TO is something differently entirely
    // and does not contain the actual recipients in the email

    MilterServerService milterService = Config.getConfig().getMilterServerService();

    if (milterService.getIncludeBCC() && includeBCC) {
      logger.debug("including BCC addresses");
      // check to see if address is flagged to ignore
      if (rcpts.size() > 0) {
        Iterator<String> i = rcpts.iterator();
        while (i.hasNext()) {
          String rcpt = i.next();
          if (shouldIgnoreBCCAddress(rcpt)) {
            logger.debug("ignore include bcc address {address='" + rcpt + "'}");
            i.remove();
          }
        }
      }

      if (rcpts.size() > 0) {
        try {
          for (int j = 0; j < rcpts.size(); j++) {
            if (j == 0) {
              bos.write("bcc: ".getBytes());
            } else {
              bos.write(",".getBytes());
            }
            bos.write(rcpts.get(j).getBytes());
          }
          bos.write("\n".getBytes());
        } catch (IOException io) {
          logger.error("jilter failed to write end of header data", io);
        }
      }
    }
    return JilterStatus.SMFIS_CONTINUE;
  }
Example #19
0
  private ArrayList GetFolderTree(String s_Dir, String s_Flag, int n_Indent, int n_TreeIndex) {
    String s_List = "";
    ArrayList aSubFolders = new ArrayList();

    File file = new File(s_Dir);
    File[] filelist = file.listFiles();

    if (filelist != null && filelist.length > 0) {
      for (int i = 0; i < filelist.length; i++) {
        if (filelist[i].isDirectory()) {
          aSubFolders.add(filelist[i].getName());
        }
      }

      int n_Count = aSubFolders.size();
      String s_LastFlag = "";
      String s_Folder = "";
      for (int i = 1; i <= n_Count; i++) {
        if (i < n_Count) {
          s_LastFlag = "0";
        } else {
          s_LastFlag = "1";
        }

        s_Folder = aSubFolders.get(i - 1).toString();
        s_List =
            s_List
                + "arr"
                + s_Flag
                + "["
                + String.valueOf(n_TreeIndex)
                + "]=new Array(\""
                + s_Folder
                + "\","
                + String.valueOf(n_Indent)
                + ", "
                + s_LastFlag
                + ");\n";
        n_TreeIndex = n_TreeIndex + 1;
        ArrayList a_Temp =
            GetFolderTree(s_Dir + s_Folder + sFileSeparator, s_Flag, n_Indent + 1, n_TreeIndex);
        s_List = s_List + a_Temp.get(0).toString();
        n_TreeIndex = Integer.valueOf(a_Temp.get(1).toString()).intValue();
      }
    }

    ArrayList a_Return = new ArrayList();
    a_Return.add(s_List);
    a_Return.add(String.valueOf(n_TreeIndex));
    return a_Return;
  }
Example #20
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 #22
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();
  }
Example #23
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;
    }
Example #24
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;
        }
      }
    }
  }
 /**
  * Gets the instances of <CODE>Template</CODE> that have an ID that is already in the database.
  *
  * @return An <CODE>ArrayList</CODE> containing the instances of <CODE>Template</CODE> already in
  *     the database.
  * @throws java.sql.SQLException Thrown on sql exception.
  */
 public ArrayList findTemplatesInDatabase() throws java.sql.SQLException {
   ArrayList templatesInDatabase = new ArrayList();
   Connection oracleConnection = getDataSource().getConnection();
   try {
     Statement query = oracleConnection.createStatement();
     try {
       StringBuffer sql = new StringBuffer("SELECT TMPL_ID FROM ");
       sql.append(MPSBrowserView.SCHEMA);
       sql.append(".TEMPLATE WHERE TMPL_ID IN (");
       ArrayList templates = getTemplates();
       int templateCount = templates.size();
       for (int i = 0; i < templateCount; i++) {
         if (i > 0) sql.append(", ");
         sql.append("'");
         sql.append(((Template) templates.get(i)).getID());
         sql.append("'");
       }
       sql.append(")");
       ResultSet result = query.executeQuery(sql.toString());
       try {
         while (result.next()) {
           String templateID = result.getString("TMPL_ID");
           for (int i = 0; i < templateCount; i++) {
             Template currentTemplate = (Template) templates.get(i);
             if (templateID.equals(currentTemplate.getID())) {
               templatesInDatabase.add(currentTemplate);
               currentTemplate.setInDatabase(true);
             }
           }
         }
       } finally {
         result.close();
       }
     } finally {
       query.close();
     }
   } finally {
     oracleConnection.close();
   }
   return templatesInDatabase;
 }
Example #26
0
 public void setCurrentState(ArrayList alState) {
   for (int i = 0; i < alStatefulObjects.size(); i++) {
     alStatefulObjects.set(i, alState.get(i));
   }
 }
    public void addPoint(long handId, PVector handPoint) {
      ArrayList curList = getPointList(handId);

      curList.add(0, handPoint);
      if (curList.size() > _maxPoints) curList.remove(curList.size() - 1);
    }
  public CreateCplusplusHeader(GNode n) {

    classTree = n;

    /*Debug**/
    // p1.println(classTree.size());
    final PrintWriter p1;
    final GNode[] containsRelevantClasses;
    final ArrayList<String> stringClasses = new ArrayList<String>();
    final ArrayList<Integer> countClasses = new ArrayList<Integer>();
    final ArrayList<Integer> countChildren = new ArrayList<Integer>();
    final GNode stac = GNode.create("Holder");

    File headerFile;

    File newDirectory;

    try {

      newDirectory = new File("cplusplusfiles");
      newDirectory.mkdir();
      headerFile = new File("cplusplusfiles", "Header.h");
      headerFile.createNewFile();
      p1 = new PrintWriter(headerFile);

      /*Remove comments below to Debug**/
      // p1.println(classTree.size());
      // p1.println(containsRelevantClasses.size());
      // p1.println(countClasses);
      //  p1.println(countChildren);

      p1.println("// Ankit Goel's Header");
      p1.println("#pragma once");
      p1.println();
      p1.println("#include <stdint.h>");
      p1.println("#include <string>");
      p1.println();
      p1.println("using namespace java::lang;");
      p1.println("// Foward Declarations ");
      p1.println();

      /* Remove comments below to Debug**/
      //  String s = classTree.getNode(1).getNode(0).getNode(0).getName();
      //  p1.println(s);
      //  p1.flush();
      //  p1.close();

      new Visitor() {
        int counter22 = 0;

        public void visitClass(GNode n) {
          counter22++;

          countChildren.add(n.size());
          countClasses.add(counter22);

          visit(n);
        }

        public void visitClassHeaderDeclaration(GNode n) {

          stac.add(n);

          /*Remove comments below to Debug**/
          // p1.println(n.getNode(0).getName());
          // containsRelevantClasses[counter22] = (GNode) n;

        }

        public void visit(Node n) {
          for (Object o : n) if (o instanceof Node) dispatch((Node) o);
        }
      }.dispatch(classTree);

      /*Remove comments below to Debug**/
      // p1.println(stac.size());

      String globalVariableArrayCheck;
      for (int b = 4; b < stac.size(); b++) {

        createCplusplusHeader = (GNode) stac.getNode(b);
        GNode vMethods = (GNode) createCplusplusHeader.getNode(0);
        // p1.println(createCplusplusHeader.getName());
        /*Remove comments below to Debug**/
        // p1.println(vMethods.getName());
        // We need a mapping of methodName to accessibility

        final HashMap<String, String> mNAccess = new HashMap<String, String>();

        /*Remove comments below to Debug**/
        // We need a mapping to methodName to whetherItsStatic
        // p1.println(mNAccess);
        // p1.println(mNAccess.get("goel"));

        final GNode constructorPrinter = GNode.create("ConstructorPrinter");

        final ArrayList<Integer> getCounter = new ArrayList<Integer>();

        new Visitor() {
          int counter2 = 0;

          public void visitVirtualMethodDeclaration(GNode n) {
            counter2++;
            getCounter.add(counter2);
          }

          public void visit(Node n) {
            for (Object o : n) if (o instanceof Node) dispatch((Node) o);
          }
        }.dispatch(vMethods);

        int startHere = getCounter.get(getCounter.size() - 1) + 1;

        /*Remove comments below to Debug**/
        // p1.println(startHere);

        final String className = vMethods.getNode(startHere).getNode(4).getNode(0).getString(0);

        final String plainClassName = className.substring(2, className.length());

        final GNode ARRAYTRACKER = GNode.create("ArrayTracker");

        // Need another dispatch for constructor heeader node
        new Visitor() {
          public void visitConstructorHeader(GNode n) {

            // Add each node
            if (n.getString(0).equals(plainClassName)) constructorPrinter.add(n);
          }

          public void visitCustomArrayDeclaration(GNode n) {
            ARRAYTRACKER.add(n);
          }

          public void visit(Node n) {
            for (Object o : n) if (o instanceof Node) dispatch((Node) o);
          }
        }.dispatch(createCplusplusHeader);
        // p1.println(constructorPrinter.size());
        // Find out when the virtual method declarations ends

        /*Remove comments below to Debug**/
        // p1.println(getCounter);

        p1.println("struct __" + plainClassName + ";");
        p1.println();
        p1.println("struct __" + plainClassName + "_VT;");
        p1.println();
        p1.println("typedef __rt::Ptr<" + "__" + plainClassName + "> " + plainClassName + ";");
        p1.println();
        p1.println("struct __" + plainClassName + " { ");
        p1.println();
        p1.println("    // The data layout for java.lang.plainClassName");
        p1.println("      " + "__" + plainClassName + "_VT* __vptr;");

        // Get the Field Decl in this

        final GNode fields = GNode.create("Fields");
        new Visitor() {
          public void visitDataLayoutDeclaration(GNode n) {
            visit(n);
          }

          public void visitDataFieldList(GNode n) {

            fields.add(n);
          }

          public void visit(Node n) {
            for (Object o : n) if (o instanceof Node) dispatch((Node) o);
          }
        }.dispatch(createCplusplusHeader);
        // p1.println(fields.size());

        final ArrayList<String> privateOrpublic = new ArrayList<String>();
        final ArrayList<String> PrimitiveType = new ArrayList<String>();
        final ArrayList<String> Decl = new ArrayList<String>();

        new Visitor() {
          public void visitDataFieldList(GNode n) {
            visit(n);
          }

          public void visitFieldDeclaration(GNode n) {

            // if (n.getNode(0).size() > 0 )
            // privateOrpublic.add(n.getNode(0).getNode(0).getString(0));
            /*
            if (n.getNode(0).getNode(0).getString(0).equals("static") && n.getNode(1).getNode(0).getString(0).equals("int") )
                PrimitiveType.add("static const int32_t ");
            **/
            if (n.getNode(1).getNode(0).getString(0).equals("int")
                && n.toString().contains("static")) PrimitiveType.add(" static int32_t");
            else PrimitiveType.add(n.getNode(1).getNode(0).getString(0));

            Decl.add(n.getNode(2).getNode(0).getString(0));

            /*
            else
                Decl.add(n.getNode(2).getNode(0).getString(0) + "  = " +  n.getNode(2).getNode(0).getNode(2).getString(0));
             **/
          }

          public void visit(Node n) {
            for (Object o : n) if (o instanceof Node) dispatch((Node) o);
          }
        }.dispatch(fields);

        // Print out the Data Fields
        for (int c = 0; c < Decl.size(); c++) {

          p1.println();
          p1.println("     " + PrimitiveType.get(c) + " " + Decl.get(c) + ";");
        }

        List<String> typeOfParameter = new ArrayList<String>();
        List<String> DECLARATOR = new ArrayList<String>();

        // p1.println(constructorPrinter);

        for (int ccd = 0; ccd < constructorPrinter.size(); ccd++) {

          // There is more than one parameter
          if (constructorPrinter.getNode(ccd).getNode(1).size() >= 1) {

            GNode GETPARAMS = GNode.create("GETPARAMS");

            GETPARAMS.add(constructorPrinter.getNode(ccd).getNode(1));
            // p1.println(GETPARAMS);
            // Now Go through the Formal Parameters

            for (int dcc = 0; dcc < GETPARAMS.size(); dcc++) {

              typeOfParameter.add(
                  GETPARAMS.getNode(0).getNode(dcc).getNode(1).getNode(0).getString(0));

              DECLARATOR.add(GETPARAMS.getNode(0).getNode(dcc).getString(3));
            }
          } else {

            p1.println();

            p1.println("      " + className + "();");
          }
        }

        if (DECLARATOR.size() >= 1 && typeOfParameter.size() >= 1) {
          p1.print(className + "( ");
          for (int goela = 0; goela < typeOfParameter.size(); goela++) {

            if (goela != typeOfParameter.size() - 1)
              p1.print(typeOfParameter.get(goela) + "   " + DECLARATOR.get(goela) + ",");
            else p1.print(typeOfParameter.get(goela) + "   " + DECLARATOR.get(goela) + ");");
          }
        }

        p1.println();

        if ((constructorPrinter.size() == 0)) {
          p1.println();
          p1.println("     " + "// The Constructor");
          p1.println();
          p1.println("          " + "__" + plainClassName + "(); ");
        }

        // Find Instance Methods of the class Basically go through vtMethodPointersList and
        //  go through its children and check if the qualified identifier is the same as the clas
        // name

        // Store the names in a Arraylist type
        final List<String> names = new ArrayList<String>();

        List<String> types2 = new ArrayList<String>();

        final List<Integer> indexx = new ArrayList<Integer>();

        final HashMap<Integer, String> checkForOtherSuperClass = new HashMap<Integer, String>();

        // final HashMap<String,String> checkForPredefinedMethods = new HashMap<String,String>();
        // Basically You need to consider this fact there will be however so many Constructors and
        // you need to keep a tally to start it like that and
        // Ignore those indices

        final List<Integer> constuctorIndex = new ArrayList<Integer>();
        final GNode constructors = GNode.create("CONSTRUCTOR");
        final String constructorNameGetter = plainClassName;
        //  p1.println(constructors.size());
        // p1.println(constructorNameGetter);
        // Lets find out which methods are unique

        new Visitor() {
          public int counter = 0;

          public void visitVTConstructorDeclaration(GNode n) {
            visit(n);
          }

          public void visitvtMethodPointersList(GNode n) {

            visit(n);
          }

          public void visitvtMethodPointer(GNode n) {

            counter++;

            if (!(n.getNode(1).getString(1).equals("__Object"))
                && !(n.getString(0).equals("main_String"))) {

              //  constructorIndex.add(counter);

              //  p1.println(n.getString(0));

              indexx.add(counter);
              names.add(n.getString(0));
              // There needs to be a check for the other than __Object && __SuperClass
              checkForOtherSuperClass.put(counter, n.getNode(1).getString(1));

              //  checkForPredefinedMethods.put(n.getString(0), n.getNode(1).getString(1));

            } else {

              checkForOtherSuperClass.put(counter, n.getNode(1).getString(1));
              // constructors.add(n);
            }
          }

          public void visit(Node n) {
            for (Object o : n) if (o instanceof Node) dispatch((Node) o);
          }
        }.dispatch(vMethods);

        // p1.println(names);
        //  p1.println("Constructors" + constructors.size());
        //  p1.println(checkForOtherSuperClass);
        // System.out.println("ARRAY CONTENTS" + names);
        // Now lets get the type of the method and store it in Types arraylist

        // Visit the Method Declarations of the Java AST and store the types in order into an array.
        // Then
        // store the corresponding names of the methods in another array then do matching to
        // determine the
        // the types of the method
        // p1.println(checkForOtherSuperClass);

        for (int i = 0; i < indexx.size(); i++) {

          if (vMethods.getNode(indexx.get(i)).getGeneric(0) != null) {

            if (vMethods.getNode(indexx.get(i)).getNode(0).getName().equals("Type")) {

              // I think there only needs to be one check for a bool value the rest translate as is
              if (vMethods
                  .getNode(indexx.get(i))
                  .getNode(0)
                  .getNode(0)
                  .getString(0)
                  .equals("boolean")) types2.add("bool");
              else types2.add(vMethods.getNode(indexx.get(i)).getNode(0).getNode(0).getString(0));

            } else types2.add("void");

          } else {

            types2.add(" ");
          }
        }
        // p1.println(types2);
        // p1.println(names);
        // params are appended to the methods name
        List<String> specialnames = new ArrayList<String>();

        // A single method name which is a string could essential map to however many Strings
        Map<String, String> parameters = new HashMap<String, String>();

        // Remove anything after _ in the method these are the parameters that are appended to it
        for (int i = 0; i < names.size(); i++) {

          Pattern p = Pattern.compile("_");

          Matcher m = p.matcher(names.get(i));

          if (m.find()) {
            // p1.println("FOUND");

            // p1.println(m.start());

            // ****** Changed
            //  specialnames.add(names.get(i).substring(0,m.start()));

            specialnames.add(names.get(i));
            // Money.add(names.get(i));

            parameters.put(
                specialnames.get(i), names.get(i).substring(m.start(), names.get(i).length()));
          } else {

            specialnames.add(names.get(i));
            // The hashmap needs to be consistent
            parameters.put(names.get(i), "ZeroParams");
          }
        }
        // p1.println(names);
        // p1.println(parameters);
        // p1.println(types2);
        // p1.println(parameters);
        // Now print the instance methods using the types and names
        p1.println("    // The instance methods of java.lang.plainClassName");
        // p1.println(specialnames);

        // Constructor Initializeer
        p1.println("    static " + plainClassName + " init_Construct( " + plainClassName + "); ");

        for (int i = 0; i < types2.size(); i++) {

          if (parameters.get(specialnames.get(i)).equals("ZeroParams")
              && !(specialnames.get(i).equals(plainClassName)))
            p1.println(
                "    "
                    + "static "
                    + types2.get(i)
                    + " "
                    + specialnames.get(i)
                    + "( "
                    + plainClassName
                    + ")"
                    + ";");
          else {

            if (!(specialnames.get(i).equals(plainClassName))) {

              ArrayList<Integer> getTheParameters = new ArrayList<Integer>();

              p1.print(
                  "    "
                      + "static "
                      + types2.get(i)
                      + " "
                      + specialnames.get(i)
                      + "( "
                      + plainClassName
                      + " , ");

              Pattern pp = Pattern.compile("_");

              Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));

              while (mm.find()) {

                getTheParameters.add(mm.start());
              }

              for (int cc = 0; cc < getTheParameters.size(); cc++) {

                if (cc != getTheParameters.size() - 1) {

                  p1.print(
                      parameters
                              .get(specialnames.get(i))
                              .substring(getTheParameters.get(cc) + 1, getTheParameters.get(cc + 1))
                          + " , ");

                } else {
                  int length = parameters.get(specialnames.get(i)).length();
                  p1.print(
                      parameters
                              .get(specialnames.get(i))
                              .substring(getTheParameters.get(cc) + 1, length)
                          + ");");
                }
              }

              p1.println();
            }
          }
        }

        p1.println();
        p1.println(
            "    // The Function returning the class Object representing java.lang.plainClassName ");
        p1.println("    static Class __class(); ");
        p1.println("    static void init(  " + "__" + plainClassName + "*" + "  );");
        p1.println();

        // Changes for Command line arguements
        if (plainClassName.contains("Test")) {

          p1.println("    static void main(__rt::Ptr<__rt::Array<String> > args);");
        }
        p1.println("    static __" + plainClassName + "_" + "VT " + "__vtable;");
        p1.println();
        p1.println(" };");
        p1.println();

        // Now print the Constructor taking into account which ones are implemented by the given
        // class
        p1.println("struct __" + plainClassName + "_" + "VT" + "{");
        p1.println("    Class __isa;");

        // Introduce some logic to differentiate between new methods and predefined inherited method
        // from Object
        List<String> arr1 = new ArrayList<String>();
        arr1.add("hashcode");
        arr1.add("equals");
        arr1.add("getClass");
        arr1.add("toString");
        arr1.add("getName");
        arr1.add("getSuperClass");
        arr1.add("isInstance");

        // Basically iterate through map and add any methods that have a type not equal to the

        // You need to add the inherited types
        p1.println("    void (*__delete)(__" + plainClassName + "*);");
        p1.println("    int32_t (*hashCode)(" + plainClassName + ");");
        p1.println("    bool (*equals)(" + plainClassName + " , " + "Object);");
        p1.println("    Class (*getClass)(" + plainClassName + ");");
        p1.println("    String (*toString) (" + plainClassName + ");");

        for (int i = 0; i < names.size(); i++) {

          if (!(arr1.contains(names.get(i)))) {

            p1.println();

            ArrayList<Integer> getTheParameters = new ArrayList<Integer>();

            if (parameters.get(specialnames.get(i)).equals("ZeroParams")
                && !(specialnames.get(i).equals(plainClassName)))
              p1.println(
                  "    "
                      + types2.get(i)
                      + " (*"
                      + specialnames.get(i)
                      + ") ("
                      + plainClassName
                      + ");");
            else {

              if (!(specialnames.get(i).equals(plainClassName))) {

                Pattern pp = Pattern.compile("_");

                Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));

                while (mm.find()) {

                  getTheParameters.add(mm.start());
                }
                p1.print(
                    "    "
                        + types2.get(i)
                        + " (*"
                        + specialnames.get(i)
                        + ") ("
                        + plainClassName
                        + " , ");

                for (int cc = 0; cc < getTheParameters.size(); cc++) {

                  if (cc != getTheParameters.size() - 1) {

                    p1.print(
                        parameters
                                .get(specialnames.get(i))
                                .substring(
                                    getTheParameters.get(cc) + 1, getTheParameters.get(cc + 1))
                            + " , ");

                  } else {
                    int length = parameters.get(specialnames.get(i)).length();
                    p1.print(
                        parameters
                                .get(specialnames.get(i))
                                .substring(getTheParameters.get(cc) + 1, length)
                            + ");");
                  }
                }
              }

              // p1.println(getTheParameters);
            }
          }
        }

        p1.println();
        p1.println();
        // Now the constructor initilization inlined in the header
        p1.println("    __" + plainClassName + "_VT()");
        p1.println("    : __isa(__" + plainClassName + "::__class()),");

        List<String> getImplementation = new ArrayList<String>();

        int COUNT = 0;

        // Are there any instance methods
        for (int i = 0; i < specialnames.size(); i++) {
          if (!(specialnames.equals(plainClassName))) COUNT++;
        }
        // p1.println(COUNT);
        for (int i = 0; i < arr1.size(); i++) {

          if (names.contains(arr1.get(i))) {

            // Suppose a super class defines an Object method then this is wrong  so add an
            // additional check
            // if(checkForPredefinedMethods.get(arr1.get(i)).equals("__" + plainClassName))
            getImplementation.add(plainClassName);
            // else
            //  getImplementation.add(checkForPredefinedMethods.get(arr1.get(i)));

          } else {

            getImplementation.add("Object");
          }
        }
        // Remove comment to Debug
        // p1.println(getImplementation);

        p1.println("    __delete(&__rt::__delete<__" + plainClassName + ">),");

        // Hardcoded May Need to Change in the final Phase
        if (getImplementation.get(0).equals("Object"))
          p1.println(
              "      hashCode((int32_t(*)("
                  + plainClassName
                  + "))"
                  + "&__"
                  + getImplementation.get(0)
                  + "::hashCode),");
        else p1.println("      hashCode(&__" + plainClassName + "::hashCode),");

        if (getImplementation.get(1).equals("Object"))
          p1.println(
              "      equals((bool(*)("
                  + plainClassName
                  + " , Object)) &__"
                  + getImplementation.get(1)
                  + "::equals), ");
        else p1.println("      equals(&__" + plainClassName + "::equals");

        if (getImplementation.get(2).equals("Object"))
          p1.println(
              "      getClass((Class(*)("
                  + plainClassName
                  + ")) &__"
                  + getImplementation.get(2)
                  + "::getClass), ");
        else p1.println("      getClass(&__" + plainClassName + ")");

        // Remember to Take care of the comma issue
        if (getImplementation
            .get(3)
            .equals("Object") /*|| !(getImplementation.get(3).equals("__" + plainClassName))**/) {

          if (COUNT != 0)
            p1.println(
                "      toString((String(*)("
                    + plainClassName
                    + ")) &__"
                    + getImplementation.get(3)
                    + "::toString), ");
          else
            p1.println(
                "      toString((String(*)("
                    + plainClassName
                    + ")) &__"
                    + getImplementation.get(3)
                    + "::toString) { ");

        } else {
          int x = names.size();
          boolean bat = false;
          if ((x == 1) && (names.get(0).equals("toString"))) bat = true;
          if (COUNT != 0 && !(bat))
            p1.println("      toString(&__" + getImplementation.get(3) + "::toString),");
          else p1.println("      toString(&__" + getImplementation.get(3) + "::toString) {");
        }
        // p1.println(names);

        //

        for (int uniqueNames = 0; uniqueNames < names.size(); uniqueNames++) {

          // Remove Unnecessary Methods
          if (arr1.contains(names.get(uniqueNames))) {
            names.remove(uniqueNames);
            specialnames.remove(uniqueNames);
            types2.remove(uniqueNames);
          }
        }

        // p1.println(types2);
        // p1.println(names);
        // ADD Remaining Methods to implementation
        for (int i = 0; i < names.size(); i++) {

          if (!(arr1.contains(specialnames.get(i)))
              && checkForOtherSuperClass.get(i + 6).equals(className)
              && (i == names.size() - 1)
              && !(specialnames.get(i).equals(plainClassName))) {
            // Remember to Fix this later

            p1.println();
            p1.println(
                "      "
                    + specialnames.get(i)
                    + "(&__"
                    + plainClassName
                    + "::"
                    + specialnames.get(i)
                    + ") {");

          }

          // Finally Add Parameters Here
          else {
            if (parameters.get(specialnames.get(i)).equals("ZeroParams")
                && !(specialnames.get(i).equals(plainClassName))
                && !(arr1.contains(specialnames.get(i)))) {

              if (i != names.size() - 1)
                p1.println(
                    "      "
                        + specialnames.get(i)
                        + "(("
                        + types2.get(i)
                        + "(*)"
                        + "("
                        + plainClassName
                        + "))"
                        + "&"
                        + checkForOtherSuperClass.get(i + 6)
                        + "::"
                        + specialnames.get(i)
                        + "),");
              else
                p1.println(
                    "      "
                        + specialnames.get(i)
                        + "(("
                        + types2.get(i)
                        + "(*)"
                        + "("
                        + plainClassName
                        + "))"
                        + "&"
                        + checkForOtherSuperClass.get(i + 6)
                        + "::"
                        + specialnames.get(i)
                        + ") {");

              p1.println();

            } else {

              if (!(specialnames.get(i).equals(plainClassName))
                  && !(arr1.contains(specialnames.get(i)))) {

                ArrayList<Integer> getTheParameters = new ArrayList<Integer>();

                p1.print(
                    "      "
                        + specialnames.get(i)
                        + "(("
                        + types2.get(i)
                        + "(*)"
                        + "("
                        + plainClassName
                        + " , ");

                Pattern pp = Pattern.compile("_");

                Matcher mm = pp.matcher(parameters.get(specialnames.get(i)));

                while (mm.find()) {

                  getTheParameters.add(mm.start());
                }

                for (int cc = 0; cc < getTheParameters.size(); cc++) {

                  if (cc != getTheParameters.size() - 1) {

                    p1.print(
                        parameters
                                .get(specialnames.get(i))
                                .substring(
                                    getTheParameters.get(cc) + 1, getTheParameters.get(cc + 1))
                            + " , ");

                  } else {
                    int length = parameters.get(specialnames.get(i)).length();
                    p1.print(
                        parameters
                            .get(specialnames.get(i))
                            .substring(getTheParameters.get(cc) + 1, length));
                    if (i != names.size() - 1)
                      p1.print(
                          "))"
                              + "&"
                              + checkForOtherSuperClass.get(i + 6)
                              + "::"
                              + specialnames.get(i)
                              + "),");
                    else
                      p1.print(
                          "))"
                              + "&"
                              + checkForOtherSuperClass.get(i + 6)
                              + "::"
                              + specialnames.get(i)
                              + ") {");

                    p1.println();
                  }
                }

                // p1.println(getTheParameters);
              }
            }
          }
        }

        p1.println("    }");
        p1.println("};");
        p1.println();
        p1.println();
        p1.println();
        /*Remove comments below to Debug**/

      }
      // p1.println(names);

      p1.flush();
      p1.close();
    } catch (Exception e) {
    }
  }
Example #29
0
 public int matchCount() {
   return urls.size();
 }
  public void deinit(Appendable out, boolean force) throws Exception {
    Settings settings = new Settings(platform.getConfigFile());

    if (!force) {
      Justif justify = new Justif(80, 40);
      StringBuilder sb = new StringBuilder();
      Formatter f = new Formatter(sb);

      try {
        String list = listFiles(platform.getGlobal());
        if (list != null) {
          f.format("In global default environment:%n");
          f.format(list);
        }

        list = listFiles(platform.getLocal());
        if (list != null) {
          f.format("In local default environment:%n");
          f.format(list);
        }

        if (settings.containsKey(JPM_CACHE_GLOBAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_GLOBAL)));
          if (list != null) {
            f.format("In global configured environment:%n");
            f.format(list);
          }
        }

        if (settings.containsKey(JPM_CACHE_LOCAL)) {
          list = listFiles(IO.getFile(settings.get(JPM_CACHE_LOCAL)));
          if (list != null) {
            f.format("In local configured environment:%n");
            f.format(list);
          }
        }

        list = listSupportFiles();
        if (list != null) {
          f.format("jpm support files:%n");
          f.format(list);
        }

        f.format("%n%n");

        f.format(
            "All files listed above will be deleted if deinit is run with the force flag set"
                + " (\"jpm deinit -f\" or \"jpm deinit --force\"%n%n");
        f.flush();

        justify.wrap(sb);
        out.append(sb.toString());
      } finally {
        f.close();
      }
    } else { // i.e. if(force)
      int count = 0;
      File[] caches = {platform.getGlobal(), platform.getLocal(), null, null};
      if (settings.containsKey(JPM_CACHE_LOCAL)) {
        caches[2] = IO.getFile(settings.get(JPM_CACHE_LOCAL));
      }
      if (settings.containsKey(JPM_CACHE_GLOBAL)) {
        caches[3] = IO.getFile(settings.get(JPM_CACHE_GLOBAL));
      }
      ArrayList<File> toDelete = new ArrayList<File>();

      for (File cache : caches) {
        if (cache == null || !cache.exists()) {
          continue;
        }
        listFiles(cache, toDelete);
        if (toDelete.size() > count) {
          count = toDelete.size();
          if (!cache.canWrite()) {
            reporter.error(PERMISSION_ERROR + " (" + cache + ")");
            return;
          }
          toDelete.add(cache);
        }
      }
      listSupportFiles(toDelete);

      for (File f : toDelete) {
        if (f.exists() && !f.canWrite()) {
          reporter.error(PERMISSION_ERROR + " (" + f + ")");
        }
      }
      if (reporter.getErrors().size() > 0) {
        return;
      }

      for (File f : toDelete) {
        if (f.exists()) {
          IO.deleteWithException(f);
        }
      }
    }
  }