Example usage for java.util Arrays binarySearch

List of usage examples for java.util Arrays binarySearch

Introduction

In this page you can find the example usage for java.util Arrays binarySearch.

Prototype

public static int binarySearch(Object[] a, Object key) 

Source Link

Document

Searches the specified array for the specified object using the binary search algorithm.

Usage

From source file:fastcall.FastCallSNP.java

private void callSNPByChromosome(int currentChr, String referenceFileS, String vcfDirS) {
    int chrIndex = Arrays.binarySearch(chroms, currentChr);
    String chrSeq = genomeFa.getSeq(chrIndex).toUpperCase();
    int regionStart = 1;
    int regionEnd = chrSeq.length();
    this.performPileup(currentChr, regionStart, regionEnd, referenceFileS);
    String outfileS = "chr" + FStringUtils.getNDigitNumber(3, currentChr) + ".VCF.txt";
    outfileS = new File(vcfDirS, outfileS).getAbsolutePath();
    int[][] binBound = this.creatBins(currentChr, binSize, regionStart, regionEnd);
    try {//from w  ww  . ja  v  a  2 s. c  o m
        HashMap<String, BufferedReader> bamPathPileupReaderMap = this.getBamPathPileupReaderMap();
        ConcurrentHashMap<BufferedReader, List<String>> readerRemainderMap = this
                .getReaderRemainderMap(bamPathPileupReaderMap);
        BufferedWriter bw = IoUtils.getTextWriter(outfileS);
        bw.write(this.getAnnotation(referenceFileS));
        bw.write(this.getVCFHeader());
        bw.newLine();
        for (int i = 0; i < binBound.length; i++) {
            long startTimePoint = System.nanoTime();
            int binStart = binBound[i][0];
            int binEnd = binBound[i][1];
            ConcurrentHashMap<String, List<List<String>>> bamPileupResultMap = this.getBamPileupResultMap(
                    currentChr, binStart, binEnd, bamPathPileupReaderMap, readerRemainderMap);
            StringBuilder[][] baseSb = this.getPopulateBaseBuilder(binStart, binEnd);
            int[][] depth = this.getPopulatedDepthArray(binStart, binEnd);
            this.fillDepthAndBase(bamPileupResultMap, baseSb, depth, binStart);
            String[][] base = this.getBaseMatrix(baseSb);
            ArrayList<Integer> positionList = this.getPositionList(binStart, binEnd);
            ConcurrentHashMap<Integer, String> posVCFMap = new ConcurrentHashMap(
                    (int) ((binEnd - binStart + 1) * 1.5));
            this.calculateVCF(posVCFMap, positionList, currentChr, binStart, chrSeq, depth, base);
            for (int j = 0; j < positionList.size(); j++) {
                String vcfStr = posVCFMap.get(positionList.get(j));
                if (vcfStr == null)
                    continue;
                bw.write(vcfStr);
                bw.newLine();
            }
            StringBuilder sb = new StringBuilder();
            sb.append("Bin from ").append(binStart).append(" to ").append(binEnd).append(" is finished. Took ")
                    .append(Benchmark.getTimeSpanSeconds(startTimePoint)).append(" seconds. Memory used: ")
                    .append(Benchmark.getUsedMemoryGb()).append(" Gb");
            System.out.println(sb.toString());
        }
        bw.flush();
        bw.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println(
            "Chromosome " + String.valueOf(currentChr) + " is finished. File written to " + outfileS + "\n");
}

From source file:com.indeed.lsmtree.core.TestImmutableBTreeIndex.java

public void testRandom() throws Exception {
    final int[] ints = createTree();
    final ImmutableBTreeIndex.Reader<Integer, Long> reader = new ImmutableBTreeIndex.Reader(tmpDir,
            new IntSerializer(), new LongSerializer(), false);
    final int max = ints[ints.length - 1];
    final AtomicInteger done = new AtomicInteger(8);
    for (int i = 0; i < 8; i++) {
        final int index = i;
        new Thread(new Runnable() {
            @Override/*from  w w w .  j  ava2 s  .c o  m*/
            public void run() {
                try {
                    final Random r = new Random(index);
                    for (int i = 0; i < treeSize; i++) {
                        int rand = r.nextInt(max + 1);
                        int insertionindex = Arrays.binarySearch(ints, rand);
                        final Iterator<Generation.Entry<Integer, Long>> iterator = reader.iterator(rand, true);
                        try {
                            assertTrue(iterator.hasNext());
                        } catch (Throwable t) {
                            System.err.println("rand: " + rand);
                            throw Throwables.propagate(t);
                        }
                        Generation.Entry<Integer, Long> entry = iterator.next();
                        assertTrue("entry: " + entry + " rand: " + rand, entry.getKey() >= rand);
                        assertTrue(entry.getKey().longValue() == entry.getValue());
                        if (insertionindex >= 0) {
                            assertTrue(rand == ints[insertionindex]);
                            assertTrue(entry.getKey() == rand);
                            Generation.Entry<Integer, Long> result = reader.get(rand);
                            assertTrue(result.getValue() == rand);
                        } else {
                            if (insertionindex != -1)
                                assertTrue(ints[(~insertionindex) - 1] < rand);
                            assertTrue(
                                    "insertionindex: " + insertionindex + " entry: " + entry
                                            + " ints[!insertionindex]" + ints[~insertionindex],
                                    ints[~insertionindex] == entry.getKey());
                            Generation.Entry<Integer, Long> result = reader.get(rand);
                            assertTrue(result == null);
                        }
                    }
                } finally {
                    done.decrementAndGet();
                }
            }
        }).start();
    }
    while (done.get() > 0) {
        Thread.yield();
    }
    reader.close();
}

From source file:jsat.distributions.empirical.KernelDensityEstimatorButla.java

public KernelDensityEstimatorButla(Vec dataPoints, KDEFormelVariant formelVariant, double bandwidth,
        double minSearchStep, double minSearchAccuracy) {

    // TODO check

    this.dataPoints = dataPoints.sortedCopy();
    this.X = dataPoints.arrayCopy();
    this.minSearchStep = minSearchStep;
    this.minSearchAccuracy = minSearchAccuracy;
    this.kdeFormelVariant = formelVariant;

    if (Precision.equals(bandwidth, 0)) {
        bandwidth = MyKernelDensityEstimator.BandwithGuassEstimate(dataPoints);
        this.minSearchStep = bandwidth / 4.0;
    }// w  w w . ja  v a2  s.co  m

    if (this.minSearchStep < 0.0001) {
        this.minSearchStep = 0.25d;
    }

    if (formelVariant == KDEFormelVariant.OriginalKDE) {

        final MyKernelDensityEstimator kernelDensity = new MyKernelDensityEstimator(dataPoints,
                GaussKF.getInstance(), bandwidth);
        kernelPdfFunction = ContinuousDistribution.getFunctionPDF(kernelDensity);
        kernelDerivationFunction = ContinuousDistribution.getFunctionPDF(
                new MyKernelDensityEstimator(dataPoints, GaussKFDerivation.getInstance(), bandwidth));

        startX = kernelDensity.min() + bandwidth;
        endX = kernelDensity.max() - bandwidth;

    } else if (formelVariant == KDEFormelVariant.OriginalButlaVariableBandwidth) {

        kernelPdfFunction = new Function() {

            private static final long serialVersionUID = 337703545623146489L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = Math.pow(X[X.length - 1] * 0.05, 2);
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = dataPoints.get(i);
                    if (!Precision.equals(ti, 0)) {
                        sum += Math.exp(-Math.pow(t - ti, 2) / (2 * 0.05 * ti))
                                / (Math.sqrt(2.0 * Math.PI) * 0.05 * ti);
                    }
                }

                return sum / dataPoints.length();
            }
        };

        kernelDerivationFunction = new Function() {
            private static final long serialVersionUID = 1896912471233540595L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = Math.pow(X[X.length - 1] * 0.05, 2);
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = dataPoints.get(i);
                    if (!Precision.equals(ti, 0)) {
                        sum += (-79.7885 * Math.exp(-10 * Math.pow(t - ti, 2) / ti)
                                * (Math.pow(ti, 2) + 0.1 * ti - Math.pow(t, 2))) / Math.pow(ti, 3);
                    }
                }

                return sum / dataPoints.length();
            }
        };

        startX = Math.max(dataPoints.get(0), 1.0);
        endX = dataPoints.get(dataPoints.length() - 1);

    } else if (formelVariant == KDEFormelVariant.ButlaBandwidthNotSquared) {

        kernelPdfFunction = new Function() {
            private static final long serialVersionUID = -8200289641116502672L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = Math.pow(X[X.length - 1] * 0.05, 2);
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = X[i];
                    if (!Precision.equals(ti, 0)) {
                        sum += Math.exp(-Math.pow(t - ti, 2) / (2 * Math.pow(0.05 * ti, 2)))
                                / (Math.sqrt(2.0 * Math.PI) * 0.05 * ti);
                    }
                }

                return sum / dataPoints.length();
            }
        };

        kernelDerivationFunction = new Function() {
            private static final long serialVersionUID = -2561020473687438986L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = Math.pow(X[X.length - 1] * 0.05, 2);
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = dataPoints.get(i);
                    if (!Precision.equals(ti, 0)) {
                        sum += ((-7.97885 * Math.pow(ti, 2) - 3191.54 * ti * t + 3191.54 * Math.pow(t, 2))
                                * Math.exp(-200 * Math.pow(t - ti, 2) / Math.pow(ti, 2))) / Math.pow(ti, 4);
                    }
                }

                return sum / dataPoints.length();
            }
        };

        startX = Math.max(dataPoints.get(0), 1.0);
        endX = dataPoints.get(dataPoints.length() - 1);

    } else if (formelVariant == KDEFormelVariant.ButlaBandwidthSquared) {

        kernelPdfFunction = new Function() {
            private static final long serialVersionUID = 6749547413109881687L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = X[X.length - 1] * 0.05;
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = dataPoints.get(i);
                    if (!Precision.equals(ti, 0)) {
                        sum += Math.exp(-Math.pow(t - ti, 2) / (2 * 0.05 * ti))
                                / (Math.sqrt(2.0 * Math.PI * 0.05 * ti));
                    }
                }

                return sum / dataPoints.length();
            }
        };

        kernelDerivationFunction = new Function() {
            private static final long serialVersionUID = 3612595828189571262L;

            @Override
            public double f(Vec x) {
                return f(new double[] { x.get(0) });
            }

            @Override
            public double f(double... x) {

                final double t = x[0];
                double sum = 0.0d;

                final double maxH = X[X.length - 1] * 0.05;
                int from = Arrays.binarySearch(X, t - maxH * 13);
                int to = Arrays.binarySearch(X, t + maxH * 13);
                from = from < 0 ? -from - 1 : from;
                to = to < 0 ? -to - 1 : to;

                for (int i = Math.max(0, from); i < Math.min(X.length, to + 1); i++) {
                    final double ti = dataPoints.get(i);
                    if (!Precision.equals(ti, 0)) {
                        sum += (Math.exp(-10 * Math.pow(t - ti, 2) / ti)
                                * (-17.8412 * Math.pow(ti, 2) - 0.892062 * ti + 17.8412 * Math.pow(t, 2)))
                                / Math.sqrt(Math.pow(ti, 5));
                    }
                }

                return sum / dataPoints.length();
            }
        };

        startX = Math.max(dataPoints.get(0), 1.0);
        endX = dataPoints.get(dataPoints.length() - 1);
    }
}

From source file:arena.action.AttributesMap.java

private Object getFromRequest(String key) {
    // First, prefer attribute values if available because of overwrites
    Object att = request.getAttribute(key);
    if (att != null) {
        log.trace("Getting param " + key + " from request attributes");
        return att;
    }/*from   w  ww. j  a v a2 s.  co m*/

    // Second, check reserved framework words
    int posOfReserved = Arrays.binarySearch(ROUTER_ATTS, key.toString());
    if (posOfReserved >= 0) {
        log.trace("Getting param " + key + " from fixed router parameters");
        // get based on hidden
        if (key.equals(RouterConstants.USER_AGENT_PARAM)) {
            String agent = request.getHeader("User-Agent");
            if (agent == null) {
                agent = "(not supplied)";
            }
            return agent;
        } else if (key.equals(RouterConstants.CLIENT_HOSTNAME_PARAM)) {
            return request.getRemoteHost();
        } else if (key.equals(RouterConstants.CLIENT_IP_ADDR_PARAM)) {
            return request.getRemoteAddr();
        } else if (key.equals(RouterConstants.FULL_REQUEST_URL_PARAM)) {
            String qs = request.getQueryString();
            StringBuffer fullRequestURL = request.getRequestURL();
            if ((qs != null) && !qs.equals("")) {
                fullRequestURL.append('?').append(qs);
            }
            return fullRequestURL.toString();
        } else if (key.equals(RouterConstants.QUERY_STRING_PARAM)) {
            String qs = request.getQueryString();
            return (qs == null ? "" : qs);
        } else if (key.equals(RouterConstants.METHOD_PARAM)) {
            return request.getMethod();
        }
    }

    // Third, check url params
    String paramValues[] = request.getParameterValues(key);
    if (paramValues != null) {
        log.trace("Getting param " + key + " from request parameters: length=" + paramValues.length);
        if (paramValues.length == 1) {
            return paramValues[0];
        } else {
            return paramValues;
        }
    }

    // Fourth check multipart files if required
    if (request instanceof MultipartRequest) {
        MultipartFile mf = ((MultipartRequest) request).getFile(key);
        if (mf != null) {
            log.trace("Getting param " + key + " from multipart file upload");
            return mf;
        }
    }
    return null;
}

From source file:net.maritimecloud.identityregistry.keycloak.spi.eventprovider.McEventListenerProvider.java

public void onEvent(Event event) {
    // We only worry about IDENTITY_PROVIDER_LOGIN events.
    if (event.getType() != EventType.LOGIN && event.getType() != EventType.IDENTITY_PROVIDER_LOGIN) {
        return;//from w  ww .j  a va 2 s .  c  o m
    }
    StringBuilder sb = new StringBuilder();

    sb.append("type=");
    sb.append(event.getType());
    sb.append(", realmId=");
    sb.append(event.getRealmId());
    sb.append(", clientId=");
    sb.append(event.getClientId());
    sb.append(", userId=");
    sb.append(event.getUserId());
    sb.append(", ipAddress=");
    sb.append(event.getIpAddress());

    if (event.getError() != null) {
        sb.append(", error=");
        sb.append(event.getError());
    }
    String identityProvider = null;
    if (event.getDetails() != null) {
        for (Map.Entry<String, String> e : event.getDetails().entrySet()) {
            if ("identity_provider".equals(e.getKey())) {
                identityProvider = e.getValue();
            }
            sb.append(", ");
            sb.append(e.getKey());
            if (e.getValue() == null || e.getValue().indexOf(' ') == -1) {
                sb.append("=");
                sb.append(e.getValue());
            } else {
                sb.append("='");
                sb.append(e.getValue());
                sb.append("'");
            }
        }
    }
    log.info("event info: " + sb.toString());

    // Only users coming from an identity provider is sync'ed.
    if (identityProvider == null) {
        log.info("no identity provider found for this user, so sync skipped!");
        return;
    }

    // we skip certain identity providers
    if (Arrays.binarySearch(idpNotToSync, identityProvider) < 0) {
        log.info("this identity provider is setup not to be sync'ed, so sync skipped!");
        return;
    }

    if (event.getRealmId() != null && event.getUserId() != null) {
        RealmModel realm = session.realms().getRealm(event.getRealmId());
        UserModel user = session.users().getUserById(event.getUserId(), realm);
        User mcUser = new User();
        mcUser.setEmail(user.getEmail());
        mcUser.setFirstName(user.getFirstName());
        mcUser.setLastName(user.getLastName());
        String orgShortName = null;
        if (event.getType() == EventType.IDENTITY_PROVIDER_LOGIN) {
            // The username should be in the form "<org-shortname>.<user-unique-org-id>"
            String[] splitName = user.getUsername().split(".", 1);
            if (splitName.length == 2) {
                orgShortName = splitName[0].toUpperCase();
                mcUser.setUserOrgId(splitName[1]);
            } else {
                return;
            }
        } else {
            // TODO: This is for testing only!! Remove again!! 
            List<String> orgList = user.getAttributes().get("org");
            if (orgList != null && orgList.size() > 0) {
                orgShortName = orgList.get(0);
            }
            mcUser.setUserOrgId(user.getUsername());
        }
        if (orgShortName == null || orgShortName.isEmpty()) {
            log.warn("No org shortname found, skipping user sync");
            return;
        }
        List<String> permissionsList = user.getAttributes().get("permissions");
        if (permissionsList != null && permissionsList.size() > 0) {
            mcUser.setPermissions(String.join(", ", permissionsList));
        }

        List<String> mrnList = user.getAttributes().get("mrn");
        if (mrnList != null && mrnList.size() > 0) {
            mcUser.setMrn(String.join(", ", mrnList));
        }

        if (user != null && user.getAttributes() != null) {
            for (Map.Entry<String, List<String>> e : user.getAttributes().entrySet()) {
                log.info("user attr: " + e.getKey() + ", value: " + String.join(", ", e.getValue()));
            }
        }
        sendUserUpdate(mcUser, orgShortName);
    }
}

From source file:CharMap.java

/**
 * Returns {@code true} if this map contains a mapping for the specified key.
 *///from   w  w  w .j a v  a2  s. c  o  m
public boolean containsKey(Object key) {
    char k = checkKey(key);
    int index = Arrays.binarySearch(keyIndices, k);
    return index >= 0;
}

From source file:de.fhg.igd.iva.explorer.main.CompareViewPanel.java

protected void updateSelection() {
    KnownColormap colormap = (KnownColormap) mapsCombo.getSelectedItem();

    cmView.setColormap(colormap);/*from   ww  w  .java2  s.  com*/

    statsBars.removeAll();

    Map<ColormapQuality, Double> row = table.row(colormap);

    Insets insets = new Insets(0, 0, 0, 0);
    Insets insets5 = new Insets(0, 5, 0, 0);

    GridBagConstraints gbcName = new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets, 0, 0);
    GridBagConstraints gbcQual = new GridBagConstraints(1, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcRank = new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatL = new GridBagConstraints(3, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStatR = new GridBagConstraints(4, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_END,
            GridBagConstraints.NONE, insets5, 0, 0);
    GridBagConstraints gbcStat = new GridBagConstraints(3, 0, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, insets5, 0, 0);

    statsBars.add(new JLabel("Name"), gbcName);
    statsBars.add(new JLabel("Score"), gbcQual);
    statsBars.add(new JLabel("Rank"), gbcRank);

    // maybe use a best/worst arrow down marker instead? unicode: \u2193
    statsBars.add(new JLabel("\u2190Worse"), gbcStatL);
    statsBars.add(new JLabel("Better\u2192"), gbcStatR);

    GridBagConstraints gbcSpace = new GridBagConstraints(0, 1, 5, 1, 1.0, 1.0, GridBagConstraints.LINE_START,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 0), 0, 0);
    JSeparator spacing = new JSeparator(SwingConstants.HORIZONTAL);
    statsBars.add(spacing, gbcSpace);

    int count = table.rowKeySet().size();

    int rowIdx = 2;
    for (ColormapQuality metric : row.keySet()) {
        double quality = row.get(metric);
        DescriptiveStatistics stats = computeStats(metric);
        int index = Arrays.binarySearch(stats.getSortedValues(), quality);

        int rank = metric.moreIsBetter() ? count - index : index + 1;

        gbcName = (GridBagConstraints) gbcName.clone();
        gbcQual = (GridBagConstraints) gbcQual.clone();
        gbcRank = (GridBagConstraints) gbcRank.clone();
        gbcStat = (GridBagConstraints) gbcStat.clone();

        gbcName.gridy = rowIdx;
        gbcQual.gridy = rowIdx;
        gbcRank.gridy = rowIdx;
        gbcStat.gridy = rowIdx;

        statsBars.add(new JLabel(metric.getName()), gbcName);
        statsBars.add(new JLabel(String.format("%.2f", quality)), gbcQual);
        statsBars.add(new JLabel(Integer.toString(rank)), gbcRank);
        statsBars.add(new JStatBar(metric, stats, quality), gbcStat);
        rowIdx++;
    }

    // I find it strange that both revalidate and repaint must be explicitly called here
    revalidate();
    repaint();
}

From source file:com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck.java

/**
 * @param lineNo a line number/*www.  j  av a  2  s  .com*/
 * @return if {@code lineNo} is one of the repeat header lines.
 */
private boolean isMultiLine(int lineNo) {
    return Arrays.binarySearch(multiLines, lineNo + 1) >= 0;
}

From source file:org.apache.sqoop.manager.cubrid.CubridAuthTest.java

/**
 * Connect to a db and ensure that password-based
 *  authentication succeeds.//from  ww w.  j a  v a  2 s  .  c  o m
 */
@Test
public void testAuthAccess() throws IOException {
    SqoopOptions options = new SqoopOptions(conf);
    options.setConnectString(CubridTestUtils.getConnectString());
    options.setUsername(CubridTestUtils.getCurrentUser());
    options.setPassword(CubridTestUtils.getPassword());

    ConnManager mgr = new CubridManager(options);
    String[] tables = mgr.listTables();
    Arrays.sort(tables);
    assertTrue(TABLE_NAME + " is not found!", Arrays.binarySearch(tables, TABLE_NAME) >= 0);
}

From source file:edu.umn.cs.spatialHadoop.indexing.BTRPartitioner.java

@Override
public void overlapPartitions(Shape shape, ResultCollector<Integer> matcher) {
    if (shape == null)
        return;//from   w ww.  j a v a 2  s  .  c o  m
    Rectangle shapeMBR = shape.getMBR();
    if (shapeMBR == null)
        return;
    // Replicate to all overlapping partitions
    // Find first and last matching columns
    int col1 = Arrays.binarySearch(xSplits, shapeMBR.x1);
    if (col1 < 0)
        col1 = -col1 - 1; // Adjust the position if value not found
    int col2 = Arrays.binarySearch(xSplits, shapeMBR.x2);
    if (col2 < 0)
        col2 = -col2 - 1; // Adjust the position if value not found

    for (int col = col1; col <= col2; col++) {
        // For each column, find all matching rows
        int cell1 = Arrays.binarySearch(ySplits, col * rows, (col + 1) * rows, shapeMBR.y1);
        if (cell1 < 0)
            cell1 = -cell1 - 1;
        int cell2 = Arrays.binarySearch(ySplits, col * rows, (col + 1) * rows, shapeMBR.y2);
        if (cell2 < 0)
            cell2 = -cell2 - 1;

        for (int cell = cell1; cell <= cell2; cell++)
            matcher.collect(cell);
    }
}