Ejemplo n.º 1
1
 boolean go(double ntime, Box box) {
   debug("go");
   g(ntime);
   for (int i = 0; i < bs.size() - 1; i++)
     if (bs.get(i) == box) {
       Box nb = box.h1 <= box.h2 ? bs.get(i - 1) : bs.get(i + 1);
       if (eq(nb.h, box.h)) {
         Box nbox = box.combine(nb);
         bs.remove(box);
         bs.add(i, nbox);
         bs.remove(nb);
       } else {
         nb.f += box.f;
         box.f = 0;
       }
       return true;
     }
   return false;
 }
Ejemplo n.º 2
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();
    }
  }
 public void init() {
   Scanner scan = new Scanner(System.in);
   count = scan.nextInt();
   x0 = scan.nextLong();
   y0 = scan.nextLong();
   int result = 0;
   boolean special = false;
   for (int i = 0; i < count; i++) {
     long tempx = scan.nextLong();
     long tempy = scan.nextLong();
     if (tempx == x0 && tempy == y0) {
       special = true;
       continue;
     }
     boolean isDuplicate = false;
     for (int j = 0; j < result; j++) {
       long x1 = xList.get(j);
       long y1 = yList.get(j);
       if ((x1 - x0) * (tempy - y0) == (y1 - y0) * (tempx - x0)) {
         isDuplicate = true;
         break;
       }
     }
     if (!isDuplicate) {
       xList.add(tempx);
       yList.add(tempy);
       result++;
     }
   }
   if (special && result == 0) result = 1;
   System.out.println(result);
   scan.close();
 }
Ejemplo n.º 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();
  }
Ejemplo n.º 5
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
Ejemplo n.º 6
0
 boolean solve2() {
   int t = nextInt();
   if (t == 0) return false;
   int n = nextInt();
   Tower[] towers = new Tower[t];
   for (int i = 0; i < t; i++) {
     towers[i] = new Tower(new Point(nextInt(), nextInt()), nextInt());
   }
   n++;
   Point[] p = new Point[n];
   for (int i = 0; i < n; i++) {
     p[i] = new Point(nextInt(), nextInt());
   }
   // System.err.println(Arrays.toString(p));
   ArrayList<Point> points = new ArrayList<Point>();
   double r = 1;
   for (int i = 0; i < n - 1; i++) {
     double dist = p[i].dist(p[i + 1]) - (1 - r);
     int e = (int) Math.floor(dist + 1 - EPS);
     Point v = p[i + 1].subtract(p[i]).norm();
     for (int j = 0; j < e; j++) {
       points.add(p[i].add(v.multiply(j).add(v.multiply(1 - r))));
     }
     r = p[i + 1].dist(points.get(points.size() - 1));
   }
   if (p[n - 1].dist(points.get(points.size() - 1)) > 0.5 - EPS) {
     points.add(p[n - 1]);
   }
   // System.err.println(points);
   char last = 0;
   ArrayList<String> ans = new ArrayList<String>();
   for (int i = 0; i < points.size(); i++) {
     double maxP = Integer.MIN_VALUE;
     char here = 0;
     for (int j = 0; j < t; j++) {
       double w = towers[j].get(points.get(i));
       if (maxP < w - EPS) {
         maxP = w;
         here = (char) (j + 'A');
       }
     }
     if (here != last) {
       ans.add("(" + i + "," + here + ")");
     }
     last = here;
   }
   for (int i = 0; i < ans.size(); i++) {
     if (i != 0) out.print(" ");
     out.print(ans.get(i));
   }
   out.println();
   return true;
 }
  /** Business logic to execute. */
  public VOListResponse updateWindowCustomizations(
      ArrayList oldRows, ArrayList newRows, String serverLanguageId, String username)
      throws Throwable {
    Statement stmt = null;
    Connection conn = null;
    try {
      if (this.conn == null) conn = getConn();
      else conn = this.conn;

      WindowCustomizationVO oldVO = null;
      WindowCustomizationVO newVO = null;
      for (int i = 0; i < oldRows.size(); i++) {
        oldVO = (WindowCustomizationVO) oldRows.get(i);
        newVO = (WindowCustomizationVO) newRows.get(i);
        TranslationUtils.updateTranslation(
            oldVO.getDescriptionSYS10(),
            newVO.getDescriptionSYS10(),
            newVO.getProgressiveSys10SYS12(),
            serverLanguageId,
            conn);
      }

      return new VOListResponse(newRows, false, newRows.size());
    } catch (Throwable ex) {
      Logger.error(
          username,
          this.getClass().getName(),
          "executeCommand",
          "Error while updating customized columns",
          ex);
      try {
        if (this.conn == null && conn != null)
          // rollback only local connection
          conn.rollback();
      } catch (Exception ex3) {
      }

      throw new Exception(ex.getMessage());
    } finally {
      try {
        if (this.conn == null && conn != null) {
          // close only local connection
          conn.commit();
          conn.close();
        }

      } catch (Exception exx) {
      }
    }
  }
Ejemplo n.º 8
0
 Point[] getConvex(Point[] points) {
   ArrayList<Point> hull = new ArrayList<Point>();
   for (Point p : points) {
     while (hull.size() >= 2
         && !isConvex(hull.get(hull.size() - 2), hull.get(hull.size() - 1), p)) {
       hull.remove(hull.size() - 1);
     }
     hull.add(p);
   }
   while (hull.size() >= 2 && hull.get(hull.size() - 1).x == hull.get(hull.size() - 2).x) {
     hull.remove(hull.size() - 1);
   }
   return hull.toArray(new Point[0]);
 }
Ejemplo n.º 9
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;
    }
  }
Ejemplo n.º 10
0
  // Executes the given action
  public void executeAction(Action a) {

    // For each state variable, retrieve the DD for it, evaluate it
    // w.r.t. the current state and build a new state.
    ArrayList new_state = new ArrayList();
    int c;
    for (c = 0; c < (_nVars << 1); c++) {
      new_state.add("-");
    }
    for (c = 0; c < (_nVars << 1); c++) {
      Object cur_assign = _state.get(c);
      if (cur_assign instanceof Boolean) {
        // System.out.println(a._tmID2DD);
        int nonprime_id = c + 1;
        int prime_id = nonprime_id - _nVars;
        Object DD = a._tmID2DD.get(new Integer(prime_id));
        _state.set(prime_id - 1, TRUE);
        double p_true = _mdp._context.evaluate(DD, _state);
        // System.out.println("ID: " + nonprime_id + ", " + prime_id + ": " +
        //		   _mdp._context.printNode(DD) + " -> " +
        //		   _mdp._df.format(p_true));
        new_state.set(c, (_r.nextFloat() < p_true) ? TRUE : FALSE);
      }
    }

    _state = new_state;
  }
Ejemplo n.º 11
0
 public ChangeVO updateRow(
     int windowNo,
     int AD_Tab_ID,
     int queryResultID,
     int relRowNo,
     Map<String, String> context,
     boolean force) {
   if (context == null || context.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "NoContext"));
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null || data.size() == 0)
     return new ChangeVO(true, Msg.translate(m_context, "CachedDataNotFound"));
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, Msg.translate(m_context, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID));
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue;
   if (force) retValue = tab.saveRow(ctx, windowNo, false, null);
   else retValue = tab.saveRow(ctx, windowNo, false, data.get(relRowNo));
   if (retValue.hasError()) return retValue;
   // Update Results
   String[] dataRow = retValue.rowData.clone();
   data.set(relRowNo, dataRow);
   postProcessChangeVO(retValue, windowNo, context, dataRow, tab);
   retValue.trxInfo = GridTab.getTrxInfo(tab.getTableName(), ctx, windowNo, tab.getTabNo());
   if (retValue.isRefreshAll()) {}
   return retValue;
 }
Ejemplo n.º 12
0
  /**
   * Get Field Lookup Value Direct
   *
   * @param windowNo Window
   * @param AD_Field_ID
   * @param keyValues array of id values
   * @param cache
   * @return list of display values
   */
  public ArrayList<NamePair> getLookupValueDirect(
      int AD_Field_ID, ArrayList<String> keyValues, boolean cache) {
    int windowNo = 0; // No Context
    ArrayList<NamePair> displayValues = new ArrayList<NamePair>();
    UIField field = getField(AD_Field_ID, windowNo);

    // if (cache && field.isLookup())
    // field.getLookup().removeAllElements();
    if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
    //
    for (int i = 0; i < keyValues.size(); i++) {
      String key = keyValues.get(i);
      String value = null;
      if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache);
      if (value == null) {
        /*
         * if(key == null) value = ""; else value = "<" + key + ">";
         */
        value = "";
      }
      NamePair pp = new ValueNamePair(key, value);
      displayValues.add(pp);
    }
    return displayValues;
  } // getLookupValueDirect
Ejemplo n.º 13
0
  public double evalBasisState(ArrayList state, double wb1, double wb2) {

    int sum_basis_1 = 0;
    int sum_basis_2 = 0;

    // TODO: Code to get connection links... use current state to get status
    // System.out.print(", Eval: " + state);
    Action a = (Action) _mdp._hmName2Action.get("noreboot");
    for (int c = 0; c < (_nVars << 1); c++) {
      Object cur_assign = state.get(c);
      if (cur_assign instanceof Boolean && ((Boolean) cur_assign).booleanValue()) {

        sum_basis_1++;

        // System.out.println(a._tmID2DD);
        int nonprime_id = c + 1;
        int prime_id = nonprime_id - _nVars;
        Object DD = a._tmID2DD.get(new Integer(prime_id));
        Set IDs = _mdp._context.getGIDs(DD);
        // System.out.print(IDs + ": ");
        Iterator it = IDs.iterator();
        // System.out.print("[" + prime_id + " - ");
        while (it.hasNext()) {
          int c_id = ((Integer) it.next()).intValue() - 1; // nonprime array index
          if (c_id < _nVars || c_id == c) { // Skip prime/np this var
            continue;
          }
          // System.out.print(c_id + " ");
          Object c_id_assign = state.get(c_id);
          if (c_id_assign instanceof Boolean && ((Boolean) c_id_assign).booleanValue()) {
            sum_basis_2++;
            break;
          }
        }
        // System.out.println("]");
      }
    }
    double val = wb1 * sum_basis_1 + wb2 * sum_basis_2;
    // System.out.println(state + ", b1: " + sum_basis_1 +
    //		   ", b2: " + sum_basis_2 + ", total: " +
    //		   _mdp._df.format(val));

    return val;
  }
Ejemplo n.º 14
0
 E nextEvent() {
   Box res = bs.get(0);
   double min = res.flowtime();
   for (Box b : bs)
     if (b.flowtime() < min) {
       min = b.flowtime();
       res = b;
     }
   return new F(res, time + min);
 }
Ejemplo n.º 15
0
	public void WriteUnparsed(){
		//@ToDo : Make this proper java!
		out.println("           <ValidichroUnparsed>");
		int s = unparsed_lines.size();
		for(int i=0;i<s;i++){
			String line=(String)unparsed_lines.get(i);
			out.println("           	<ValidichroUnparsedLine>"+line+"</ValidichroUnparsedLine>");
		}
		out.println("           </ValidichroUnparsed>");
	}
Ejemplo n.º 16
0
 /**
  * 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;
 }
Ejemplo n.º 17
0
 /** Fill Tab and Field arrays */
 private void fillTabsFieldsAndInitFieldsAndCreateDependencyRelations(UIWindow win, int windowNO) {
   ArrayList<UITab> tabs = win.getTabs();
   for (int j = 0; j < tabs.size(); j++) {
     UITab winTab = tabs.get(j);
     Integer tabKey = Integer.valueOf(winTab.getAD_Tab_ID());
     Integer ReferencetabKey = Integer.valueOf(winTab.getReferenced_Tab_ID());
     m_tabs.put(tabKey, winTab);
     m_referencetabs.put(ReferencetabKey, winTab);
     //
     ArrayList<UIField> fields = winTab.getFields();
     for (int k = 0; k < fields.size(); k++) {
       UIField field = fields.get(k);
       field.initialize(m_context, windowNO);
       Integer fieldKey = Integer.valueOf(field.getAD_Field_ID());
       // set the correct value
       if (field.isLookup()) field.getLookup().setContext(m_context, windowNO);
       m_fields.put(fieldKey, field);
     }
     winTab.createDependencyRelations();
   }
 } // fillTabsFields
Ejemplo n.º 18
0
 /** @param args the command line arguments */
 public static void main(String[] args) throws IOException {
   File names = new File("C:\\Users\\FRANKCHUKY\\Desktop\\whotnames.txt");
   Scanner sc = new Scanner(names);
   v = new Vector<String>();
   while (sc.hasNext()) {
     String get = sc.nextLine();
     v.addElement(get);
   }
   ArrayList<Vector> view = share(v);
   player1 = view.get(0);
   player2 = view.get(1);
   place.addElement(v.elementAt(0));
   v.removeElementAt(0);
   int determine = rules(place.elementAt(place.size() - 1), player1, player2, v);
   System.out.println(view);
   // System.out.println(player2);
 }
Ejemplo n.º 19
0
 public static ArrayList<String> serializeTree(TreeNode tree) {
   ArrayList<String> res = new ArrayList<>();
   LinkedList<TreeNode> queue = new LinkedList<>();
   queue.addLast(tree);
   while (!queue.isEmpty()) {
     TreeNode node = queue.removeFirst();
     if (node == null) {
       res.add(NULL);
     } else {
       res.add(String.valueOf(node.val));
       queue.add(node.left);
       queue.add(node.right);
     }
   }
   while (res.size() > 1 && res.get(res.size() - 1).equals(NULL)) {
     res.remove(res.size() - 1);
   }
   return res;
 }
Ejemplo n.º 20
0
  // this method basically will chop up the blocks and get their frequencies
  private static void getBlockFrequency() throws Exception {
    directory = "../../thesis-datasets/morph_file_100MB/";
    ReadFile.readFile(directory, fileList); // read the two files
    HashMap<Integer, Integer> blockFreq =
        new HashMap<Integer, Integer>(); // this stores the block in the map along there frequencies
    int start = 0; // start of the sliding window
    int end = start + window - 1; // ending boundary
    preliminaryStep(directory);
    // System.out.println("Choping the document TDDD " + fileList.get(0));
    long[] divisorArray = {
      1000
    }; // run the frequency code for these divisor values (AKA expected block Size)
    for (long i : divisorArray) {

      long divisor1 = i;
      long divisor2 = i / 2;
      long divisor3 = i / 4;
      long remainder = 7;
      long minBoundary = min_multiplier * i;
      long maxBoundary = max_multiplier * i;
      // System.out.println("Running Likelihood for " + i + " " + divisor2 + " " + divisor3);
      int totalBlocks =
          chopDocument(
              fileArray.get(0),
              hashed_File_List.get(0),
              divisor1,
              divisor2,
              divisor3,
              remainder,
              minBoundary,
              maxBoundary,
              blockFreq);
      // now output the block sizes, along with there frequencies and probilities
      for (Map.Entry<Integer, Integer> tuple : blockFreq.entrySet()) {
        // output the block freq
        double prob = (double) tuple.getValue() / (double) totalBlocks;
        System.out.println(tuple.getKey() + " " + tuple.getValue() + " " + prob);
      }

      blockFreq.clear();
    }
  }
Ejemplo n.º 21
0
 /**
  * Retrieve results for Tab. If the from/to range does not exist, it returns existing rows
  *
  * @param queryResultID stored query identifier provided by client
  * @param fromRow from row first is 0
  * @param noRows number of rows
  * @return array of rows of array of field values or null if error. You get the columnNames via
  *     String[] columns = uiTab.getColumnNames();
  */
 public String[][] getResults(int queryResultID, int fromRow, int noRows) {
   if (noRows < 0) {
     log.config("Invalid: fromRow=" + fromRow + ",noRows" + noRows);
   } else if (noRows == 0) return new String[][] {};
   //
   ArrayList<String[]> resultAll = m_results.get(queryResultID);
   if (resultAll == null) {
     log.config("No Results for queryResultID=" + queryResultID);
     return null;
   }
   if (resultAll.size() < fromRow) {
     log.config(
         "Insufficient Results for queryResultID="
             + queryResultID
             + ", Length="
             + resultAll.size()
             + ", fromRow="
             + fromRow);
     return null;
   }
   // copy
   if (resultAll.size() < noRows) {
     log.config(
         "Insufficient Rows for queryResultID="
             + queryResultID
             + ", Length="
             + resultAll.size()
             + ", fromRow="
             + fromRow
             + ", noRows="
             + noRows);
     noRows = resultAll.size();
   }
   String[][] result = new String[noRows][];
   for (int i = 0; i < noRows; i++) {
     int index = i + fromRow;
     if (index >= resultAll.size()) break;
     result[i] = resultAll.get(index);
   }
   return result;
 } // getResult
Ejemplo n.º 22
0
 /**
  * Get Field Lookup Value Direct
  *
  * @param windowNo Window
  * @param AD_Field_ID
  * @param keyValues array of id values
  * @param cache
  * @return list of display values
  */
 public ArrayList<String> getLookupValueOnlyDirect(
     int AD_Field_ID, ArrayList<String> keyValues, boolean cache) {
   int windowNo = 0; // No Context
   ArrayList<String> displayValues = new ArrayList<String>();
   UIField field = getField(AD_Field_ID, windowNo);
   if (field == null) log.warning("Cannot find AD_Field_ID=" + AD_Field_ID);
   //
   for (int i = 0; i < keyValues.size(); i++) {
     String key = keyValues.get(i);
     String value = null;
     if (field != null) value = field.getLookupDisplay(m_context, windowNo, key, cache);
     if (value == null) {
       /*
        * if(key == null) value = ""; else value = "<" + key + ">";
        */
       value = "";
     }
     displayValues.add(value);
   }
   return displayValues;
 } // getLookupValueDirect
Ejemplo n.º 23
0
  /*
  	- This reads the file and hashses the document, which are then stored in our arrayLisrs
  	- we do this before, so we dont have to hash again later ( which is time consuming)
  */
  private static void preliminaryStep(String dir) throws Exception {
    int start = 0; // start of the sliding window
    int end = start + window - 1; // ending boundary
    // prepoccessing step to hash the document, since we dont need to hash the document again
    for (int i = 0; i < fileList.size(); ++i) {
      // System.out.println("preliminaryStep " + fileList.get(i));
      Path p = Paths.get(dir + fileList.get(i)); // read this file
      byte[] array = Files.readAllBytes(p); // read the file in bytes
      // System.out.println(array.length);

      ArrayList<Long> md5Hashes = new ArrayList<Long>(); // make a new arrayList for this document
      HashDocument.hashDocument(
          array, md5Hashes, start,
          end); // this hashes the entire document using the window and stores itto md5hashes array

      // add the fileArray and hashedFile to our lists so we can use them later to run the
      // algorithms
      // note we hash and read file before, so we don't have to do it again
      fileArray.add(array);
      hashed_File_List.add(md5Hashes);
    }
  }
Ejemplo n.º 24
0
 /**
  * Delete existing Row
  *
  * @param windowNo relative window
  * @param AD_Tab_ID tab
  * @param relRowNo relative row number in results
  * @return error message or null
  */
 public ChangeVO deleteRow(int windowNo, int AD_Tab_ID, int queryResultID, int relRowNo) {
   UITab tab = getTab(AD_Tab_ID);
   if (tab == null) {
     log.config("Not found AD_Tab_ID=" + AD_Tab_ID);
     return new ChangeVO(true, "@NotFound@ @AD_Tab_ID@=" + AD_Tab_ID);
   }
   ArrayList<String[]> data = m_results.get(queryResultID);
   if (data == null) return new ChangeVO(true, "Data Not Found");
   String[] rowData = data.get(relRowNo);
   // Copy Data into Context
   Map<String, String> context = new HashMap<String, String>();
   String[] columns = tab.getColumnNames();
   for (int i = 0; i < columns.length; i++) {
     String column = columns[i];
     context.put(column, rowData[i]);
   }
   CContext ctx = new CContext(m_context.entrySet());
   ctx.addWindow(windowNo, context);
   ChangeVO retValue = tab.deleteRow(ctx, windowNo);
   if (retValue.hasError()) return retValue;
   // Update Results
   data.remove(relRowNo);
   return retValue;
 } // deleteRow
Ejemplo n.º 25
0
  /*
  	- This method is used has a helper method to run the algo for the archive dataset
  	- Note the archive set has multiple directories ( one for each url )
  	- So Read all of the directories in first and for each directory run the code
  */
  private static void runArchiveSet() throws Exception {

    System.out.println("Running TDDD archive");
    directory = "../../thesis-datasets/datasets2/";
    File file = new File(directory);
    String[] directory_list =
        file.list(
            new FilenameFilter() {
              @Override
              public boolean accept(File current, String name) {
                return new File(current, name).isDirectory(); // make sure its a directory
              }
            });

    int totalRuns = 0; // used to avg the runs in the end
    int total_iter_count =
        0; // this is used check how many times we will iterate through the data so we can make an
           // array of that size
    for (int i = startBoundary; i <= endBoundary; i += increment) total_iter_count++;

    // System.out.println(Arrays.toString(directory_list));
    int sets = 0;
    // make the arrays to hold the respecitve info for the different verions\
    // run it simulateounsly to speed the from the program!
    double[] block_size_list_last_year = new double[total_iter_count];
    double[] ratio_size_list_last_year = new double[total_iter_count];

    double[] block_size_list_six_month = new double[total_iter_count];
    double[] ratio_size_list__six_month = new double[total_iter_count];

    double[] block_size_list_two_year = new double[total_iter_count];
    double[] ratio_size_list_two_year = new double[total_iter_count];

    int current = 0;
    int six_month = 2;
    int last_year = 1;
    int two_year = 3;
    // loop through and run the cdc for each directory
    for (String dir : directory_list) {

      ReadFile.readFile(directory + dir, fileList); // read all the files in this directory
      preliminaryStep(directory + dir + "/"); // call the preliminaryStep on all the files

      totalRuns++;

      totalSize =
          fileArray.get(current)
              .length; // get the length of the file we will be running it against!

      // run it against six month
      startCDC(
          block_size_list_six_month,
          ratio_size_list__six_month,
          fileArray.get(current),
          fileArray.get(six_month),
          hashed_File_List.get(current),
          hashed_File_List.get(six_month));

      // run it against last year
      startCDC(
          block_size_list_last_year,
          ratio_size_list_last_year,
          fileArray.get(current),
          fileArray.get(last_year),
          hashed_File_List.get(current),
          hashed_File_List.get(last_year));

      // run it against 2
      startCDC(
          block_size_list_two_year,
          ratio_size_list_two_year,
          fileArray.get(current),
          fileArray.get(two_year),
          hashed_File_List.get(current),
          hashed_File_List.get(two_year));

      // // clear the fileList and hashed_file_list array
      fileArray.clear();
      hashed_File_List.clear();
      fileList.clear();

      // if (Double.isNaN(ratio_size_list[0])){
      // 	System.out.println(sets+" "+Arrays.toString(ratio_size_list));
      // 	test = true;
      // 	break;
      // }
      if (sets % 200 == 0) System.out.println(sets);
      ++sets;
    } // end of directory list for loop

    // now output the avged value for all the runs
    // System.out.println(Arrays.toString(ratio_size_list));
    System.out.println("Printing six_month");
    int index = 0;
    for (int i = startBoundary; i <= endBoundary; i += increment) {
      // avg out the outputs
      double blockSize = block_size_list_six_month[index] / (double) totalRuns;
      double ratio = ratio_size_list__six_month[index] / (double) totalRuns;
      System.out.println(i + " " + i / 2 + 1 + " " + i / 4 + 1 + " " + blockSize + " " + ratio);
      index++;
    }
    System.out.println("Printing last year");
    index = 0;
    for (int i = startBoundary; i <= endBoundary; i += increment) {
      double blockSize = block_size_list_last_year[index] / (double) totalRuns;
      double ratio = ratio_size_list_last_year[index] / (double) totalRuns;
      System.out.println(i + " " + blockSize + " " + ratio);
      index++;
    }

    System.out.println("Printing two year");
    index = 0;
    for (int i = startBoundary; i <= endBoundary; i += increment) {
      double blockSize = block_size_list_two_year[index] / (double) totalRuns;
      double ratio = ratio_size_list_two_year[index] / (double) totalRuns;
      System.out.println(i + " " + blockSize + " " + ratio);
      index++;
    }
  }
Ejemplo n.º 26
0
  public void sortResults(
      int WindowNo, int AD_Tab_ID, int AD_Field_ID, int queryResultID, final boolean ascending) {
    class SortCell {

      String[] row;

      String sort;
    }
    ArrayList<String[]> results = m_results.get(queryResultID);
    if (results == null)
      log.severe("cannot sort. results non-existent for queryResultID:" + queryResultID);
    UITab tab = getTab(AD_Tab_ID);
    final UIField field = getField(AD_Field_ID, WindowNo);
    final int displayType = field.getAD_Reference_ID();
    final int idx = tab.getFieldIndex(AD_Field_ID);
    // if not a lookup, directly sort
    if (!field.isLookup()) {
      if (FieldType.isNumeric(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                BigDecimal s1 = new BigDecimal(o1[idx].equals("") ? "-1e-10" : o1[idx]);
                BigDecimal s2 = new BigDecimal(o2[idx].equals("") ? "-1e-10" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else if (FieldType.isDate(displayType)) {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                Long s1 = new Long(o1[idx].equals("") ? "-1000000" : o1[idx]);
                Long s2 = new Long(o2[idx].equals("") ? "-1000000" : o2[idx]);
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      } else {
        Collections.sort(
            results,
            new Comparator<String[]>() {

              @Override
              public int compare(String[] o1, String[] o2) {
                if (o1[idx] == null) o1[idx] = "";
                if (o2[idx] == null) o2[idx] = "";
                String s1 = o1[idx];
                String s2 = o2[idx];
                return ascending ? s1.compareTo(s2) : s2.compareTo(s1);
              }
            });
      }
      return;
    }
    Comparator<SortCell> c =
        new Comparator<SortCell>() {

          public int compare(SortCell o1, SortCell o2) {
            if (ascending) return o1.sort.compareTo(o2.sort);
            else return o2.sort.compareTo(o1.sort);
          }
        };
    // for look up, first get id values
    ArrayList<String> fieldValues = new ArrayList<String>(results.size());
    for (String[] row : results) {
      fieldValues.add(row[idx]);
    }
    // then translate into real values
    ArrayList<String> sorts = getLookupValueOnlyDirect(AD_Field_ID, fieldValues, true);
    ArrayList<SortCell> toBeSorteds = new ArrayList<SortCell>(sorts.size());
    for (int i = 0; i < sorts.size(); i++) {
      SortCell toBeSorted = new SortCell();
      toBeSorted.row = results.get(i);
      toBeSorted.sort = sorts.get(i);
      toBeSorteds.add(toBeSorted);
    }
    // sort
    Collections.sort(toBeSorteds, c);
    // after sorting, replace col with original values
    int i = 0;
    for (SortCell toBeSorted : toBeSorteds) {
      results.set(i, toBeSorted.row);
      i++;
    }
  }
Ejemplo n.º 27
0
  /*
  	-- This is a helper method to run the periodic dataset basically

  */
  private static void runPeriodic() throws Exception {
    System.out.println("Running TDDD Periodic");
    // this is alll the directories we will be running
    int arr[] = {10, 15, 20, 25, 30}; // this is the input number we will be running on
    // this is the base of the two files
    // these two are directories, we will concanate with the numbers to get the full dir name
    String base_old_file = "../../thesis-datasets/input_";
    String base_new_file = "../../thesis-datasets/periodic_";

    int total_iter_count =
        0; // this is used check how many times we will iterate through the data so we can make an
           // array of that size
    for (int i = startBoundary; i <= endBoundary; i += increment) total_iter_count++;

    for (int dir_num : arr) {
      // set up our directories

      String old_file_dir = base_old_file + dir_num + "/";
      String new_file_dir = base_new_file + dir_num + "/";
      System.out.println(old_file_dir);

      // read all the files in these two directories in sorted order
      ArrayList<String> old_file_list = new ArrayList<String>();
      ArrayList<String> new_file_list = new ArrayList<String>();

      ReadFile.readFile(old_file_dir, old_file_list);
      ReadFile.readFile(new_file_dir, new_file_list);

      // used to store all the runnings for the periodic data
      double[] block_size_list = new double[total_iter_count];
      double[] ratio_size_list = new double[total_iter_count];
      int totalRuns = 0;

      for (int i = 0; i < old_file_list.size(); ++i) {
        // System.out.println(old_file_list.get(i) + " " + new_file_list.get(i));
        String[] s1 = old_file_list.get(i).split("_");
        String[] s2 = new_file_list.get(i).split("_");
        // input file should corrospond to the output file
        if (!s1[1].equals(s2[1]) || !s1[2].equals(s2[2]))
          System.out.println("We got a huge problem");

        // basically same code as in the prelinaryStep method, but we need to modify it for
        // perdiodic files
        int start = 0; // start of the sliding window
        int end = start + window - 1; // ending boundary
        // we cant call preliminary function, so hash the two files individually
        // System.out.println("preliminaryStep " + fileList.get(i));
        Path p =
            Paths.get(
                old_file_dir
                    + old_file_list.get(
                        i)); // read the old file ( the one which we will be using as the base
                             // comparason)
        Path p2 =
            Paths.get(
                new_file_dir
                    + new_file_list.get(
                        i)); // read the old file ( the one which we will be using as the base
                             // comparason)

        byte[] old_file = Files.readAllBytes(p); // read the file in bytes
        byte[] new_file = Files.readAllBytes(p2);
        // System.out.println(array.length);
        ArrayList<Long> old_file_hashes =
            new ArrayList<Long>(); // make a new arrayList for this document
        ArrayList<Long> new_file_hashes =
            new ArrayList<Long>(); // make a new arrayList for this document

        HashDocument.hashDocument(
            old_file,
            old_file_hashes,
            start,
            end); // this hashes the entire document using the window and stores itto md5hashes
                  // array
        HashDocument.hashDocument(
            new_file,
            new_file_hashes,
            start,
            end); // this hashes the entire document using the window and stores itto md5hashes
                  // array

        // now call the startCdc method
        totalSize = new_file.length; // this is the length of the file
        startCDC(
            block_size_list, ratio_size_list, new_file, old_file, new_file_hashes, old_file_hashes);

        if (totalRuns % 10 == 0) System.out.println(totalRuns);
        totalRuns++;
      }

      // now output the results
      System.out.println("File dir = " + dir_num + " totalRuns = " + totalRuns);
      int index = 0;
      for (int i = startBoundary; i <= endBoundary; i += increment) {
        // avg out the outputs
        double blockSize = block_size_list[index] / (double) totalRuns;
        double ratio = ratio_size_list[index] / (double) totalRuns;
        System.out.println(i + " " + blockSize + " " + ratio);
        index++;
      }

      // now each index matches the corrosponding file
    }
  } // end of methid
Ejemplo n.º 28
0
  /* -------------------------------------------------------------------------------------------------------
  This method:

  	This method:
  	--	Takes in three paramters:
  		1. array - this is the byte array that actually holds the document contents
  		2. md5Hases - holds the entire hash values of the document
  		3. Divisor1/Divisor2/divisor3... - main and back up divisors
  		5. The remainder we are looking for
  		6/7. min/max boundaries

  	-- We will start running the karb rabin algorithm
  	-- We will find the boundaries using mod values and once they equal the mod value we have stored
  	-- we also have the divsor2/3 .. which are backup divisors. If we don't find a boundary by the divisor1 once we hit the maxBoundary
  	-- we will see if we have one with divisor2, if not, then we will see if we have one with divisor3 and so on
  	-- We will hash everything in that hash boundary and store it
  -------------------------------------------------------------------------------------------------------- */
  private static void runTddd(
      byte[] array,
      ArrayList<Long> md5Hashes,
      long divisor1,
      long divisor2,
      long divisor3,
      long remainder,
      long minBoundary,
      long maxBoundary) {
    int documentStart = 0; // used to keep track of where the boundaries are
    boolean match = false; // used to ck if we encountered a match
    int backUpBreakPoint = -1; // used to store the backup breakpoint
    int secondBackUpBreakPoint = -1; // used with the divisor3
    StringBuilder builder = new StringBuilder();
    int i = documentStart + (int) minBoundary - 1; // so we start at the minimum
    // loop through all the values in the document
    for (; i < md5Hashes.size() - 1; ++i) {
      // if ((i - documentStart + 1) < minBoundary) //  if the size of this boundary is less than
      // the min, continue looping
      // 	continue;
      /*-----------------------------------------------------------------
      	- If the mod of this equals the modvalue we defined, then
      	- this is a boundary
      ------------------------------------------------------------------*/

      if ((md5Hashes.get(i - 1) + md5Hashes.get(i) + md5Hashes.get(i + 1)) % divisor1
          == remainder) // ck if this equals the mod value
      {
        // Hash all the values in the range (documentStart,current(i))
        // Remember we only want to hash the original VALUES from the array that contains the
        // original
        // content of the file. Not the hash values in the md5Hash Array
        for (int j = documentStart; j <= i; ++j) {
          builder.append(array[j]); // store everything upto the current value
        }
        String original = builder.toString();
        // if the string is a perfect match ( hash and original string)
        if (HashClass.is_string_match(original, table)) // iinsert the hash in the table)
        coverage += i - documentStart + 1; // this is the amount of bytes we saved
        documentStart = i + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1;
        numOfPieces++; // increment the num of pieces
        i = i + (int) minBoundary - 1; // skip all the way here
        builder.setLength(0); // reset the stringBuilder for the next round
      } else if ((md5Hashes.get(i - 1) + md5Hashes.get(i) + md5Hashes.get(i + 1)) % divisor2
          == remainder) { //  check if this is the backup point
        backUpBreakPoint = i; // this is the backup breakpoint
      } else if ((md5Hashes.get(i - 1) + md5Hashes.get(i) + md5Hashes.get(i + 1)) % divisor2
          == remainder) {
        secondBackUpBreakPoint = i; // set the second backup point
      }
      if ((i - documentStart + 1) >= maxBoundary) { // we have reached the maximum
        // ck if we have a backUpbreakpoint
        int point;
        if (backUpBreakPoint != -1) // if we do, set this as the boundary
        point = backUpBreakPoint;
        else if (secondBackUpBreakPoint != -1) {
          point = secondBackUpBreakPoint; // if we don't have a first break point, find the second
        } else point = i; // else this current value of i is the breakpoint

        // Hash all the values in the range (documentStart,current(i))
        // Remember we only want to hash the original VALUES from the array that contains the
        // original
        // content of the file. Not the hash values in the md5Hash Array
        for (int j = documentStart; j <= point; ++j) {
          builder.append(array[j]); // store everything upto the current value
        }
        String original = builder.toString();
        if (HashClass.is_string_match(original, table))
          coverage += point - documentStart + 1; // this is the amount of bytes we saved
        numOfPieces++; // increment the num of pieces
        documentStart = point + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1; // reset the secondBackUp point
        i = point + (int) minBoundary - 1; // skip all the way here ;
        builder.setLength(0); // reset the stringBuilder for the next round
      }
    } // end of the for loop

    // -------------------------------------------------------------------------------------------
    //  we are missing the last boundary, so hash that last value
    //	We will also check against our values of the strings we already have, and if we encountered
    // this
    //	already, then we will simply increment the counter, otherwise we will insert it in the
    // hashtable
    //	and increase our miss counter
    // ----------------------------------------------------------------------------------------------
    for (int j = documentStart; j < array.length; ++j) {
      builder.append(array[j]);
    }
    // only compute hash and insert into our hashtable only if the string buffer isn't empty
    String original = builder.toString();
    if (HashClass.is_string_match(original, table))
      coverage += array.length - documentStart; // this is the amount of bytes we saved
    numOfPieces++; // increment the num of pieces
  } // end of the method
  /** Business logic to execute. */
  public VOListResponse loadOutDeliveryNotesForSaleDoc(
      GridParams pars, String serverLanguageId, String username, ArrayList companiesList)
      throws Throwable {
    PreparedStatement pstmt = null;
    Connection conn = null;
    try {
      if (this.conn == null) conn = getConn();
      else conn = this.conn;

      // retrieve companies list...
      String companies = "";
      for (int i = 0; i < companiesList.size(); i++)
        companies += "'" + companiesList.get(i).toString() + "',";
      companies = companies.substring(0, companies.length() - 1);

      String sql =
          "select DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01,DOC08_DELIVERY_NOTES.DOC_TYPE,"
              + "DOC08_DELIVERY_NOTES.DOC_YEAR,DOC08_DELIVERY_NOTES.DOC_NUMBER,DOC08_DELIVERY_NOTES.DOC_DATE, "
              + "DOC08_DELIVERY_NOTES.DESTINATION_CODE_REG18,DOC08_DELIVERY_NOTES.DESCRIPTION,"
              + "DOC08_DELIVERY_NOTES.DOC_SEQUENCE "
              + " from DOC08_DELIVERY_NOTES where "
              + "DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01 in ("
              + companies
              + ") and "
              + "DOC08_DELIVERY_NOTES.ENABLED='Y' and "
              + "DOC08_DELIVERY_NOTES.DOC_TYPE=? and "
              + "DOC08_DELIVERY_NOTES.DOC_STATE=? and "
              + "(DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01,DOC08_DELIVERY_NOTES.DOC_TYPE,DOC08_DELIVERY_NOTES.DOC_YEAR,DOC08_DELIVERY_NOTES.DOC_NUMBER) "
              + " in (select DOC10_OUT_DELIVERY_NOTE_ITEMS.COMPANY_CODE_SYS01,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_TYPE,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_YEAR,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_NUMBER "
              + " from DOC10_OUT_DELIVERY_NOTE_ITEMS where "
              + " DOC10_OUT_DELIVERY_NOTE_ITEMS.COMPANY_CODE_SYS01=? and "
              + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_TYPE_DOC01=? and "
              + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_YEAR_DOC01=? and "
              + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_NUMBER_DOC01=? ";

      DetailSaleDocVO docVO =
          (DetailSaleDocVO)
              pars.getOtherGridParams().get(ApplicationConsts.SALE_DOC_VO); // invoice document...
      if (docVO.getDocNumberDOC01() == null)
        sql +=
            " and DOC10_OUT_DELIVERY_NOTE_ITEMS.QTY-DOC10_OUT_DELIVERY_NOTE_ITEMS.INVOICE_QTY>0)";
      else sql += ")";

      Map attribute2dbField = new HashMap();
      attribute2dbField.put("companyCodeSys01DOC08", "DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01");
      attribute2dbField.put("docTypeDOC08", "DOC08_DELIVERY_NOTES.DOC_TYPE");
      attribute2dbField.put("docYearDOC08", "DOC08_DELIVERY_NOTES.DOC_YEAR");
      attribute2dbField.put("docNumberDOC08", "DOC08_DELIVERY_NOTES.DOC_NUMBER");
      attribute2dbField.put("docDateDOC08", "DOC08_DELIVERY_NOTES.DOC_DATE");
      attribute2dbField.put(
          "destinationCodeReg18DOC08", "DOC08_DELIVERY_NOTES.DESTINATION_CODE_REG18");
      attribute2dbField.put("descriptionDOC08", "DOC08_DELIVERY_NOTES.DESCRIPTION");
      attribute2dbField.put("docSequenceDOC08", "DOC08_DELIVERY_NOTES.DOC_SEQUENCE");

      ArrayList values = new ArrayList();
      values.add(ApplicationConsts.OUT_DELIVERY_NOTE_DOC_TYPE);
      values.add(ApplicationConsts.CLOSED);
      values.add(docVO.getCompanyCodeSys01DOC01());
      values.add(docVO.getDocTypeDoc01DOC01());
      values.add(docVO.getDocYearDoc01DOC01());
      values.add(docVO.getDocNumberDoc01DOC01());

      // read from DOC08 table...
      Response res =
          QueryUtil.getQuery(
              conn,
              new UserSessionParameters(username),
              sql,
              values,
              attribute2dbField,
              OutDeliveryNotesVO.class,
              "Y",
              "N",
              null,
              pars,
              true);

      if (res.isError()) throw new Exception(res.getErrorMessage());

      // check if the invoice document has been already created and there exists delivery notes
      // linked to it...
      if (docVO.getDocNumberDOC01() != null) {
        pstmt =
            conn.prepareStatement(
                "select DOC08_DELIVERY_NOTES.DOC_NUMBER from DOC08_DELIVERY_NOTES where "
                    + "DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01 in ("
                    + companies
                    + ") and "
                    + "DOC08_DELIVERY_NOTES.ENABLED='Y' and "
                    + "DOC08_DELIVERY_NOTES.DOC_TYPE=? and "
                    + "DOC08_DELIVERY_NOTES.DOC_STATE=? and "
                    + "(DOC08_DELIVERY_NOTES.COMPANY_CODE_SYS01,DOC08_DELIVERY_NOTES.DOC_TYPE,DOC08_DELIVERY_NOTES.DOC_YEAR,DOC08_DELIVERY_NOTES.DOC_NUMBER) "
                    + " in (select DOC10_OUT_DELIVERY_NOTE_ITEMS.COMPANY_CODE_SYS01,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_TYPE,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_YEAR,DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_NUMBER "
                    + " from DOC10_OUT_DELIVERY_NOTE_ITEMS,DOC02_SELLING_ITEMS where "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.COMPANY_CODE_SYS01=? and "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_TYPE_DOC01=? and "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_YEAR_DOC01=? and "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.DOC_NUMBER_DOC01=? and "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.COMPANY_CODE_SYS01=DOC02_SELLING_ITEMS.COMPANY_CODE_SYS01 and "
                    + " DOC02_SELLING_ITEMS.DOC_TYPE=? and "
                    + " DOC02_SELLING_ITEMS.DOC_YEAR=? and "
                    + " DOC02_SELLING_ITEMS.DOC_NUMBER=? and "
                    + " DOC10_OUT_DELIVERY_NOTE_ITEMS.ITEM_CODE_ITM01=DOC02_SELLING_ITEMS.ITEM_CODE_ITM01)");

        pstmt.setString(1, ApplicationConsts.OUT_DELIVERY_NOTE_DOC_TYPE);
        pstmt.setString(2, ApplicationConsts.CLOSED);
        pstmt.setString(3, docVO.getCompanyCodeSys01DOC01());
        pstmt.setString(4, docVO.getDocTypeDoc01DOC01());
        pstmt.setBigDecimal(5, docVO.getDocYearDoc01DOC01());
        pstmt.setBigDecimal(6, docVO.getDocNumberDoc01DOC01());
        pstmt.setString(7, docVO.getDocTypeDOC01());
        pstmt.setBigDecimal(8, docVO.getDocYearDOC01());
        pstmt.setBigDecimal(9, docVO.getDocNumberDOC01());

        HashSet docNumberDOC08s = new HashSet();
        ResultSet rset = pstmt.executeQuery();
        while (rset.next()) docNumberDOC08s.add(rset.getBigDecimal(1));
        rset.close();

        java.util.List rows = ((VOListResponse) res).getRows();
        OutDeliveryNotesVO vo = null;
        for (int i = 0; i < rows.size(); i++) {
          vo = (OutDeliveryNotesVO) rows.get(i);
          if (docNumberDOC08s.contains(vo.getDocNumberDOC08())) vo.setSelected(Boolean.TRUE);
        }
      }

      Response answer = res;
      if (answer.isError()) throw new Exception(answer.getErrorMessage());
      else return (VOListResponse) answer;
    } catch (Throwable ex) {
      Logger.error(
          username,
          this.getClass().getName(),
          "executeCommand",
          "Error while fetching out delivery notes list, related to the specified sale document",
          ex);
      throw new Exception(ex.getMessage());
    } finally {
      try {
        pstmt.close();
      } catch (Exception exx) {
      }
      try {
        if (this.conn == null && conn != null) {
          // close only local connection
          conn.commit();
          conn.close();
        }

      } catch (Exception exx) {
      }
    }
  }
Ejemplo n.º 30
0
  /* -------------------------------------------------------------------------------------------------------
  This method:
  	--	Takes in three paramters:
  		1. array - this is the byte array that actually holds the document contents
  		2. md5Hases - holds the entire hash values of the document
  		3. Divisor1/Divisor2 - main and back up divisor
  		5. The remainder we are looking for
  		6/7. min/max boundaries
  		8. blockFreq - store the block sizes and how many time's they occur

  	-- We are simply choping up the first file
  -------------------------------------------------------------------------------------------------------- */
  private static int chopDocument(
      byte[] array,
      ArrayList<Long> md5Hashes,
      long divisor1,
      long divisor2,
      long divisor3,
      long remainder,
      long minBoundary,
      long maxBoundary,
      HashMap<Integer, Integer> blockFreq) {

    int documentStart = 0; // used to keep track of where the boundaries are
    boolean match = false; // used to ck if we encountered a match
    int backUpBreakPoint = -1; // used to store the backup breakpoint
    int secondBackUpBreakPoint = -1; // this is the second backup point with the divisor3
    StringBuilder builder = new StringBuilder();
    int counter = 0;
    int i = documentStart + (int) minBoundary - 1; // so we start at the minimum
    // loop through all the values in the document
    for (; i < md5Hashes.size(); ++i) {

      if (md5Hashes.get(i) % divisor1 == remainder) // ck if this equals the mod value
      {
        int size = i - documentStart + 1; // we only care about the size
        if (blockFreq.get(size) == null) // if not in there, then simply store it
        blockFreq.put(size, 1);
        else // increment it's integer count
        blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
        counter++; // increment the block count
        documentStart = i + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1; // second backup point reset it!
        i = i + (int) minBoundary - 1; // skip all the way here
      } else if (md5Hashes.get(i) % divisor2 == remainder) { //  check if this is the backup point
        backUpBreakPoint = i; // this is the backup breakpoint
      } else if (md5Hashes.get(i) % divisor3 == remainder) {
        secondBackUpBreakPoint = i; // we found a second backup point with divisor3
      }
      if ((i - documentStart + 1) >= maxBoundary) { // we have reached the maximum
        // ck if we have a backUpbreakpoint
        int point;
        if (backUpBreakPoint != -1) // if we do, set this as the boundary
        point = backUpBreakPoint;
        else if (secondBackUpBreakPoint != -1)
          point = secondBackUpBreakPoint; // if we don't have a first backup, ck if we have a second
        else point = i; // else this current value of i is the breakpoint

        // Hash all the values in the range (documentStart,point
        // Remember we only want to hash the original VALUES from the array that contains the
        // original
        // content of the file. Not the hash values in the md5Hash Array
        int size = point - documentStart + 1; // we only care about the size
        if (blockFreq.get(size) == null) // if not in there, then simply store it
        blockFreq.put(size, 1);
        else // increment it's integer count
        blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
        counter++; // increment the block count
        documentStart = point + 1; // set this as the beginning of the new boundary
        backUpBreakPoint = -1; // reset this
        secondBackUpBreakPoint = -1; // reset second backup break point
        i = point + (int) minBoundary - 1; // so we start at the minimum
      }
    } // end of the for loop

    // -------------------------------------------------------------------------------------------
    //  we are missing the last boundary, so hash that last value
    //	We will also check against our values of the strings we already have, and if we encountered
    // this
    //	already, then we will simply increment the counter, otherwise we will insert it in the
    // hashtable
    //	and increase our miss counter
    // ----------------------------------------------------------------------------------------------
    int size = array.length - documentStart; // we start from the point
    if (blockFreq.get(size) == null) // if not in there, then simply store it
    blockFreq.put(size, 1);
    else // increment it's integer count
    blockFreq.put(size, blockFreq.get(size) + 1); // increment the count
    return ++counter; // increment the block count
  } // end of the method