List of usage examples for java.util Arrays binarySearch
public static int binarySearch(Object[] a, Object key)
From source file:com.cg.mapreduce.fpgrowth.mahout.fpm.fpgrowth.FPGrowth.java
private static FrequentPatternMaxHeap growth(FPTree tree, MutableLong minSupportMutable, int k, FPTreeDepthCache treeCache, int level, int currentAttribute, StatusUpdater updater) { FrequentPatternMaxHeap frequentPatterns = new FrequentPatternMaxHeap(k, true); int i = Arrays.binarySearch(tree.getHeaderTableAttributes(), currentAttribute); if (i < 0) { return frequentPatterns; }/* w ww. j av a 2 s. c o m*/ int headerTableCount = tree.getHeaderTableCount(); while (i < headerTableCount) { int attribute = tree.getAttributeAtIndex(i); long count = tree.getHeaderSupportCount(attribute); if (count < minSupportMutable.longValue()) { i++; continue; } updater.update("FPGrowth Algorithm for a given feature: " + attribute); FPTree conditionalTree = treeCache.getFirstLevelTree(attribute); if (conditionalTree.isEmpty()) { traverseAndBuildConditionalFPTreeData(tree.getHeaderNext(attribute), minSupportMutable.longValue(), conditionalTree, tree); // printTree(conditionalTree); } FrequentPatternMaxHeap returnedPatterns; if (attribute == currentAttribute) { returnedPatterns = growthTopDown(conditionalTree, minSupportMutable, k, treeCache, level + 1, true, currentAttribute, updater); frequentPatterns = mergeHeap(frequentPatterns, returnedPatterns, attribute, count, true); } else { returnedPatterns = growthTopDown(conditionalTree, minSupportMutable, k, treeCache, level + 1, false, currentAttribute, updater); frequentPatterns = mergeHeap(frequentPatterns, returnedPatterns, attribute, count, false); } if (frequentPatterns.isFull() && minSupportMutable.longValue() < frequentPatterns.leastSupport()) { minSupportMutable.setValue(frequentPatterns.leastSupport()); } i++; } return frequentPatterns; }
From source file:com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck.java
/** * Decides whether the number of an AST is in the ignore list of this * check./*from w w w . j a v a 2 s . co m*/ * @param ast the AST to check * @return true if the number of ast is in the ignore list of this check. */ private boolean isInIgnoreList(DetailAST ast) { double value = CheckUtils.parseDouble(ast.getText(), ast.getType()); final DetailAST parent = ast.getParent(); if (parent.getType() == TokenTypes.UNARY_MINUS) { value = -1 * value; } return Arrays.binarySearch(ignoreNumbers, value) >= 0; }
From source file:net.dorokhov.pony.web.server.common.StreamingViewRenderer.java
/** * Returns true if the given accept header accepts the given value. * @param acceptHeader The accept header. * @param toAccept The value to be accepted. * @return True if the given accept header accepts the given value. *//*from w ww .jav a 2s . c om*/ private static boolean accepts(String acceptHeader, String toAccept) { String[] acceptValues = acceptHeader.split("\\s*(,|;)\\s*"); Arrays.sort(acceptValues); return Arrays.binarySearch(acceptValues, toAccept) > -1 || Arrays.binarySearch(acceptValues, toAccept.replaceAll("/.*$", "/*")) > -1 || Arrays.binarySearch(acceptValues, "*/*") > -1; }
From source file:fastcall.FastCallSNP.java
private String getVCFString(String[] base, int[] depth, int currentChr, int position, byte refBase) { TByteArrayList bList;/*from w w w . j a v a2 s. co m*/ boolean ifRecordedDeletion = false; TIntHashSet insertionLengthSet = new TIntHashSet(); TIntHashSet deletionLengthSet = new TIntHashSet(); int[][] pAlleleCount = new int[base.length][this.possibleAllele.length]; int[] refDepth = new int[base.length]; for (int i = 0; i < base.length; i++) { bList = new TByteArrayList(); byte[] ba = base[i].getBytes(); for (int j = 0; j < ba.length; j++) { if (ba[j] == '.') { bList.add(refBase); } else if (ba[j] == ',') { bList.add(refBase); } else if (ba[j] == 'A') { bList.add((byte) 65); } else if (ba[j] == 'a') { bList.add((byte) 65); } else if (ba[j] == 'C') { bList.add((byte) 67); } else if (ba[j] == 'c') { bList.add((byte) 67); } else if (ba[j] == 'G') { bList.add((byte) 71); } else if (ba[j] == 'g') { bList.add((byte) 71); } else if (ba[j] == 'T') { bList.add((byte) 84); } else if (ba[j] == 't') { bList.add((byte) 84); } else if (ba[j] == '+') { int endIndex = j + 2; for (int k = j + 1; k < ba.length; k++) { if (ba[k] > 57) { endIndex = k; break; } } StringBuilder sb = new StringBuilder(); for (int k = j + 1; k < endIndex; k++) { sb.append((char) ba[k]); } int length = Integer.valueOf(sb.toString()); insertionLengthSet.add(length); j += sb.length(); j += length; if (ba[j - 1] == '.' || ba[j - 1] == ',') { bList.add((byte) 73); } } else if (ba[j] == '-') { int endIndex = j + 2; for (int k = j + 1; k < ba.length; k++) { if (ba[k] > 57) { endIndex = k; break; } } StringBuilder sb = new StringBuilder(); for (int k = j + 1; k < endIndex; k++) { sb.append((char) ba[k]); } int length = Integer.valueOf(sb.toString()); deletionLengthSet.add(length); j += sb.length(); j += length; if (ba[j - 1] == '.' || ba[j - 1] == ',') { bList.add((byte) 68); } } else if (ba[j] == '^') { j++; } else if (ba[j] == '*') { bList.add(refBase); ifRecordedDeletion = true; } //N, n, $, >, < else { //do nothing } } byte[] taxonBase = bList.toArray(); for (int j = 0; j < taxonBase.length; j++) { int index = Arrays.binarySearch(this.possibleAllele, taxonBase[j]); pAlleleCount[i][index]++; } int altSum = 0; for (int j = 0; j < pAlleleCount[i].length; j++) { if (this.possibleAllele[j] == refBase) continue; // if (this.possibleAllele[j] == 68) continue; // if (this.possibleAllele[j] == 73) continue; altSum += pAlleleCount[i][j]; } refDepth[i] = depth[i] - altSum; } int totalDepth = 0; for (int i = 0; i < depth.length; i++) { totalDepth += depth[i]; } int[] indelTypeCount = new int[2]; indelTypeCount[0] = deletionLengthSet.size(); indelTypeCount[1] = insertionLengthSet.size(); //****************************Filter1 IndelFilter***************************************** //Too many indels usually means mis-alignment if (indelTypeCount[0] + indelTypeCount[1] > 1) return null; //=======================================Filter1===================================================== //****************************Filter2 Depth_ratio_test***************************************** //In any individual, alt allele show up < 2 times, ignore //In any individual, alt allele show up 2 times when 2 < depth < 5. Pick up //In any individual, alt allele show up > individualDepthRatioThresh, when depth >= 5. Pick up //When depth is low, tend to have assembly errors, LTR TByteHashSet altAlleleSet = new TByteHashSet(); for (int i = 0; i < pAlleleCount[0].length; i++) { if (possibleAllele[i] == refBase) continue; for (int j = 0; j < pAlleleCount.length; j++) { if (depth[j] < 2) { } else if (depth[j] < 5) { if (pAlleleCount[j][i] >= 2) { altAlleleSet.add(this.possibleAllele[i]); } } else { if ((double) pAlleleCount[j][i] / depth[j] > this.individualDepthRatioThresh) { altAlleleSet.add(this.possibleAllele[i]); } } } } byte[] altAllele = altAlleleSet.toArray(); if (altAllele.length == 0) return null; Arrays.sort(altAllele); //=======================================Filter2===================================================== int[] altAllele2PAlleleIndex = new int[altAllele.length]; for (int i = 0; i < this.possibleAllele.length; i++) { int index = Arrays.binarySearch(altAllele, this.possibleAllele[i]); if (index < 0) continue; altAllele2PAlleleIndex[index] = i; } int[] altAlleleTotalDepth = new int[altAllele.length]; for (int i = 0; i < altAllele.length; i++) { for (int j = 0; j < base.length; j++) { altAlleleTotalDepth[i] += pAlleleCount[j][altAllele2PAlleleIndex[i]]; } } int[] altAlleleDepthDesendingIndex = FArrayUtils.getIndexByDescendingValue(altAlleleTotalDepth); int refTotalDepth = 0; for (int i = 0; i < refDepth.length; i++) refTotalDepth += refDepth[i]; //****************************Filter3 third_allele_test************************************************ //individual should not have the third allele if (altAllele.length > 1) { for (int i = 0; i < base.length; i++) { int[] tempCnt = new int[altAllele.length]; for (int j = 0; j < altAllele.length; j++) { tempCnt[j] = pAlleleCount[i][altAllele2PAlleleIndex[j]]; } int sum = refDepth[i]; double[] v = new double[altAllele.length + 1]; for (int j = 0; j < tempCnt.length; j++) v[j] = (double) tempCnt[j] / sum; v[v.length - 1] = (double) refDepth[i] / sum; Arrays.sort(v); if (v[v.length - 3] > individualThirdAlleleRatioThresh) return null; } } //===========================Filter3========================================================= //****************************Filter4 Segregation_test***************************************** long[] observed = new long[base.length]; double[] expected = new double[base.length]; double[] segregationP = new double[altAllele.length]; ChiSquareTest ct = new ChiSquareTest(); int cnt = 0; for (int i = 0; i < altAllele.length; i++) { double r = (double) altAlleleTotalDepth[i] / (refTotalDepth + altAlleleTotalDepth[i]); for (int j = 0; j < base.length; j++) { observed[j] = pAlleleCount[j][altAllele2PAlleleIndex[i]]; expected[j] = r; } segregationP[i] = ct.chiSquareTest(expected, observed); if (segregationP[i] > this.segregationPValueThresh) cnt++; } if (cnt == altAllele.length) return null; //===========================Filter4========================================================= int nonMissingCnt = 0; int[] refAndAllelePresence = new int[altAllele.length + 1]; for (int i = 0; i < base.length; i++) { if (refDepth[i] != 0) { nonMissingCnt++; refAndAllelePresence[0]++; } else { for (int j = 0; j < altAllele.length; j++) { if (pAlleleCount[i][altAllele2PAlleleIndex[j]] != 0) { nonMissingCnt++; break; } } } for (int j = 0; j < altAllele.length; j++) { if (pAlleleCount[i][altAllele2PAlleleIndex[j]] != 0) { refAndAllelePresence[j + 1]++; } } } StringBuilder sb = new StringBuilder(); sb.append(currentChr).append("\t").append(position).append("\t").append((char) refBase).append("\t"); for (int i = 0; i < altAllele.length; i++) sb.append(String.valueOf((char) altAllele[altAlleleDepthDesendingIndex[i]])).append(","); sb.deleteCharAt(sb.length() - 1); sb.append("\t").append("DP=").append(totalDepth).append(";AD=").append(refTotalDepth); for (int i = 0; i < altAllele.length; i++) sb.append(",").append(altAlleleTotalDepth[altAlleleDepthDesendingIndex[i]]); sb.append(";NZ=").append(nonMissingCnt).append(";AP="); for (int i = 0; i < refAndAllelePresence.length; i++) sb.append(refAndAllelePresence[i]).append(","); sb.deleteCharAt(sb.length() - 1); sb.append(";PV="); for (int i = 0; i < altAllele.length; i++) sb.append(segregationP[i]).append(","); sb.deleteCharAt(sb.length() - 1); sb.append(";DI="); for (int i = 0; i < indelTypeCount.length; i++) sb.append(indelTypeCount[i]).append(","); sb.deleteCharAt(sb.length() - 1); sb.append("\t").append("GT:AD:PL"); for (int i = 0; i < base.length; i++) { int[] dep = new int[altAllele.length + 1]; dep[0] = refDepth[i]; for (int j = 0; j < altAllele.length; j++) { dep[j + 1] = pAlleleCount[i][altAllele2PAlleleIndex[altAlleleDepthDesendingIndex[j]]]; } sb.append("\t").append(this.getGenotype(dep)); } return sb.toString(); }
From source file:net.sourceforge.checkstyle4ada.TreeWalker4Ada.java
/** * Register a check for a given configuration. * @param aCheck the check to register// ww w .j a v a2 s . c o m * @throws CheckstyleException if an error occurs */ private void registerCheck(Check aCheck) throws CheckstyleException { int[] tokens = new int[] {}; //safety initialization final Set checkTokens = aCheck.getTokenNames(); if (!checkTokens.isEmpty()) { tokens = aCheck.getRequiredTokens(); //register configured tokens final int acceptableTokens[] = aCheck.getAcceptableTokens(); Arrays.sort(acceptableTokens); final Iterator it = checkTokens.iterator(); while (it.hasNext()) { final String token = (String) it.next(); try { final int tokenId = TokenTypes4Ada.getTokenId(token); if (Arrays.binarySearch(acceptableTokens, tokenId) >= 0) { registerCheck(token, aCheck); } // TODO: else log warning } catch (IllegalArgumentException ex) { throw new CheckstyleException("illegal token \"" + token + "\" in check " + aCheck, ex); } } } else { tokens = aCheck.getDefaultTokens(); } for (int i = 0; i < tokens.length; i++) { registerCheck(tokens[i], aCheck); } mAllChecks.add(aCheck); }
From source file:ca.phon.app.project.ProjectWindow.java
private void init() { /* Layout */// w w w . j a va 2 s .c o m setLayout(new BorderLayout()); final ProjectDataTransferHandler transferHandler = new ProjectDataTransferHandler(this); /* Create components */ newCorpusButton = createNewCorpusButton(); createCorpusButton = createCorpusButton(); corpusList = new JList<String>(); corpusModel = new CorpusListModel(getProject()); corpusList.setModel(corpusModel); corpusList.setCellRenderer(new CorpusListCellRenderer()); corpusList.setVisibleRowCount(20); corpusList.addListSelectionListener(e -> { if (getSelectedCorpus() != null) { String corpus = getSelectedCorpus(); sessionModel.setCorpus(corpus); sessionList.clearSelection(); corpusDetails.setCorpus(corpus); if (getProject().getCorpusSessions(corpus).size() == 0) { onSwapNewAndCreateSession(newSessionButton); } else { onSwapNewAndCreateSession(createSessionButton); } } }); corpusList.addMouseListener(new MouseInputAdapter() { @Override public void mousePressed(MouseEvent e) { doPopup(e); } @Override public void mouseReleased(MouseEvent e) { doPopup(e); } public void doPopup(MouseEvent e) { if (e.isPopupTrigger()) { int clickedIdx = corpusList.locationToIndex(e.getPoint()); if (clickedIdx >= 0 && Arrays.binarySearch(corpusList.getSelectedIndices(), clickedIdx) < 0) { corpusList.setSelectedIndex(clickedIdx); } showCorpusListContextMenu(e.getPoint()); } } }); final DragSource corpusDragSource = new DragSource(); corpusDragSource.createDefaultDragGestureRecognizer(corpusList, DnDConstants.ACTION_COPY, (event) -> { final List<ProjectPath> paths = new ArrayList<>(); for (String corpus : getSelectedCorpora()) { final ProjectPath corpusPath = new ProjectPath(getProject(), corpus, null); paths.add(corpusPath); } final ProjectPathTransferable transferable = new ProjectPathTransferable(paths); event.startDrag(DragSource.DefaultCopyDrop, transferable); }); corpusList.setDragEnabled(true); corpusList.setTransferHandler(transferHandler); corpusDetails = new CorpusDetailsPane(getProject()); corpusDetails.setWrapStyleWord(true); corpusDetails.setRows(6); corpusDetails.setLineWrap(true); corpusDetails.setBackground(Color.white); corpusDetails.setOpaque(true); JScrollPane corpusDetailsScroller = new JScrollPane(corpusDetails); sessionList = new JList<String>(); newSessionButton = createNewSessionButton(); createSessionButton = createSessionButton(); sessionModel = new SessionListModel(getProject()); sessionList.setModel(sessionModel); sessionList.setCellRenderer(new SessionListCellRenderer()); sessionList.setVisibleRowCount(20); sessionList.addListSelectionListener(e -> { if (sessionList.getSelectedValue() != null && !e.getValueIsAdjusting()) { String corpus = getSelectedCorpus(); String session = getSelectedSessionName(); sessionDetails.setSession(corpus, session); } }); sessionList.addMouseListener(new MouseInputAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == 1) { // get the clicked item int clickedItem = sessionList.locationToIndex(e.getPoint()); if (sessionList.getModel().getElementAt(clickedItem) == null) return; final String session = sessionList.getModel().getElementAt(clickedItem).toString(); final String corpus = ((SessionListModel) sessionList.getModel()).getCorpus(); msgPanel.reset(); msgPanel.setMessageLabel("Opening '" + corpus + "." + session + "'"); msgPanel.setIndeterminate(true); msgPanel.repaint(); SwingUtilities.invokeLater(() -> { final ActionEvent ae = new ActionEvent(sessionList, -1, "openSession"); (new OpenSessionAction(ProjectWindow.this, corpus, session)).actionPerformed(ae); msgPanel.setIndeterminate(false); }); } } @Override public void mousePressed(MouseEvent e) { doPopup(e); } @Override public void mouseReleased(MouseEvent e) { doPopup(e); } public void doPopup(MouseEvent e) { if (e.isPopupTrigger()) { int clickedIdx = sessionList.locationToIndex(e.getPoint()); if (clickedIdx >= 0 && Arrays.binarySearch(sessionList.getSelectedIndices(), clickedIdx) < 0) { sessionList.setSelectedIndex(clickedIdx); } showSessionListContextMenu(e.getPoint()); } } }); sessionList.setDragEnabled(true); sessionList.setTransferHandler(transferHandler); final DragSource sessionDragSource = new DragSource(); sessionDragSource.createDefaultDragGestureRecognizer(sessionList, DnDConstants.ACTION_COPY, (event) -> { final List<ProjectPath> paths = new ArrayList<>(); final String corpus = getSelectedCorpus(); if (corpus == null) return; for (String session : getSelectedSessionNames()) { final ProjectPath sessionPath = new ProjectPath(getProject(), corpus, session); paths.add(sessionPath); } final ProjectPathTransferable transferable = new ProjectPathTransferable(paths); event.startDrag(DragSource.DefaultCopyDrop, transferable); }); sessionDetails = new SessionDetailsPane(getProject()); sessionDetails.setLineWrap(true); sessionDetails.setRows(6); sessionDetails.setWrapStyleWord(true); sessionDetails.setBackground(Color.white); sessionDetails.setOpaque(true); JScrollPane sessionDetailsScroller = new JScrollPane(sessionDetails); JScrollPane corpusScroller = new JScrollPane(corpusList); JScrollPane sessionScroller = new JScrollPane(sessionList); blindModeBox = new JCheckBox("Blind transcription"); blindModeBox.setSelected(false); msgPanel = new StatusPanel(); corpusPanel = new JPanel(new BorderLayout()); corpusPanel.add(newCorpusButton, BorderLayout.NORTH); corpusPanel.add(corpusScroller, BorderLayout.CENTER); corpusPanel.add(corpusDetailsScroller, BorderLayout.SOUTH); sessionPanel = new JPanel(new BorderLayout()); sessionPanel.add(newSessionButton, BorderLayout.NORTH); sessionPanel.add(sessionScroller, BorderLayout.CENTER); sessionPanel.add(sessionDetailsScroller, BorderLayout.SOUTH); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(corpusPanel); splitPane.setRightComponent(sessionPanel); splitPane.setResizeWeight(0.5); // invoke later SwingUtilities.invokeLater(() -> { splitPane.setDividerLocation(0.5); }); // the frame layout String projectName = null; projectName = getProject().getName(); DialogHeader header = new DialogHeader(projectName, StringUtils.abbreviate(projectLoadPath, 80)); add(header, BorderLayout.NORTH); CellConstraints cc = new CellConstraints(); final JPanel topPanel = new JPanel(new FormLayout("pref, fill:pref:grow, right:pref", "pref")); topPanel.add(msgPanel, cc.xy(1, 1)); topPanel.add(blindModeBox, cc.xy(3, 1)); add(splitPane, BorderLayout.CENTER); add(topPanel, BorderLayout.SOUTH); // if no corpora are currently available, 'prompt' the user to create a new one if (getProject().getCorpora().size() == 0) { SwingUtilities.invokeLater(() -> { onSwapNewAndCreateCorpus(newCorpusButton); }); } else { SwingUtilities.invokeLater(() -> { corpusList.setSelectedIndex(0); }); } }
From source file:eu.eidas.node.utils.EidasNodeErrorUtil.java
private static String getSamlSubStatusCode(final String errorCode) { for (int i = 0; i < EIDAS_SUB_STATUS_CODES.length; i++) { if (EIDAS_ERRORS_CODES_WITH_SAML_GENERATION[i] != null && EIDAS_ERRORS_CODES_WITH_SAML_GENERATION[i].length > 0 && Arrays.binarySearch(EIDAS_ERRORS_CODES_WITH_SAML_GENERATION[i], errorCode) >= 0) { return EIDAS_SUB_STATUS_CODES[i].toString(); }//w w w .ja v a 2 s . co m } return null; }
From source file:net.maizegenetics.analysis.imputation.FILLINImputationAccuracy.java
private boolean matchChromosomes() { Chromosome[] unimpChr = this.unimp.chromosomes(); Chromosome[] keyChr = this.maskKey.chromosomes(); ArrayList<Integer> keepSites = new ArrayList<>(); for (Chromosome chr : unimpChr) { //if any of the chromosomes in input do not exist in key, return false (which then masks proportion) if (Arrays.binarySearch(keyChr, chr) < 0) return false; }// www . j a v a 2 s . c o m for (Chromosome chr : keyChr) { //keep sites on key that are on matching chromosomes if (Arrays.binarySearch(unimpChr, chr) > -1) { int[] startEnd = this.maskKey.firstLastSiteOfChromosome(chr); for (int site = startEnd[0]; site <= startEnd[1]; site++) { keepSites.add(site); } } } FilterGenotypeTable filter = FilterGenotypeTable.getInstance(this.maskKey, ArrayUtils.toPrimitive(keepSites.toArray(new Integer[keepSites.size()]))); this.maskKey = filter;//GenotypeTableBuilder.getGenotypeCopyInstance(filter);//Change this back when GenotypeCopyInstance fixed if (verboseOutput) System.out.println(this.maskKey.numberOfSites() + " sites retained after chromsome filter"); return true; }
From source file:net.dorokhov.pony.web.server.common.StreamingViewRenderer.java
/** * Returns true if the given match header matches the given value. * @param matchHeader The match header./*w w w. j a v a2 s. c o m*/ * @param toMatch The value to be matched. * @return True if the given match header matches the given value. */ private static boolean matches(String matchHeader, String toMatch) { String[] matchValues = matchHeader.split("\\s*,\\s*"); Arrays.sort(matchValues); return Arrays.binarySearch(matchValues, toMatch) > -1 || Arrays.binarySearch(matchValues, "*") > -1; }
From source file:org.apache.sysml.runtime.transform.BinAgent.java
@Override public MatrixBlock apply(FrameBlock in, MatrixBlock out) { for (int j = 0; j < _colList.length; j++) { int colID = _colList[j]; for (int i = 0; i < in.getNumRows(); i++) { double inVal = UtilFunctions.objectToDouble(in.getSchema()[colID - 1], in.get(i, colID - 1)); int ix = Arrays.binarySearch(_binMaxs[j], inVal); int binID = ((ix < 0) ? Math.abs(ix + 1) : ix) + 1; out.quickSetValue(i, colID - 1, binID); }/*w ww .j a v a 2 s .co m*/ } return out; }