Example usage for java.util TreeMap entrySet

List of usage examples for java.util TreeMap entrySet

Introduction

In this page you can find the example usage for java.util TreeMap entrySet.

Prototype

EntrySet entrySet

To view the source code for java.util TreeMap entrySet.

Click Source Link

Document

Fields initialized to contain an instance of the entry set view the first time this view is requested.

Usage

From source file:cfappserver.Bot.java

public static void getAbsences(HttpClient client, ClssPkg cp, List<NameValuePair> urlParameters) {
    String numabs = "";
    String month = "";
    String url = "https://home-access.cfisd.net/HomeAccess/Content/Attendance/MonthlyView.aspx";
    BasicNameValuePair bnvp = null;/*from  www.  ja v a2 s  .  c  om*/
    BasicNameValuePair bnvp2 = null;
    BasicNameValuePair bnvp3 = null;
    BasicNameValuePair bnvp4 = null;
    TreeMap<String, Integer> absen = new TreeMap<String, Integer>();
    while (!month.equals("January") && !month.equals("August")) {
        try {
            HttpPost post = new HttpPost(url);
            urlParameters = new ArrayList<NameValuePair>();
            if (bnvp != null && bnvp2 != null && bnvp3 != null && bnvp4 != null) {
                urlParameters.add(bnvp);
                urlParameters.add(bnvp2);
                urlParameters.add(bnvp3);
                urlParameters.add(bnvp4);
            }
            post.setEntity(new UrlEncodedFormEntity(urlParameters));
            HttpResponse response = client.execute(post);

            BufferedReader rd = new BufferedReader(
                    new InputStreamReader(response.getEntity().getContent()));

            StringBuffer result = new StringBuffer();
            String line = "";
            while ((line = rd.readLine()) != null) {
                String total = "";
                if (line.contains("Monday")) {
                    total = line.replace("\n", "").replace("\r", "");
                    while (!(line = rd.readLine()).equals("</table>")) {
                        total += "-" + line.replace("\n", "").replace("\r", "");
                    }
                    String[] arr = total.split("\"");
                    ArrayList<String> a = new ArrayList<String>();
                    for (int i = 0; i < arr.length; i++) {
                        if (arr[i].contains("td title=")) {
                            String[] arr2 = arr[i + 1].split("-");
                            for (String s : arr2) {
                                if (!s.contains("AM") && !s.contains("PM")) {
                                    a.add(s);
                                }
                            }
                        }
                    }
                    for (int i = 0; i < a.size(); i++) {
                        if (unExcused(a.get(i + 1))) {
                            addToTree(a.get(i), absen);
                        }
                        if (a.get(i + 1).equals("Tardy")) {
                            addToTree("T", absen);
                        }
                        i++;
                    }

                }
                if (line.contains("__EVENTVALIDATION")) {
                    bnvp4 = new BasicNameValuePair("__EVENTVALIDATION", line.split("\"")[7]);
                }
                if (line.contains("__VIEWSTATE")) {
                    bnvp3 = new BasicNameValuePair("__VIEWSTATE", line.split("\"")[7]);
                }
                if (line.contains("Go to the previous month")) {
                    String[] arr = line.split("'");
                    bnvp = new BasicNameValuePair("__EVENTTARGET", arr[1]);
                    bnvp2 = new BasicNameValuePair("__EVENTARGUMENT", arr[3]);
                    month = getMonth(line);
                }
            }
        } catch (Exception ex) {

        }
    }
    for (Map.Entry<String, Integer> e : absen.entrySet()) {
        numabs += e.getKey() + "-" + e.getValue() + " ";
    }
    cp.addAbsences(numabs);
}

From source file:org.apache.hadoop.hive.metastore.MetaStoreDirectSql.java

/**
 * Merges applies the result of a PM SQL query into a tree of object.
 * Essentially it's an object join. DN could do this for us, but it issues queries
 * separately for every object, which is suboptimal.
 * @param tree The object tree, by ID./*from   ww w. j av  a  2s  .  c  o m*/
 * @param queryText The query text.
 * @param keyIndex Index of the Long column corresponding to the map ID in query result rows.
 * @param func The function that is called on each (object,row) pair with the same id.
 * @return the count of results returned from the query.
 */
private <T> int loopJoinOrderedResult(TreeMap<Long, T> tree, String queryText, int keyIndex, ApplyFunc<T> func)
        throws MetaException {
    boolean doTrace = LOG.isDebugEnabled();
    long start = doTrace ? System.nanoTime() : 0;
    Query query = pm.newQuery("javax.jdo.query.SQL", queryText);
    Object result = query.execute();
    long queryTime = doTrace ? System.nanoTime() : 0;
    if (result == null) {
        query.closeAll();
        return 0;
    }
    List<Object[]> list = ensureList(result);
    Iterator<Object[]> iter = list.iterator();
    Object[] fields = null;
    for (Map.Entry<Long, T> entry : tree.entrySet()) {
        if (fields == null && !iter.hasNext())
            break;
        long id = entry.getKey();
        while (fields != null || iter.hasNext()) {
            if (fields == null) {
                fields = iter.next();
            }
            long nestedId = extractSqlLong(fields[keyIndex]);
            if (nestedId < id)
                throw new MetaException("Found entries for unknown ID " + nestedId);
            if (nestedId > id)
                break; // fields belong to one of the next entries
            func.apply(entry.getValue(), fields);
            fields = null;
        }
        Deadline.checkTimeout();
    }
    int rv = list.size();
    query.closeAll();
    timingTrace(doTrace, queryText, start, queryTime);
    return rv;
}

From source file:com.clust4j.algo.HDBSCANTests.java

@Test
public void testPrimLinkage() {
    KDTree k = new KDTree(iris);
    double[] core_dists = MatUtils.getColumn(k.query(iris.getDataRef(), 5, true, true).getDistances(), 4);

    double[][] X = iris.getData();
    DistanceMetric metric = Distance.EUCLIDEAN;
    double alpha = 1.0;

    double[][] cdist = HDBSCAN.LinkageTreeUtils.minSpanTreeLinkageCore_cdist(X, core_dists, metric, alpha);

    double[][] expected_cdists = new double[][] {
            new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01 },
            new double[] { 3.90000000e+01, 1.70000000e+01, 1.73205081e-01 },
            new double[] { 1.70000000e+01, 2.70000000e+01, 1.73205081e-01 },
            new double[] { 2.70000000e+01, 2.80000000e+01, 1.73205081e-01 },
            new double[] { 2.80000000e+01, 7.00000000e+00, 2.00000000e-01 },
            new double[] { 7.00000000e+00, 4.90000000e+01, 2.23606798e-01 },
            new double[] { 4.90000000e+01, 4.00000000e+00, 2.23606798e-01 },
            new double[] { 4.00000000e+00, 2.60000000e+01, 2.44948974e-01 },
            new double[] { 2.60000000e+01, 4.00000000e+01, 2.44948974e-01 },
            new double[] { 4.00000000e+01, 4.80000000e+01, 2.44948974e-01 },
            new double[] { 4.80000000e+01, 9.00000000e+00, 2.64575131e-01 },
            new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01 },
            new double[] { 1.00000000e+00, 3.00000000e+01, 1.73205081e-01 },
            new double[] { 3.00000000e+01, 3.40000000e+01, 1.73205081e-01 },
            new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01 },
            new double[] { 3.70000000e+01, 1.20000000e+01, 1.73205081e-01 },
            new double[] { 1.20000000e+01, 2.50000000e+01, 2.23606798e-01 },
            new double[] { 2.50000000e+01, 2.90000000e+01, 2.23606798e-01 },
            new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01 },
            new double[] { 4.70000000e+01, 3.00000000e+00, 2.44948974e-01 },
            new double[] { 3.00000000e+00, 1.90000000e+01, 2.64575131e-01 },
            new double[] { 1.90000000e+01, 2.00000000e+00, 2.64575131e-01 },
            new double[] { 2.00000000e+00, 2.10000000e+01, 2.64575131e-01 },
            new double[] { 2.10000000e+01, 4.50000000e+01, 2.64575131e-01 },
            new double[] { 4.50000000e+01, 3.80000000e+01, 3.00000000e-01 },
            new double[] { 3.80000000e+01, 1.10000000e+01, 3.00000000e-01 },
            new double[] { 1.10000000e+01, 4.20000000e+01, 3.00000000e-01 },
            new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01 },
            new double[] { 4.60000000e+01, 6.00000000e+00, 3.16227766e-01 },
            new double[] { 6.00000000e+00, 3.10000000e+01, 3.16227766e-01 },
            new double[] { 3.10000000e+01, 3.50000000e+01, 3.31662479e-01 },
            new double[] { 3.50000000e+01, 1.00000000e+01, 3.31662479e-01 },
            new double[] { 1.00000000e+01, 8.00000000e+00, 3.46410162e-01 },
            new double[] { 8.00000000e+00, 3.60000000e+01, 3.46410162e-01 },
            new double[] { 3.60000000e+01, 2.00000000e+01, 3.60555128e-01 },
            new double[] { 2.00000000e+01, 4.30000000e+01, 3.74165739e-01 },
            new double[] { 4.30000000e+01, 5.00000000e+00, 3.74165739e-01 },
            new double[] { 5.00000000e+00, 2.30000000e+01, 3.87298335e-01 },
            new double[] { 2.30000000e+01, 1.60000000e+01, 3.87298335e-01 },
            new double[] { 1.60000000e+01, 4.40000000e+01, 4.12310563e-01 },
            new double[] { 4.40000000e+01, 3.30000000e+01, 4.12310563e-01 },
            new double[] { 3.30000000e+01, 3.20000000e+01, 4.24264069e-01 },
            new double[] { 3.20000000e+01, 2.40000000e+01, 4.24264069e-01 },
            new double[] { 2.40000000e+01, 1.30000000e+01, 4.79583152e-01 },
            new double[] { 1.30000000e+01, 1.80000000e+01, 5.09901951e-01 },
            new double[] { 1.80000000e+01, 2.20000000e+01, 5.38516481e-01 },
            new double[] { 2.20000000e+01, 1.40000000e+01, 5.56776436e-01 },
            new double[] { 1.40000000e+01, 1.50000000e+01, 6.16441400e-01 },
            new double[] { 1.50000000e+01, 4.10000000e+01, 7.81024968e-01 },
            new double[] { 4.10000000e+01, 9.80000000e+01, 1.64012195e+00 },
            new double[] { 9.80000000e+01, 5.70000000e+01, 7.93725393e-01 },
            new double[] { 5.70000000e+01, 6.00000000e+01, 7.21110255e-01 },
            new double[] { 6.00000000e+01, 8.00000000e+01, 7.14142843e-01 },
            new double[] { 8.00000000e+01, 6.90000000e+01, 3.00000000e-01 },
            new double[] { 6.90000000e+01, 9.20000000e+01, 2.64575131e-01 },
            new double[] { 9.20000000e+01, 9.90000000e+01, 2.64575131e-01 },
            new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01 },
            new double[] { 9.60000000e+01, 8.20000000e+01, 3.00000000e-01 },
            new double[] { 8.20000000e+01, 8.90000000e+01, 3.00000000e-01 },
            new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01 },
            new double[] { 9.40000000e+01, 8.80000000e+01, 3.16227766e-01 },
            new double[] { 8.80000000e+01, 5.50000000e+01, 3.31662479e-01 },
            new double[] { 5.50000000e+01, 9.50000000e+01, 3.31662479e-01 },
            new double[] { 9.50000000e+01, 6.70000000e+01, 3.60555128e-01 },
            new double[] { 6.70000000e+01, 6.10000000e+01, 3.60555128e-01 },
            new double[] { 6.10000000e+01, 7.80000000e+01, 3.60555128e-01 },
            new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01 },
            new double[] { 9.10000000e+01, 9.70000000e+01, 3.46410162e-01 },
            new double[] { 9.70000000e+01, 7.40000000e+01, 3.87298335e-01 },
            new double[] { 7.40000000e+01, 5.40000000e+01, 3.87298335e-01 },
            new double[] { 5.40000000e+01, 5.80000000e+01, 3.74165739e-01 },
            new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01 },
            new double[] { 7.50000000e+01, 8.60000000e+01, 3.31662479e-01 },
            new double[] { 8.60000000e+01, 6.50000000e+01, 3.46410162e-01 },
            new double[] { 6.50000000e+01, 5.20000000e+01, 3.46410162e-01 },
            new double[] { 5.20000000e+01, 5.10000000e+01, 3.74165739e-01 },
            new double[] { 5.10000000e+01, 7.60000000e+01, 3.74165739e-01 },
            new double[] { 7.60000000e+01, 7.10000000e+01, 4.00000000e-01 },
            new double[] { 7.10000000e+01, 6.60000000e+01, 4.12310563e-01 },
            new double[] { 6.60000000e+01, 7.70000000e+01, 4.24264069e-01 },
            new double[] { 7.70000000e+01, 1.47000000e+02, 4.24264069e-01 },
            new double[] { 1.47000000e+02, 1.45000000e+02, 3.74165739e-01 },
            new double[] { 1.45000000e+02, 1.12000000e+02, 3.74165739e-01 },
            new double[] { 1.12000000e+02, 1.20000000e+02, 3.74165739e-01 },
            new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01 },
            new double[] { 1.40000000e+02, 1.43000000e+02, 3.46410162e-01 },
            new double[] { 1.43000000e+02, 1.39000000e+02, 3.74165739e-01 },
            new double[] { 1.39000000e+02, 1.24000000e+02, 3.74165739e-01 },
            new double[] { 1.24000000e+02, 1.15000000e+02, 3.87298335e-01 },
            new double[] { 1.15000000e+02, 1.11000000e+02, 3.87298335e-01 },
            new double[] { 1.11000000e+02, 1.03000000e+02, 3.87298335e-01 },
            new double[] { 1.03000000e+02, 1.16000000e+02, 3.87298335e-01 },
            new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01 },
            new double[] { 1.28000000e+02, 1.04000000e+02, 3.87298335e-01 },
            new double[] { 1.04000000e+02, 1.44000000e+02, 4.00000000e-01 },
            new double[] { 1.44000000e+02, 1.46000000e+02, 4.12310563e-01 },
            new double[] { 1.46000000e+02, 1.23000000e+02, 4.12310563e-01 },
            new double[] { 1.23000000e+02, 1.27000000e+02, 3.60555128e-01 },
            new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01 },
            new double[] { 1.38000000e+02, 1.49000000e+02, 3.31662479e-01 },
            new double[] { 1.49000000e+02, 1.01000000e+02, 3.31662479e-01 },
            new double[] { 1.01000000e+02, 1.42000000e+02, 3.31662479e-01 },
            new double[] { 1.42000000e+02, 8.30000000e+01, 3.74165739e-01 },
            new double[] { 8.30000000e+01, 1.26000000e+02, 3.87298335e-01 },
            new double[] { 1.26000000e+02, 7.00000000e+01, 4.24264069e-01 },
            new double[] { 7.00000000e+01, 7.20000000e+01, 4.24264069e-01 },
            new double[] { 7.20000000e+01, 1.10000000e+02, 4.24264069e-01 },
            new double[] { 1.10000000e+02, 9.00000000e+01, 4.24264069e-01 },
            new double[] { 9.00000000e+01, 6.30000000e+01, 4.24264069e-01 },
            new double[] { 6.30000000e+01, 1.33000000e+02, 4.35889894e-01 },
            new double[] { 1.33000000e+02, 5.30000000e+01, 4.35889894e-01 },
            new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01 },
            new double[] { 8.10000000e+01, 1.32000000e+02, 4.35889894e-01 },
            new double[] { 1.32000000e+02, 1.37000000e+02, 4.35889894e-01 },
            new double[] { 1.37000000e+02, 7.30000000e+01, 4.35889894e-01 },
            new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01 },
            new double[] { 1.36000000e+02, 7.90000000e+01, 4.47213595e-01 },
            new double[] { 7.90000000e+01, 5.60000000e+01, 4.58257569e-01 },
            new double[] { 5.60000000e+01, 1.21000000e+02, 4.58257569e-01 },
            new double[] { 1.21000000e+02, 5.00000000e+01, 4.58257569e-01 },
            new double[] { 5.00000000e+01, 1.02000000e+02, 4.58257569e-01 },
            new double[] { 1.02000000e+02, 8.50000000e+01, 4.69041576e-01 },
            new double[] { 8.50000000e+01, 1.25000000e+02, 4.69041576e-01 },
            new double[] { 1.25000000e+02, 8.40000000e+01, 4.89897949e-01 },
            new double[] { 8.40000000e+01, 1.30000000e+02, 5.09901951e-01 },
            new double[] { 1.30000000e+02, 1.41000000e+02, 5.09901951e-01 },
            new double[] { 1.41000000e+02, 6.40000000e+01, 5.19615242e-01 },
            new double[] { 6.40000000e+01, 1.13000000e+02, 5.19615242e-01 },
            new double[] { 1.13000000e+02, 1.14000000e+02, 5.19615242e-01 },
            new double[] { 1.14000000e+02, 5.90000000e+01, 5.29150262e-01 },
            new double[] { 5.90000000e+01, 1.07000000e+02, 5.47722558e-01 },
            new double[] { 1.07000000e+02, 1.05000000e+02, 5.47722558e-01 },
            new double[] { 1.05000000e+02, 1.29000000e+02, 5.56776436e-01 },
            new double[] { 1.29000000e+02, 1.00000000e+02, 5.56776436e-01 },
            new double[] { 1.00000000e+02, 1.19000000e+02, 5.83095189e-01 },
            new double[] { 1.19000000e+02, 6.20000000e+01, 5.83095189e-01 },
            new double[] { 6.20000000e+01, 8.70000000e+01, 6.08276253e-01 },
            new double[] { 8.70000000e+01, 1.48000000e+02, 6.16441400e-01 },
            new double[] { 1.48000000e+02, 1.08000000e+02, 6.16441400e-01 },
            new double[] { 1.08000000e+02, 9.30000000e+01, 6.48074070e-01 },
            new double[] { 9.30000000e+01, 1.34000000e+02, 6.63324958e-01 },
            new double[] { 1.34000000e+02, 6.80000000e+01, 6.78232998e-01 },
            new double[] { 6.80000000e+01, 1.35000000e+02, 6.78232998e-01 },
            new double[] { 1.35000000e+02, 1.22000000e+02, 6.78232998e-01 },
            new double[] { 1.22000000e+02, 1.09000000e+02, 7.54983444e-01 },
            new double[] { 1.09000000e+02, 1.06000000e+02, 8.77496439e-01 },
            new double[] { 1.06000000e+02, 1.18000000e+02, 9.27361850e-01 },
            new double[] { 1.18000000e+02, 1.31000000e+02, 9.32737905e-01 },
            new double[] { 1.31000000e+02, 1.17000000e+02, 1.00498756e+00 } };

    assertTrue(MatUtils.equalsWithTolerance(cdist, expected_cdists, 1e-8));

    double[][] srtd_cdists = MatUtils.sortAscByCol(cdist, 2);
    double[][] expected_srted = new double[][] {
            new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01 },
            new double[] { 3.90000000e+01, 1.70000000e+01, 1.73205081e-01 },
            new double[] { 1.70000000e+01, 2.70000000e+01, 1.73205081e-01 },
            new double[] { 2.70000000e+01, 2.80000000e+01, 1.73205081e-01 },
            new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01 },
            new double[] { 3.00000000e+01, 3.40000000e+01, 1.73205081e-01 },
            new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01 },
            new double[] { 1.00000000e+00, 3.00000000e+01, 1.73205081e-01 },
            new double[] { 3.70000000e+01, 1.20000000e+01, 1.73205081e-01 },
            new double[] { 2.80000000e+01, 7.00000000e+00, 2.00000000e-01 },
            new double[] { 1.20000000e+01, 2.50000000e+01, 2.23606798e-01 },
            new double[] { 7.00000000e+00, 4.90000000e+01, 2.23606798e-01 },
            new double[] { 4.90000000e+01, 4.00000000e+00, 2.23606798e-01 },
            new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01 },
            new double[] { 2.50000000e+01, 2.90000000e+01, 2.23606798e-01 },
            new double[] { 4.00000000e+00, 2.60000000e+01, 2.44948974e-01 },
            new double[] { 2.60000000e+01, 4.00000000e+01, 2.44948974e-01 },
            new double[] { 4.00000000e+01, 4.80000000e+01, 2.44948974e-01 },
            new double[] { 4.70000000e+01, 3.00000000e+00, 2.44948974e-01 },
            new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01 },
            new double[] { 4.80000000e+01, 9.00000000e+00, 2.64575131e-01 },
            new double[] { 3.00000000e+00, 1.90000000e+01, 2.64575131e-01 },
            new double[] { 1.90000000e+01, 2.00000000e+00, 2.64575131e-01 },
            new double[] { 2.00000000e+00, 2.10000000e+01, 2.64575131e-01 },
            new double[] { 2.10000000e+01, 4.50000000e+01, 2.64575131e-01 },
            new double[] { 9.20000000e+01, 9.90000000e+01, 2.64575131e-01 },
            new double[] { 6.90000000e+01, 9.20000000e+01, 2.64575131e-01 },
            new double[] { 4.50000000e+01, 3.80000000e+01, 3.00000000e-01 },
            new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01 },
            new double[] { 3.80000000e+01, 1.10000000e+01, 3.00000000e-01 },
            new double[] { 1.10000000e+01, 4.20000000e+01, 3.00000000e-01 },
            new double[] { 8.00000000e+01, 6.90000000e+01, 3.00000000e-01 },
            new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01 },
            new double[] { 8.20000000e+01, 8.90000000e+01, 3.00000000e-01 },
            new double[] { 9.60000000e+01, 8.20000000e+01, 3.00000000e-01 },
            new double[] { 4.60000000e+01, 6.00000000e+00, 3.16227766e-01 },
            new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01 },
            new double[] { 6.00000000e+00, 3.10000000e+01, 3.16227766e-01 },
            new double[] { 9.40000000e+01, 8.80000000e+01, 3.16227766e-01 },
            new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01 },
            new double[] { 8.80000000e+01, 5.50000000e+01, 3.31662479e-01 },
            new double[] { 3.10000000e+01, 3.50000000e+01, 3.31662479e-01 },
            new double[] { 7.50000000e+01, 8.60000000e+01, 3.31662479e-01 },
            new double[] { 1.38000000e+02, 1.49000000e+02, 3.31662479e-01 },
            new double[] { 1.49000000e+02, 1.01000000e+02, 3.31662479e-01 },
            new double[] { 1.01000000e+02, 1.42000000e+02, 3.31662479e-01 },
            new double[] { 5.50000000e+01, 9.50000000e+01, 3.31662479e-01 },
            new double[] { 3.50000000e+01, 1.00000000e+01, 3.31662479e-01 },
            new double[] { 8.60000000e+01, 6.50000000e+01, 3.46410162e-01 },
            new double[] { 1.00000000e+01, 8.00000000e+00, 3.46410162e-01 },
            new double[] { 8.00000000e+00, 3.60000000e+01, 3.46410162e-01 },
            new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01 },
            new double[] { 9.10000000e+01, 9.70000000e+01, 3.46410162e-01 },
            new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01 },
            new double[] { 1.40000000e+02, 1.43000000e+02, 3.46410162e-01 },
            new double[] { 6.50000000e+01, 5.20000000e+01, 3.46410162e-01 },
            new double[] { 9.50000000e+01, 6.70000000e+01, 3.60555128e-01 },
            new double[] { 1.23000000e+02, 1.27000000e+02, 3.60555128e-01 },
            new double[] { 3.60000000e+01, 2.00000000e+01, 3.60555128e-01 },
            new double[] { 6.10000000e+01, 7.80000000e+01, 3.60555128e-01 },
            new double[] { 6.70000000e+01, 6.10000000e+01, 3.60555128e-01 },
            new double[] { 1.12000000e+02, 1.20000000e+02, 3.74165739e-01 },
            new double[] { 1.45000000e+02, 1.12000000e+02, 3.74165739e-01 },
            new double[] { 1.47000000e+02, 1.45000000e+02, 3.74165739e-01 },
            new double[] { 1.42000000e+02, 8.30000000e+01, 3.74165739e-01 },
            new double[] { 1.43000000e+02, 1.39000000e+02, 3.74165739e-01 },
            new double[] { 1.39000000e+02, 1.24000000e+02, 3.74165739e-01 },
            new double[] { 5.20000000e+01, 5.10000000e+01, 3.74165739e-01 },
            new double[] { 5.10000000e+01, 7.60000000e+01, 3.74165739e-01 },
            new double[] { 2.00000000e+01, 4.30000000e+01, 3.74165739e-01 },
            new double[] { 5.40000000e+01, 5.80000000e+01, 3.74165739e-01 },
            new double[] { 4.30000000e+01, 5.00000000e+00, 3.74165739e-01 },
            new double[] { 7.40000000e+01, 5.40000000e+01, 3.87298335e-01 },
            new double[] { 9.70000000e+01, 7.40000000e+01, 3.87298335e-01 },
            new double[] { 1.24000000e+02, 1.15000000e+02, 3.87298335e-01 },
            new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01 },
            new double[] { 1.03000000e+02, 1.16000000e+02, 3.87298335e-01 },
            new double[] { 1.11000000e+02, 1.03000000e+02, 3.87298335e-01 },
            new double[] { 1.15000000e+02, 1.11000000e+02, 3.87298335e-01 },
            new double[] { 8.30000000e+01, 1.26000000e+02, 3.87298335e-01 },
            new double[] { 1.28000000e+02, 1.04000000e+02, 3.87298335e-01 },
            new double[] { 5.00000000e+00, 2.30000000e+01, 3.87298335e-01 },
            new double[] { 2.30000000e+01, 1.60000000e+01, 3.87298335e-01 },
            new double[] { 7.60000000e+01, 7.10000000e+01, 4.00000000e-01 },
            new double[] { 1.04000000e+02, 1.44000000e+02, 4.00000000e-01 },
            new double[] { 1.46000000e+02, 1.23000000e+02, 4.12310563e-01 },
            new double[] { 1.44000000e+02, 1.46000000e+02, 4.12310563e-01 },
            new double[] { 1.60000000e+01, 4.40000000e+01, 4.12310563e-01 },
            new double[] { 4.40000000e+01, 3.30000000e+01, 4.12310563e-01 },
            new double[] { 7.10000000e+01, 6.60000000e+01, 4.12310563e-01 },
            new double[] { 3.30000000e+01, 3.20000000e+01, 4.24264069e-01 },
            new double[] { 1.26000000e+02, 7.00000000e+01, 4.24264069e-01 },
            new double[] { 7.00000000e+01, 7.20000000e+01, 4.24264069e-01 },
            new double[] { 3.20000000e+01, 2.40000000e+01, 4.24264069e-01 },
            new double[] { 7.70000000e+01, 1.47000000e+02, 4.24264069e-01 },
            new double[] { 6.60000000e+01, 7.70000000e+01, 4.24264069e-01 },
            new double[] { 7.20000000e+01, 1.10000000e+02, 4.24264069e-01 },
            new double[] { 1.10000000e+02, 9.00000000e+01, 4.24264069e-01 },
            new double[] { 9.00000000e+01, 6.30000000e+01, 4.24264069e-01 },
            new double[] { 6.30000000e+01, 1.33000000e+02, 4.35889894e-01 },
            new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01 },
            new double[] { 1.33000000e+02, 5.30000000e+01, 4.35889894e-01 },
            new double[] { 8.10000000e+01, 1.32000000e+02, 4.35889894e-01 },
            new double[] { 1.32000000e+02, 1.37000000e+02, 4.35889894e-01 },
            new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01 },
            new double[] { 1.37000000e+02, 7.30000000e+01, 4.35889894e-01 },
            new double[] { 1.36000000e+02, 7.90000000e+01, 4.47213595e-01 },
            new double[] { 7.90000000e+01, 5.60000000e+01, 4.58257569e-01 },
            new double[] { 5.60000000e+01, 1.21000000e+02, 4.58257569e-01 },
            new double[] { 1.21000000e+02, 5.00000000e+01, 4.58257569e-01 },
            new double[] { 5.00000000e+01, 1.02000000e+02, 4.58257569e-01 },
            new double[] { 1.02000000e+02, 8.50000000e+01, 4.69041576e-01 },
            new double[] { 8.50000000e+01, 1.25000000e+02, 4.69041576e-01 },
            new double[] { 2.40000000e+01, 1.30000000e+01, 4.79583152e-01 },
            new double[] { 1.25000000e+02, 8.40000000e+01, 4.89897949e-01 },
            new double[] { 1.30000000e+01, 1.80000000e+01, 5.09901951e-01 },
            new double[] { 8.40000000e+01, 1.30000000e+02, 5.09901951e-01 },
            new double[] { 1.30000000e+02, 1.41000000e+02, 5.09901951e-01 },
            new double[] { 1.41000000e+02, 6.40000000e+01, 5.19615242e-01 },
            new double[] { 6.40000000e+01, 1.13000000e+02, 5.19615242e-01 },
            new double[] { 1.13000000e+02, 1.14000000e+02, 5.19615242e-01 },
            new double[] { 1.14000000e+02, 5.90000000e+01, 5.29150262e-01 },
            new double[] { 1.80000000e+01, 2.20000000e+01, 5.38516481e-01 },
            new double[] { 5.90000000e+01, 1.07000000e+02, 5.47722558e-01 },
            new double[] { 1.07000000e+02, 1.05000000e+02, 5.47722558e-01 },
            new double[] { 1.05000000e+02, 1.29000000e+02, 5.56776436e-01 },
            new double[] { 2.20000000e+01, 1.40000000e+01, 5.56776436e-01 },
            new double[] { 1.29000000e+02, 1.00000000e+02, 5.56776436e-01 },
            new double[] { 1.00000000e+02, 1.19000000e+02, 5.83095189e-01 },
            new double[] { 1.19000000e+02, 6.20000000e+01, 5.83095189e-01 },
            new double[] { 6.20000000e+01, 8.70000000e+01, 6.08276253e-01 },
            new double[] { 8.70000000e+01, 1.48000000e+02, 6.16441400e-01 },
            new double[] { 1.48000000e+02, 1.08000000e+02, 6.16441400e-01 },
            new double[] { 1.40000000e+01, 1.50000000e+01, 6.16441400e-01 },
            new double[] { 1.08000000e+02, 9.30000000e+01, 6.48074070e-01 },
            new double[] { 9.30000000e+01, 1.34000000e+02, 6.63324958e-01 },
            new double[] { 1.34000000e+02, 6.80000000e+01, 6.78232998e-01 },
            new double[] { 6.80000000e+01, 1.35000000e+02, 6.78232998e-01 },
            new double[] { 1.35000000e+02, 1.22000000e+02, 6.78232998e-01 },
            new double[] { 6.00000000e+01, 8.00000000e+01, 7.14142843e-01 },
            new double[] { 5.70000000e+01, 6.00000000e+01, 7.21110255e-01 },
            new double[] { 1.22000000e+02, 1.09000000e+02, 7.54983444e-01 },
            new double[] { 1.50000000e+01, 4.10000000e+01, 7.81024968e-01 },
            new double[] { 9.80000000e+01, 5.70000000e+01, 7.93725393e-01 },
            new double[] { 1.09000000e+02, 1.06000000e+02, 8.77496439e-01 },
            new double[] { 1.06000000e+02, 1.18000000e+02, 9.27361850e-01 },
            new double[] { 1.18000000e+02, 1.31000000e+02, 9.32737905e-01 },
            new double[] { 1.31000000e+02, 1.17000000e+02, 1.00498756e+00 },
            new double[] { 4.10000000e+01, 9.80000000e+01, 1.64012195e+00 } };

    //System.out.println(Arrays.toString(VecUtils.argSort(MatUtils.getColumn(cdist, 2))));
    //fail();//from w  w  w  .j av a2  s  .c om

    /*
     * In comparison to sklearn, this can get off by 1 or 2 due to
     * rounding errors in the sort. So lets just make sure there is a
     * discrepancy less than one or two.
     */
    int wrong_ct = 0;
    for (int i = 0; i < srtd_cdists.length; i++) {
        if (!VecUtils.equalsWithTolerance(srtd_cdists[i], expected_srted[i], 1e-8)) {
            if (!Precision.equals(srtd_cdists[i][2], expected_srted[i][2], 1e-8))
                wrong_ct++;
        }
    }

    assertTrue(wrong_ct < 2);

    // Do labeling
    double[][] labMat = HDBSCAN.label(srtd_cdists);

    double[][] expected_labMat = new double[][] {
            new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01, 2.00000000e+00 },
            new double[] { 1.50000000e+02, 1.70000000e+01, 1.73205081e-01, 3.00000000e+00 },
            new double[] { 1.51000000e+02, 2.70000000e+01, 1.73205081e-01, 4.00000000e+00 },
            new double[] { 1.52000000e+02, 2.80000000e+01, 1.73205081e-01, 5.00000000e+00 },
            new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01, 2.00000000e+00 },
            new double[] { 3.00000000e+01, 1.54000000e+02, 1.73205081e-01, 3.00000000e+00 },
            new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01, 2.00000000e+00 },
            new double[] { 1.56000000e+02, 1.55000000e+02, 1.73205081e-01, 5.00000000e+00 },
            new double[] { 1.57000000e+02, 1.20000000e+01, 1.73205081e-01, 6.00000000e+00 },
            new double[] { 1.53000000e+02, 7.00000000e+00, 2.00000000e-01, 6.00000000e+00 },
            new double[] { 1.58000000e+02, 2.50000000e+01, 2.23606798e-01, 7.00000000e+00 },
            new double[] { 1.59000000e+02, 4.90000000e+01, 2.23606798e-01, 7.00000000e+00 },
            new double[] { 1.61000000e+02, 4.00000000e+00, 2.23606798e-01, 8.00000000e+00 },
            new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01, 2.00000000e+00 },
            new double[] { 1.60000000e+02, 1.63000000e+02, 2.23606798e-01, 9.00000000e+00 },
            new double[] { 1.62000000e+02, 2.60000000e+01, 2.44948974e-01, 9.00000000e+00 },
            new double[] { 1.65000000e+02, 4.00000000e+01, 2.44948974e-01, 1.00000000e+01 },
            new double[] { 1.66000000e+02, 4.80000000e+01, 2.44948974e-01, 1.10000000e+01 },
            new double[] { 1.64000000e+02, 3.00000000e+00, 2.44948974e-01, 1.00000000e+01 },
            new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01, 2.00000000e+00 },
            new double[] { 1.67000000e+02, 1.68000000e+02, 2.64575131e-01, 2.10000000e+01 },
            new double[] { 1.70000000e+02, 1.90000000e+01, 2.64575131e-01, 2.20000000e+01 },
            new double[] { 1.71000000e+02, 2.00000000e+00, 2.64575131e-01, 2.30000000e+01 },
            new double[] { 1.72000000e+02, 2.10000000e+01, 2.64575131e-01, 2.40000000e+01 },
            new double[] { 1.73000000e+02, 4.50000000e+01, 2.64575131e-01, 2.50000000e+01 },
            new double[] { 9.20000000e+01, 1.69000000e+02, 2.64575131e-01, 3.00000000e+00 },
            new double[] { 6.90000000e+01, 1.75000000e+02, 2.64575131e-01, 4.00000000e+00 },
            new double[] { 1.74000000e+02, 3.80000000e+01, 3.00000000e-01, 2.60000000e+01 },
            new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01, 2.00000000e+00 },
            new double[] { 1.77000000e+02, 1.10000000e+01, 3.00000000e-01, 2.70000000e+01 },
            new double[] { 1.79000000e+02, 1.78000000e+02, 3.00000000e-01, 2.90000000e+01 },
            new double[] { 8.00000000e+01, 1.76000000e+02, 3.00000000e-01, 5.00000000e+00 },
            new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01, 2.00000000e+00 },
            new double[] { 8.20000000e+01, 1.82000000e+02, 3.00000000e-01, 3.00000000e+00 },
            new double[] { 1.81000000e+02, 1.83000000e+02, 3.00000000e-01, 8.00000000e+00 },
            new double[] { 1.80000000e+02, 6.00000000e+00, 3.16227766e-01, 3.00000000e+01 },
            new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01, 2.00000000e+00 },
            new double[] { 1.85000000e+02, 3.10000000e+01, 3.16227766e-01, 3.10000000e+01 },
            new double[] { 1.84000000e+02, 8.80000000e+01, 3.16227766e-01, 9.00000000e+00 },
            new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01, 2.00000000e+00 },
            new double[] { 1.88000000e+02, 5.50000000e+01, 3.31662479e-01, 1.00000000e+01 },
            new double[] { 1.87000000e+02, 3.50000000e+01, 3.31662479e-01, 3.20000000e+01 },
            new double[] { 1.89000000e+02, 8.60000000e+01, 3.31662479e-01, 3.00000000e+00 },
            new double[] { 1.86000000e+02, 1.49000000e+02, 3.31662479e-01, 3.00000000e+00 },
            new double[] { 1.93000000e+02, 1.01000000e+02, 3.31662479e-01, 4.00000000e+00 },
            new double[] { 1.94000000e+02, 1.42000000e+02, 3.31662479e-01, 5.00000000e+00 },
            new double[] { 1.90000000e+02, 9.50000000e+01, 3.31662479e-01, 1.10000000e+01 },
            new double[] { 1.91000000e+02, 1.00000000e+01, 3.31662479e-01, 3.30000000e+01 },
            new double[] { 1.92000000e+02, 6.50000000e+01, 3.46410162e-01, 4.00000000e+00 },
            new double[] { 1.97000000e+02, 8.00000000e+00, 3.46410162e-01, 3.40000000e+01 },
            new double[] { 1.99000000e+02, 3.60000000e+01, 3.46410162e-01, 3.50000000e+01 },
            new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01, 2.00000000e+00 },
            new double[] { 2.01000000e+02, 9.70000000e+01, 3.46410162e-01, 3.00000000e+00 },
            new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01, 2.00000000e+00 },
            new double[] { 2.03000000e+02, 1.43000000e+02, 3.46410162e-01, 3.00000000e+00 },
            new double[] { 1.98000000e+02, 5.20000000e+01, 3.46410162e-01, 5.00000000e+00 },
            new double[] { 1.96000000e+02, 6.70000000e+01, 3.60555128e-01, 1.20000000e+01 },
            new double[] { 1.23000000e+02, 1.95000000e+02, 3.60555128e-01, 6.00000000e+00 },
            new double[] { 2.00000000e+02, 2.00000000e+01, 3.60555128e-01, 3.60000000e+01 },
            new double[] { 6.10000000e+01, 2.02000000e+02, 3.60555128e-01, 4.00000000e+00 },
            new double[] { 2.06000000e+02, 2.09000000e+02, 3.60555128e-01, 1.60000000e+01 },
            new double[] { 1.12000000e+02, 2.04000000e+02, 3.74165739e-01, 4.00000000e+00 },
            new double[] { 1.45000000e+02, 2.11000000e+02, 3.74165739e-01, 5.00000000e+00 },
            new double[] { 1.47000000e+02, 2.12000000e+02, 3.74165739e-01, 6.00000000e+00 },
            new double[] { 2.07000000e+02, 8.30000000e+01, 3.74165739e-01, 7.00000000e+00 },
            new double[] { 2.13000000e+02, 1.39000000e+02, 3.74165739e-01, 7.00000000e+00 },
            new double[] { 2.15000000e+02, 1.24000000e+02, 3.74165739e-01, 8.00000000e+00 },
            new double[] { 2.05000000e+02, 5.10000000e+01, 3.74165739e-01, 6.00000000e+00 },
            new double[] { 2.17000000e+02, 7.60000000e+01, 3.74165739e-01, 7.00000000e+00 },
            new double[] { 2.08000000e+02, 4.30000000e+01, 3.74165739e-01, 3.70000000e+01 },
            new double[] { 5.40000000e+01, 2.18000000e+02, 3.74165739e-01, 8.00000000e+00 },
            new double[] { 2.19000000e+02, 5.00000000e+00, 3.74165739e-01, 3.80000000e+01 },
            new double[] { 7.40000000e+01, 2.20000000e+02, 3.87298335e-01, 9.00000000e+00 },
            new double[] { 2.10000000e+02, 2.22000000e+02, 3.87298335e-01, 2.50000000e+01 },
            new double[] { 2.16000000e+02, 1.15000000e+02, 3.87298335e-01, 9.00000000e+00 },
            new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01, 2.00000000e+00 },
            new double[] { 1.03000000e+02, 2.25000000e+02, 3.87298335e-01, 3.00000000e+00 },
            new double[] { 1.11000000e+02, 2.26000000e+02, 3.87298335e-01, 4.00000000e+00 },
            new double[] { 2.24000000e+02, 2.27000000e+02, 3.87298335e-01, 1.30000000e+01 },
            new double[] { 2.14000000e+02, 1.26000000e+02, 3.87298335e-01, 8.00000000e+00 },
            new double[] { 2.28000000e+02, 1.04000000e+02, 3.87298335e-01, 1.40000000e+01 },
            new double[] { 2.21000000e+02, 2.30000000e+01, 3.87298335e-01, 3.90000000e+01 },
            new double[] { 2.31000000e+02, 1.60000000e+01, 3.87298335e-01, 4.00000000e+01 },
            new double[] { 2.23000000e+02, 7.10000000e+01, 4.00000000e-01, 2.60000000e+01 },
            new double[] { 2.30000000e+02, 1.44000000e+02, 4.00000000e-01, 1.50000000e+01 },
            new double[] { 1.46000000e+02, 2.29000000e+02, 4.12310563e-01, 9.00000000e+00 },
            new double[] { 2.34000000e+02, 2.35000000e+02, 4.12310563e-01, 2.40000000e+01 },
            new double[] { 2.32000000e+02, 4.40000000e+01, 4.12310563e-01, 4.10000000e+01 },
            new double[] { 2.37000000e+02, 3.30000000e+01, 4.12310563e-01, 4.20000000e+01 },
            new double[] { 2.33000000e+02, 6.60000000e+01, 4.12310563e-01, 2.70000000e+01 },
            new double[] { 2.38000000e+02, 3.20000000e+01, 4.24264069e-01, 4.30000000e+01 },
            new double[] { 2.36000000e+02, 7.00000000e+01, 4.24264069e-01, 2.50000000e+01 },
            new double[] { 2.41000000e+02, 7.20000000e+01, 4.24264069e-01, 2.60000000e+01 },
            new double[] { 2.40000000e+02, 2.40000000e+01, 4.24264069e-01, 4.40000000e+01 },
            new double[] { 7.70000000e+01, 2.42000000e+02, 4.24264069e-01, 2.70000000e+01 },
            new double[] { 2.39000000e+02, 2.44000000e+02, 4.24264069e-01, 5.40000000e+01 },
            new double[] { 2.45000000e+02, 1.10000000e+02, 4.24264069e-01, 5.50000000e+01 },
            new double[] { 2.46000000e+02, 9.00000000e+01, 4.24264069e-01, 5.60000000e+01 },
            new double[] { 2.47000000e+02, 6.30000000e+01, 4.24264069e-01, 5.70000000e+01 },
            new double[] { 2.48000000e+02, 1.33000000e+02, 4.35889894e-01, 5.80000000e+01 },
            new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01, 2.00000000e+00 },
            new double[] { 2.49000000e+02, 2.50000000e+02, 4.35889894e-01, 6.00000000e+01 },
            new double[] { 2.51000000e+02, 1.32000000e+02, 4.35889894e-01, 6.10000000e+01 },
            new double[] { 2.52000000e+02, 1.37000000e+02, 4.35889894e-01, 6.20000000e+01 },
            new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01, 2.00000000e+00 },
            new double[] { 2.53000000e+02, 2.54000000e+02, 4.35889894e-01, 6.40000000e+01 },
            new double[] { 2.55000000e+02, 7.90000000e+01, 4.47213595e-01, 6.50000000e+01 },
            new double[] { 2.56000000e+02, 5.60000000e+01, 4.58257569e-01, 6.60000000e+01 },
            new double[] { 2.57000000e+02, 1.21000000e+02, 4.58257569e-01, 6.70000000e+01 },
            new double[] { 2.58000000e+02, 5.00000000e+01, 4.58257569e-01, 6.80000000e+01 },
            new double[] { 2.59000000e+02, 1.02000000e+02, 4.58257569e-01, 6.90000000e+01 },
            new double[] { 2.60000000e+02, 8.50000000e+01, 4.69041576e-01, 7.00000000e+01 },
            new double[] { 2.61000000e+02, 1.25000000e+02, 4.69041576e-01, 7.10000000e+01 },
            new double[] { 2.43000000e+02, 1.30000000e+01, 4.79583152e-01, 4.50000000e+01 },
            new double[] { 2.62000000e+02, 8.40000000e+01, 4.89897949e-01, 7.20000000e+01 },
            new double[] { 2.63000000e+02, 1.80000000e+01, 5.09901951e-01, 4.60000000e+01 },
            new double[] { 2.64000000e+02, 1.30000000e+02, 5.09901951e-01, 7.30000000e+01 },
            new double[] { 2.66000000e+02, 1.41000000e+02, 5.09901951e-01, 7.40000000e+01 },
            new double[] { 2.67000000e+02, 6.40000000e+01, 5.19615242e-01, 7.50000000e+01 },
            new double[] { 2.68000000e+02, 1.13000000e+02, 5.19615242e-01, 7.60000000e+01 },
            new double[] { 2.69000000e+02, 1.14000000e+02, 5.19615242e-01, 7.70000000e+01 },
            new double[] { 2.70000000e+02, 5.90000000e+01, 5.29150262e-01, 7.80000000e+01 },
            new double[] { 2.65000000e+02, 2.20000000e+01, 5.38516481e-01, 4.70000000e+01 },
            new double[] { 2.71000000e+02, 1.07000000e+02, 5.47722558e-01, 7.90000000e+01 },
            new double[] { 2.73000000e+02, 1.05000000e+02, 5.47722558e-01, 8.00000000e+01 },
            new double[] { 2.74000000e+02, 1.29000000e+02, 5.56776436e-01, 8.10000000e+01 },
            new double[] { 2.72000000e+02, 1.40000000e+01, 5.56776436e-01, 4.80000000e+01 },
            new double[] { 2.75000000e+02, 1.00000000e+02, 5.56776436e-01, 8.20000000e+01 },
            new double[] { 2.77000000e+02, 1.19000000e+02, 5.83095189e-01, 8.30000000e+01 },
            new double[] { 2.78000000e+02, 6.20000000e+01, 5.83095189e-01, 8.40000000e+01 },
            new double[] { 2.79000000e+02, 8.70000000e+01, 6.08276253e-01, 8.50000000e+01 },
            new double[] { 2.80000000e+02, 1.48000000e+02, 6.16441400e-01, 8.60000000e+01 },
            new double[] { 2.81000000e+02, 1.08000000e+02, 6.16441400e-01, 8.70000000e+01 },
            new double[] { 2.76000000e+02, 1.50000000e+01, 6.16441400e-01, 4.90000000e+01 },
            new double[] { 2.82000000e+02, 9.30000000e+01, 6.48074070e-01, 8.80000000e+01 },
            new double[] { 2.84000000e+02, 1.34000000e+02, 6.63324958e-01, 8.90000000e+01 },
            new double[] { 2.85000000e+02, 6.80000000e+01, 6.78232998e-01, 9.00000000e+01 },
            new double[] { 2.86000000e+02, 1.35000000e+02, 6.78232998e-01, 9.10000000e+01 },
            new double[] { 2.87000000e+02, 1.22000000e+02, 6.78232998e-01, 9.20000000e+01 },
            new double[] { 6.00000000e+01, 2.88000000e+02, 7.14142843e-01, 9.30000000e+01 },
            new double[] { 5.70000000e+01, 2.89000000e+02, 7.21110255e-01, 9.40000000e+01 },
            new double[] { 2.90000000e+02, 1.09000000e+02, 7.54983444e-01, 9.50000000e+01 },
            new double[] { 2.83000000e+02, 4.10000000e+01, 7.81024968e-01, 5.00000000e+01 },
            new double[] { 9.80000000e+01, 2.91000000e+02, 7.93725393e-01, 9.60000000e+01 },
            new double[] { 2.93000000e+02, 1.06000000e+02, 8.77496439e-01, 9.70000000e+01 },
            new double[] { 2.94000000e+02, 1.18000000e+02, 9.27361850e-01, 9.80000000e+01 },
            new double[] { 2.95000000e+02, 1.31000000e+02, 9.32737905e-01, 9.90000000e+01 },
            new double[] { 2.96000000e+02, 1.17000000e+02, 1.00498756e+00, 1.00000000e+02 },
            new double[] { 2.92000000e+02, 2.97000000e+02, 1.64012195e+00, 1.50000000e+02 } };

    // ensure the labeling method works and gets what the sklearn method would...
    assertTrue(MatUtils.equalsExactly(expected_labMat, HDBSCAN.label(expected_srted)));

    // expected sorted...
    ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> expected_hlist = new ArrayList<>();
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(150, 151, 0.6097107608496923, 50));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(150, 152, 0.6097107608496923, 100));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 2, 3.7796447300922726, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 5, 2.6726124191242397, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 6, 3.1622776601683857, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 8, 2.886751345948128, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 10, 3.015113445777631, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 11, 3.3333333333333353, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 13, 2.0851441405707485, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 14, 1.796053020267749, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 15, 1.6222142113076248, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 16, 2.5819888974716076, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 18, 1.9611613513818411, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 19, 3.7796447300922766, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 20, 2.773500981126144, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 21, 3.7796447300922726, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 22, 1.85695338177052, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 23, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 24, 2.35702260395516, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 31, 3.1622776601683804, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 32, 2.3570226039551616, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 33, 2.42535625036333, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 35, 3.0151134457776374, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 36, 2.8867513459481273, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 38, 3.3333333333333384, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 41, 1.2803687993289594, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 42, 3.3333333333333353, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 43, 2.6726124191242437, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 44, 2.4253562503633304, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 45, 3.7796447300922726, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 46, 3.3333333333333353, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 153, 3.7796447300922766, 11));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 154, 3.7796447300922766, 10));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 50, 2.1821789023599227, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 53, 2.294157338705618, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 56, 2.1821789023599236, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 57, 1.386750490563073, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 59, 1.8898223650461363, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 60, 1.4002800840280099, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 62, 1.7149858514250882, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 63, 2.357022603955156, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 64, 1.9245008972987536, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 68, 1.4744195615489724, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 73, 2.2941573387056153, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 79, 2.2360679774997894, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 81, 2.294157338705618, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 84, 2.041241452319315, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 85, 2.132007163556105, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 87, 1.6439898730535734, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 90, 2.3570226039551567, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 93, 1.5430334996209187, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 98, 1.2598815766974234, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 100, 1.796053020267749, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 102, 2.1821789023599227, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 105, 1.8257418583505527, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 106, 1.1396057645963797, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 107, 1.8257418583505547, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 108, 1.6222142113076254, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 109, 1.3245323570650438, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 110, 2.3570226039551576, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 113, 1.9245008972987536, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 114, 1.9245008972987536, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 117, 0.995037190209989, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 118, 1.0783277320343838, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 119, 1.7149858514250889, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 121, 2.1821789023599227, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 122, 1.4744195615489704, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 125, 2.132007163556103, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 129, 1.7960530202677494, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 130, 1.9611613513818407, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 131, 1.0721125348377945, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 132, 2.294157338705618, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 133, 2.2941573387056184, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 134, 1.5075567228888174, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 135, 1.474419561548971, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 136, 2.2941573387056153, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 137, 2.294157338705617, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 141, 1.9611613513818398, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 148, 1.6222142113076257, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 155, 2.3570226039551576, 27));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 156, 2.3570226039551576, 27));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 0, 5.773502691896247, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 4, 4.472135954999576, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 7, 5.000000000000003, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 17, 5.773502691896247, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 26, 4.082482904638632, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 27, 5.773502691896247, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 28, 5.773502691896247, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 39, 5.773502691896247, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 40, 4.08248290463863, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 48, 4.0824829046386295, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 49, 4.47213595499958, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 1, 5.773502691896246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 3, 4.082482904638627, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 9, 5.773502691896246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 12, 5.773502691896245, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 25, 4.47213595499958, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 29, 4.472135954999572, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 30, 5.773502691896246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 34, 5.773502691896246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 37, 5.773502691896246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 47, 4.472135954999572, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 66, 2.4253562503633277, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 71, 2.5000000000000013, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 157, 2.5819888974716125, 16));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 158, 2.5819888974716125, 9));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 70, 2.3570226039551603, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 72, 2.3570226039551603, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 77, 2.3570226039551576, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 159, 2.425356250363331, 15));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 160, 2.425356250363331, 9));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 55, 3.0151134457776374, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 61, 2.7735009811261433, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 67, 2.773500981126145, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 69, 3.333333333333332, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 78, 2.7735009811261433, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 80, 3.333333333333332, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 82, 3.3333333333333317, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 88, 3.162277660168379, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 89, 3.3333333333333317, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 91, 2.7735009811261433, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 92, 3.333333333333332, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 94, 3.3333333333333317, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 95, 3.015113445777636, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 96, 3.333333333333332, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 97, 2.7735009811261433, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 99, 3.333333333333332, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 51, 2.672612419124244, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 52, 2.886751345948124, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 54, 2.6726124191242406, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 58, 2.886751345948124, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 65, 2.886751345948124, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 74, 2.5819888974716125, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 75, 2.886751345948124, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 76, 2.672612419124244, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 86, 2.886751345948124, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 103, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 104, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 111, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 112, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 115, 2.5819888974716125, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 116, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 120, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 124, 2.6726124191242446, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 128, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 139, 2.6726124191242455, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 140, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 143, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 144, 2.5000000000000004, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 145, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 147, 2.6726124191242464, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 83, 2.672612419124246, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 101, 3.0151134457776365, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 123, 2.7735009811261446, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 126, 2.581988897471612, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 127, 3.0151134457776365, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 138, 3.0151134457776365, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 142, 3.0151134457776365, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 146, 2.425356250363331, 1));
    expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 149, 3.0151134457776365, 1));

    // test the condense tree label
    ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> condensed = HDBSCAN.LinkageTreeUtils
            .condenseTree(expected_labMat, 5);
    // Now sort it for the sake of comparing to the sklearn res...
    Collections.sort(condensed, new Comparator<QuadTup<Integer, Integer, Double, Integer>>() {
        @Override
        public int compare(QuadTup<Integer, Integer, Double, Integer> q1,
                QuadTup<Integer, Integer, Double, Integer> q2) {
            int cmp = q1.getFirst().compareTo(q2.getFirst());

            if (cmp == 0) {
                cmp = q1.getSecond().compareTo(q2.getSecond());

                if (cmp == 0) {
                    cmp = q1.getThird().compareTo(q2.getThird());

                    if (cmp == 0) {
                        return q1.getFourth().compareTo(q2.getFourth());
                    }

                    return cmp;
                }

                return cmp;
            }

            return cmp;
        }
    });

    for (int i = 0; i < condensed.size(); i++) {
        if (!condensed.get(i).almostEquals(expected_hlist.get(i))) {
            System.out.println(condensed.get(i));
            System.out.println(expected_hlist.get(i));
            fail();
        }
    }

    // If we get here, the condensed labels works!!
    TreeMap<Integer, Double> stability = HDBSCAN.LinkageTreeUtils.computeStability(condensed);
    TreeMap<Integer, Double> exp_stab = new TreeMap<>();
    exp_stab.put(150, Double.NaN);
    exp_stab.put(151, 128.9165546745262);
    exp_stab.put(152, 150.98635723043549);
    exp_stab.put(153, 13.48314205238124);
    exp_stab.put(154, 14.343459620092055);
    exp_stab.put(155, 5.8354683803643868);
    exp_stab.put(156, 1.6400075137961618);
    exp_stab.put(157, 8.4148537644752253);
    exp_stab.put(158, 1.7956828073404498);
    exp_stab.put(159, 2.99248898237368);
    exp_stab.put(160, Double.NaN);

    /*
     * Assert near equality...
     */
    for (Map.Entry<Integer, Double> entry : exp_stab.entrySet()) {
        int key = entry.getKey();
        double stab = entry.getValue();

        if (Double.isNaN(stab) && Double.isNaN(stability.get(key)))
            continue;
        if (!Precision.equals(stab, stability.get(key), 1e-6)) {
            System.out.println(key + ", " + stab);
            System.out.println(key + ", " + stability.get(key));
            fail();
        }
    }

    // test the treeToLabels method...
    final int[] labs = new NoiseyLabelEncoder(HDBSCAN.treeToLabels(iris.getData(), labMat, 5)).fit()
            .getEncodedLabels();
    assertTrue(VecUtils.equalsExactly(labs, expected_iris_labs));
}

From source file:org.gnenc.yams.portlet.AccountManagement.java

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws IOException {
    TreeMap<String, String> responses = new TreeMap<String, String>();
    String group = StringPool.NULL;

    switch (DAOParamUtil.getInteger(resourceRequest, UserDisplayTerms.CMD)) {
    case ADD_ACCOUNT_STEP_1_CMD:
        group = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.PRIMARY_GROUP);
        String accountType = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.ACCOUNT_TYPE);
        String firstName = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.FIRST_NAME);
        String lastName = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.LAST_NAME);
        PortletUtil.processAccountName(firstName, lastName, group, accountType, responses);
        break;/*from w  w  w .  j a v  a  2s.c o  m*/
    case CHOOSE_GROUP_CMD:
        group = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.GROUP);
        Account callingAccount = ActionUtil
                .accountFromUidNumber(DAOParamUtil.getString(resourceRequest, "callingAccount"));
        Account account = ActionUtil.accountFromEmailAddress(DAOParamUtil.getString(resourceRequest, "mail"));

        responses = ActionUtil.groupPermissionsGrantableAndAccountPermissionsToMap(callingAccount, account,
                group);

        try {
            responses.put("permissionsId",
                    String.valueOf(PermissionsLocalServiceUtil.getPermissionsIdByEmailAddressAndFqgn(
                            account.getMail().get(0), PermissionsUtil.getFqgnFromDn(group))));
        } catch (SystemException e) {
            responses.put("permissionsId", "0");
        }
        break;
    case GET_ENTITY_ACCOUNT_TYPES:
        group = DAOParamUtil.getString(resourceRequest, UserDisplayTerms.PRIMARY_GROUP);
        PortletUtil.getEntityAccountTypes(group, responses);
    default:
        //nothing
        break;
    }

    resourceResponse.setContentType("text/javascript");

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    for (Map.Entry<String, String> response : responses.entrySet()) {

        jsonObject.put(response.getKey(), response.getValue());
    }

    PrintWriter writer = resourceResponse.getWriter();
    writer.write(jsonObject.toString());
}

From source file:org.apache.hadoop.hbase.regionserver.StripeStoreFileManager.java

/**
 * Loads initial store files that were picked up from some physical location pertaining to
 * this store (presumably). Unlike adding files after compaction, assumes empty initial
 * sets, and is forgiving with regard to stripe constraints - at worst, many/all files will
 * go to level 0./*from  w w  w  . ja va  2  s .  c om*/
 * @param storeFiles Store files to add.
 */
private void loadUnclassifiedStoreFiles(List<StoreFile> storeFiles) {
    LOG.debug("Attempting to load " + storeFiles.size() + " store files.");
    TreeMap<byte[], ArrayList<StoreFile>> candidateStripes = new TreeMap<byte[], ArrayList<StoreFile>>(
            MAP_COMPARATOR);
    ArrayList<StoreFile> level0Files = new ArrayList<StoreFile>();
    // Separate the files into tentative stripes; then validate. Currently, we rely on metadata.
    // If needed, we could dynamically determine the stripes in future.
    for (StoreFile sf : storeFiles) {
        byte[] startRow = startOf(sf), endRow = endOf(sf);
        // Validate the range and put the files into place.
        if (isInvalid(startRow) || isInvalid(endRow)) {
            insertFileIntoStripe(level0Files, sf); // No metadata - goes to L0.
            ensureLevel0Metadata(sf);
        } else if (!isOpen(startRow) && !isOpen(endRow) && nonOpenRowCompare(startRow, endRow) >= 0) {
            LOG.error("Unexpected metadata - start row [" + Bytes.toString(startRow) + "], end row ["
                    + Bytes.toString(endRow) + "] in file [" + sf.getPath() + "], pushing to L0");
            insertFileIntoStripe(level0Files, sf); // Bad metadata - goes to L0 also.
            ensureLevel0Metadata(sf);
        } else {
            ArrayList<StoreFile> stripe = candidateStripes.get(endRow);
            if (stripe == null) {
                stripe = new ArrayList<StoreFile>();
                candidateStripes.put(endRow, stripe);
            }
            insertFileIntoStripe(stripe, sf);
        }
    }
    // Possible improvement - for variable-count stripes, if all the files are in L0, we can
    // instead create single, open-ended stripe with all files.

    boolean hasOverlaps = false;
    byte[] expectedStartRow = null; // first stripe can start wherever
    Iterator<Map.Entry<byte[], ArrayList<StoreFile>>> entryIter = candidateStripes.entrySet().iterator();
    while (entryIter.hasNext()) {
        Map.Entry<byte[], ArrayList<StoreFile>> entry = entryIter.next();
        ArrayList<StoreFile> files = entry.getValue();
        // Validate the file start rows, and remove the bad ones to level 0.
        for (int i = 0; i < files.size(); ++i) {
            StoreFile sf = files.get(i);
            byte[] startRow = startOf(sf);
            if (expectedStartRow == null) {
                expectedStartRow = startRow; // ensure that first stripe is still consistent
            } else if (!rowEquals(expectedStartRow, startRow)) {
                hasOverlaps = true;
                LOG.warn("Store file doesn't fit into the tentative stripes - expected to start at ["
                        + Bytes.toString(expectedStartRow) + "], but starts at [" + Bytes.toString(startRow)
                        + "], to L0 it goes");
                StoreFile badSf = files.remove(i);
                insertFileIntoStripe(level0Files, badSf);
                ensureLevel0Metadata(badSf);
                --i;
            }
        }
        // Check if any files from the candidate stripe are valid. If so, add a stripe.
        byte[] endRow = entry.getKey();
        if (!files.isEmpty()) {
            expectedStartRow = endRow; // Next stripe must start exactly at that key.
        } else {
            entryIter.remove();
        }
    }

    // In the end, there must be open ends on two sides. If not, and there were no errors i.e.
    // files are consistent, they might be coming from a split. We will treat the boundaries
    // as open keys anyway, and log the message.
    // If there were errors, we'll play it safe and dump everything into L0.
    if (!candidateStripes.isEmpty()) {
        StoreFile firstFile = candidateStripes.firstEntry().getValue().get(0);
        boolean isOpen = isOpen(startOf(firstFile)) && isOpen(candidateStripes.lastKey());
        if (!isOpen) {
            LOG.warn("The range of the loaded files does not cover full key space: from ["
                    + Bytes.toString(startOf(firstFile)) + "], to ["
                    + Bytes.toString(candidateStripes.lastKey()) + "]");
            if (!hasOverlaps) {
                ensureEdgeStripeMetadata(candidateStripes.firstEntry().getValue(), true);
                ensureEdgeStripeMetadata(candidateStripes.lastEntry().getValue(), false);
            } else {
                LOG.warn("Inconsistent files, everything goes to L0.");
                for (ArrayList<StoreFile> files : candidateStripes.values()) {
                    for (StoreFile sf : files) {
                        insertFileIntoStripe(level0Files, sf);
                        ensureLevel0Metadata(sf);
                    }
                }
                candidateStripes.clear();
            }
        }
    }

    // Copy the results into the fields.
    State state = new State();
    state.level0Files = ImmutableList.copyOf(level0Files);
    state.stripeFiles = new ArrayList<ImmutableList<StoreFile>>(candidateStripes.size());
    state.stripeEndRows = new byte[Math.max(0, candidateStripes.size() - 1)][];
    ArrayList<StoreFile> newAllFiles = new ArrayList<StoreFile>(level0Files);
    int i = candidateStripes.size() - 1;
    for (Map.Entry<byte[], ArrayList<StoreFile>> entry : candidateStripes.entrySet()) {
        state.stripeFiles.add(ImmutableList.copyOf(entry.getValue()));
        newAllFiles.addAll(entry.getValue());
        if (i > 0) {
            state.stripeEndRows[state.stripeFiles.size() - 1] = entry.getKey();
        }
        --i;
    }
    state.allFilesCached = ImmutableList.copyOf(newAllFiles);
    this.state = state;
    debugDumpState("Files loaded");
}

From source file:jetbrains.exodus.env.Reflect.java

public void traverse() {
    final TreeMap<Long, Long> usedSpace = new TreeMap<>();
    System.out.print("Analysing meta tree loggables... ");
    fetchUsedSpace(env.getMetaTree(null).addressIterator(), usedSpace);
    final List<String> names = env.computeInReadonlyTransaction(new TransactionalComputable<List<String>>() {
        @Override//  w w  w  . ja  v  a 2 s  .c o  m
        public List<String> compute(@NotNull Transaction txn) {
            return env.getAllStoreNames(txn);
        }
    });
    env.executeInReadonlyTransaction(new TransactionalExecutable() {
        @Override
        public void execute(@NotNull final Transaction txn) {
            if (env.storeExists(GarbageCollector.UTILIZATION_PROFILE_STORE_NAME, txn)) {
                names.add(GarbageCollector.UTILIZATION_PROFILE_STORE_NAME);
            }
        }
    });
    final int size = names.size();
    System.out.println("Done. Stores found: " + size);
    int i = 0;
    for (final String name : names) {
        System.out.println("Traversing store " + name + " (" + ++i + " of " + size + ')');
        try {
            env.executeInTransaction(new TransactionalExecutable() {
                @Override
                public void execute(@NotNull final Transaction txn) {
                    final StoreImpl store = env.openStore(name, StoreConfig.USE_EXISTING, txn);
                    int storeSize = 0;
                    try (Cursor cursor = store.openCursor(txn)) {
                        while (cursor.getNext()) {
                            ++storeSize;
                        }
                    }
                    final ITree tree = ((TransactionImpl) txn).getTree(store);
                    fetchUsedSpace(tree.addressIterator(), usedSpace);
                    if (tree.getSize() != storeSize) {
                        logging.error("Stored size (" + tree.getSize() + ") isn't equal to actual size ("
                                + storeSize + ')');
                    }
                }
            });
        } catch (Throwable t) {
            System.out.println();
            logging.error("Can't fetch used space for store " + name, t);
        }
    }
    System.out.println();
    spaceInfo(usedSpace.entrySet());
}

From source file:org.apache.hadoop.mapred.HFSPScheduler.java

private void assignSizeBasedTasks(TaskType type, HelperForType helper,
        TreeMap<JobDurationInfo, JobInProgress> sizeBasedJobs,
        TreeMap<JobDurationInfo, TaskStatuses> taskStatusesSizeBased) throws IOException {

    final boolean isMap = type == TaskType.MAP;
    int totClaimedSlots = 0;

    // StringBuilder builder = new StringBuilder("SBJobs(");
    // builder.append(type).append("): [");
    // boolean first = true;
    // for (Entry<JobDurationInfo,JobInProgress> jip : sizeBasedJobs.entrySet())
    // {/*from   w  w w.j ava2s .  c  om*/
    // if (first)
    // first = false;
    // else
    // builder.append(",");
    // builder.append(jip.getValue().getJobID())
    // .append(" -> ")
    // .append(jip.getKey().getPhaseDuration())
    // .append("/")
    // .append(jip.getKey().getPhaseTotalDuration())
    // .append(" p: ")
    // .append(this.getNumPendingNewTasks(jip.getValue(), type))
    // .append(" r: ")
    // .append(this.getNumRunningTasks(jip.getValue(), type))
    // .append(" f: ")
    // .append(this.getNumFinishedTasks(jip.getValue(), type));
    // }
    // builder.append("]");
    // LOG.debug(builder.toString());

    for (Entry<JobDurationInfo, JobInProgress> entry : sizeBasedJobs.entrySet()) {

        JobInProgress jip = entry.getValue();
        JobDurationInfo jdi = entry.getKey();
        TaskStatuses taskStatuses = taskStatusesSizeBased.get(jdi);

        if (!this.isJobReadyForTypeScheduling(jip, type)) {
            if (LOG.isDebugEnabled() && jip.getStatus().getRunState() != JobStatus.SUCCEEDED) {
                LOG.debug(
                        "SIZEBASED(" + jip.getJobID() + ":" + type + "):" + "job is not ready for scheduling ("
                                + "status: " + JobStatus.getJobRunState(jip.getStatus().getRunState())
                                + ", mapProgress: " + jip.getStatus().mapProgress() + ", reduceProgress: "
                                + jip.getStatus().reduceProgress() + ", scheduleReduces: "
                                + jip.scheduleReduces() + ")");
            }
            continue;
        }

        // NEW
        int pendingNewTasks = this.getNumPendingNewTasks(jip, type);
        int pendingResumableTasks = (taskStatuses == null) ? 0 : taskStatuses.suspendedTaskStatuses.size();

        int totAvailableSizeBasedSlots = helper.totAvailableSizeBasedSlots();

        // missing slots for resumable
        int missingResumableSlots = 0;
        if (pendingResumableTasks > 0 && pendingResumableTasks > totAvailableSizeBasedSlots) {
            if (totAvailableSizeBasedSlots <= 0)
                missingResumableSlots = pendingResumableTasks;
            else
                missingResumableSlots = pendingResumableTasks - totAvailableSizeBasedSlots;
            totAvailableSizeBasedSlots = (pendingResumableTasks > totAvailableSizeBasedSlots) ? 0
                    : totAvailableSizeBasedSlots - pendingResumableTasks;
        }

        int missingNewSlots = 0;
        if (pendingNewTasks > 0 && pendingNewTasks > totAvailableSizeBasedSlots) {
            if (totAvailableSizeBasedSlots <= 0)
                missingNewSlots = pendingNewTasks;
            else
                missingNewSlots = pendingNewTasks - totAvailableSizeBasedSlots;
            totAvailableSizeBasedSlots = (pendingNewTasks > totAvailableSizeBasedSlots) ? 0
                    : totAvailableSizeBasedSlots - pendingNewTasks;
        }

        TreeMap<TaskAttemptID, TaskStatus> suspended = null;
        if (taskStatuses != null)
            suspended = taskStatuses.suspendedTaskStatuses;

        if (pendingNewTasks > 0 || pendingResumableTasks > 0 || (suspended != null && !suspended.isEmpty())) {
            LOG.debug(jip.getJobID() + ":" + type + " (d: " + jdi.getPhaseDuration() + "/"
                    + jdi.getPhaseTotalDuration() + "):" + " pendingNewTasks: " + pendingNewTasks
                    + " pendingResumableTasks: " + pendingResumableTasks
                    // + " notResumableTasksOnThisTT: " + notResumableTasks
                    + " totAvailableSizeBasedSlots: "
                    + (helper.totAvailableSizeBasedSlots() <= 0 ? 0 : helper.totAvailableSizeBasedSlots())
                    + " currAvailableSlots: " + helper.currAvailableSlots + " => missingNewSlots: "
                    + missingNewSlots + " missingResumableSlots: " + missingResumableSlots);
        }

        if (this.preemptionStrategy.isPreemptionActive()
                && (missingNewSlots > 0 || missingResumableSlots > 0)) {
            ClaimedSlots claimedSlots = this.claimSlots(helper, Phase.SIZE_BASED, jip, missingNewSlots,
                    missingResumableSlots, totClaimedSlots, sizeBasedJobs, taskStatusesSizeBased);

            totClaimedSlots += claimedSlots.getNumPreemptedForNewTasks()
                    + claimedSlots.getNumPreemptedForResumableTasks();

            LOG.debug(jip.getJobID() + " taskStatusesOnTT: " + taskStatusesSizeBased.get(jdi)
                    + " pendingNewTasks: " + pendingNewTasks + " pendingResumableTasks: "
                    + pendingResumableTasks + " missingNewSlots: " + missingNewSlots
                    + " missingResumableSlots: " + missingResumableSlots);
        }

        while (pendingNewTasks > 0 || pendingResumableTasks > 0
                || (suspended != null && !suspended.isEmpty())) {

            if (helper.currAvailableSlots <= 0) {
                LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " no slots available on "
                        + taskHelper.ttStatus.getTrackerName());
                return;
            }

            LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " totAvailableSizeBasedSlots(): "
                    + helper.totAvailableSizeBasedSlots() + " pendingNewTasks: " + pendingNewTasks
                    + " pendingResumableTasks: " + pendingResumableTasks + " suspended("
                    + (suspended == null ? 0 : suspended.size()) + "): " + suspended);

            if (this.preemptionStrategy.isPreemptionActive() && (suspended != null && !suspended.isEmpty())) {
                TaskStatus toResume = suspended.remove(suspended.firstKey());
                // LOG.debug("RESUME: " + toResume.getTaskID() + " " +
                // toResume.getRunState());
                TaskAttemptID tAID = toResume.getTaskID();
                JobInProgress rJIP = this.taskTrackerManager.getJob(tAID.getTaskID().getJobID());
                TaskInProgress tip = rJIP.getTaskInProgress(tAID.getTaskID());
                if (this.preemptionStrategy.resume(tip, toResume)) {
                    taskHelper.resume(tAID, Phase.SIZE_BASED);
                    pendingResumableTasks -= 1;
                } else {
                    LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " cannot resume " + tAID
                            + " on " + taskHelper.ttStatus.getTrackerName());
                }
            } else {

                Task task = this.obtainNewTask(jip, taskHelper.ttStatus, isMap, taskHelper.currentTime);

                if (task == null) {
                    LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):"
                            + " cannot obtain slot for new task on " + taskHelper.ttStatus.getTrackerName()
                            + " (#pendingNew: " + pendingNewTasks + ", #pendingResumable: "
                            + pendingResumableTasks + ", #free_" + type + "_slots: " + helper.currAvailableSlots
                            + ")");
                    break;
                }

                taskHelper.slotObtained(task, Phase.SIZE_BASED);
                pendingNewTasks -= 1;
            }
        }
    }
}

From source file:org.alfresco.repo.domain.propval.AbstractPropertyValueDAOImpl.java

@SuppressWarnings("unchecked")
public Serializable convertPropertyIdSearchRows(List<PropertyIdSearchRow> rows) {
    // Shortcut if there are no results
    if (rows.size() == 0) {
        return null;
    }// w w w. j  a va  2s  .  co m
    /*
     * The results all share the same root property.  Pass through the results and construct all
     * instances, storing them ordered by prop_index.
     */
    Map<Long, Serializable> valuesByPropIndex = new HashMap<Long, Serializable>(7);
    TreeMap<Long, PropertyLinkEntity> linkEntitiesByPropIndex = new TreeMap<Long, PropertyLinkEntity>();
    Long rootPropId = null; // Keep this to ensure the root_prop_id is common
    for (PropertyIdSearchRow row : rows) {
        // Check that we are handling a single root property
        if (rootPropId == null) {
            rootPropId = row.getLinkEntity().getRootPropId();
        } else if (!rootPropId.equals(row.getLinkEntity().getRootPropId())) {
            throw new IllegalArgumentException(
                    "The root_prop_id for the property search rows must not change: \n" + "   Rows: " + rows);
        }

        PropertyLinkEntity linkEntity = row.getLinkEntity();
        Long propIndex = linkEntity.getPropIndex();
        Long valuePropId = linkEntity.getValuePropId();
        PropertyValueEntity valueEntity = row.getValueEntity();
        // Get the value
        Serializable value;
        if (valueEntity != null) {
            value = propertyValueCallback.convertToValue(valueEntity);
        } else {
            // Go N+1 if the value entity was not retrieved
            value = getPropertyValueById(valuePropId);
        }
        // Keep it for later
        valuesByPropIndex.put(propIndex, value);
        linkEntitiesByPropIndex.put(propIndex, linkEntity);
    }

    Serializable result = null;
    // Iterate again, adding values to the collections and looking for the root property
    for (Map.Entry<Long, PropertyLinkEntity> entry : linkEntitiesByPropIndex.entrySet()) {
        PropertyLinkEntity linkEntity = entry.getValue();
        Long propIndex = linkEntity.getPropIndex();
        Long containedIn = linkEntity.getContainedIn();
        Long keyPropId = linkEntity.getKeyPropId();
        Serializable value = valuesByPropIndex.get(propIndex);
        // Check if this is the root property
        if (propIndex.equals(containedIn)) {
            if (result != null) {
                logger.error("Found inconsistent property root data: " + linkEntity);
                continue;
            }
            // This property is contained in itself i.e. it's the root
            result = value;
        } else {
            // Add the value to the container to which it belongs.
            // The ordering is irrelevant for some containers; but where it is important,
            // ordering given by the prop_index will ensure that values are added back
            // in the order in which the container originally iterated over them
            Serializable container = valuesByPropIndex.get(containedIn);
            if (container == null) {
                logger.error("Found container ID that doesn't have a value: " + linkEntity);
            } else if (container instanceof Map<?, ?>) {
                Map<Serializable, Serializable> map = (Map<Serializable, Serializable>) container;
                Serializable mapKey = getPropertyValueById(keyPropId).getSecond();
                map.put(mapKey, value);
            } else if (container instanceof Collection<?>) {
                Collection<Serializable> collection = (Collection<Serializable>) container;
                collection.add(value);
            } else {
                logger.error("Found container ID that is not a map or collection: " + linkEntity);
            }
        }
    }
    // This will have put the values into the correct containers
    return result;
}

From source file:com.espertech.esper.rowregex.EventRowRegexNFAView.java

/**
 * Ctor.//from  w  w w  .  jav a2 s.  c  o m
 * @param compositeEventType final event type
 * @param rowEventType event type for input rows
 * @param matchRecognizeSpec specification
 * @param variableStreams variables and their assigned stream number
 * @param streamsVariables stream number and the assigned variable
 * @param variablesSingle single variables
 * @param callbacksPerIndex  for handling the 'prev' function
 * @param aggregationService handles aggregations
 * @param isUnbound true if unbound stream
 * @param isIterateOnly true for iterate-only
 * @param isSelectAsksMultimatches if asking for multimatches
 */
public EventRowRegexNFAView(EventType compositeEventType, EventType rowEventType,
        MatchRecognizeSpec matchRecognizeSpec, LinkedHashMap<String, Pair<Integer, Boolean>> variableStreams,
        Map<Integer, String> streamsVariables, Set<String> variablesSingle,
        AgentInstanceContext agentInstanceContext,
        TreeMap<Integer, List<ExprPreviousMatchRecognizeNode>> callbacksPerIndex,
        AggregationServiceMatchRecognize aggregationService, boolean isUnbound, boolean isIterateOnly,
        boolean isSelectAsksMultimatches) {
    this.matchRecognizeSpec = matchRecognizeSpec;
    this.compositeEventType = compositeEventType;
    this.rowEventType = rowEventType;
    this.variableStreams = variableStreams;
    this.variablesArray = variableStreams.keySet().toArray(new String[variableStreams.keySet().size()]);
    this.streamsVariables = streamsVariables;
    this.variablesSingle = variablesSingle;
    this.aggregationService = aggregationService;
    this.isUnbound = isUnbound;
    this.isIterateOnly = isIterateOnly;
    this.agentInstanceContext = agentInstanceContext;
    this.isSelectAsksMultimatches = isSelectAsksMultimatches;

    if (matchRecognizeSpec.getInterval() != null) {
        scheduleSlot = agentInstanceContext.getStatementContext().getScheduleBucket().allocateSlot();
        ScheduleHandleCallback callback = new ScheduleHandleCallback() {
            public void scheduledTrigger(ExtensionServicesContext extensionServicesContext) {
                EventRowRegexNFAView.this.triggered();
            }
        };
        handle = new EPStatementHandleCallback(agentInstanceContext.getEpStatementAgentInstanceHandle(),
                callback);
        schedule = new TreeMap<Long, Object>();

        agentInstanceContext.addTerminationCallback(this);
    } else {
        scheduleSlot = null;
        handle = null;
        schedule = null;
    }

    this.windowMatchedEventset = new LinkedHashSet<EventBean>();

    // handle "previous" function nodes (performance-optimized for direct index access)
    RegexPartitionStateRandomAccessGetter randomAccessByIndexGetter;
    if (!callbacksPerIndex.isEmpty()) {
        // Build an array of indexes
        int[] randomAccessIndexesRequested = new int[callbacksPerIndex.size()];
        int count = 0;
        for (Map.Entry<Integer, List<ExprPreviousMatchRecognizeNode>> entry : callbacksPerIndex.entrySet()) {
            randomAccessIndexesRequested[count] = entry.getKey();
            count++;
        }
        randomAccessByIndexGetter = new RegexPartitionStateRandomAccessGetter(randomAccessIndexesRequested,
                isUnbound);

        // Since an expression such as "prior(2, price), prior(8, price)" translates into {2, 8} the relative index is {0, 1}.
        // Map the expression-supplied index to a relative index
        count = 0;
        for (Map.Entry<Integer, List<ExprPreviousMatchRecognizeNode>> entry : callbacksPerIndex.entrySet()) {
            for (ExprPreviousMatchRecognizeNode callback : entry.getValue()) {
                callback.setGetter(randomAccessByIndexGetter);
                callback.setAssignedIndex(count);
            }
            count++;
        }
    } else {
        randomAccessByIndexGetter = null;
    }

    Map<String, ExprNode> variableDefinitions = new LinkedHashMap<String, ExprNode>();
    for (MatchRecognizeDefineItem defineItem : matchRecognizeSpec.getDefines()) {
        variableDefinitions.put(defineItem.getIdentifier(), defineItem.getExpression());
    }

    // build states
    RegexNFAStrandResult strand = EventRowRegexHelper.recursiveBuildStartStates(matchRecognizeSpec.getPattern(),
            variableDefinitions, variableStreams);
    startStates = strand.getStartStates().toArray(new RegexNFAState[strand.getStartStates().size()]);
    allStates = strand.getAllStates().toArray(new RegexNFAState[strand.getAllStates().size()]);

    if (log.isDebugEnabled() || IS_DEBUG) {
        log.info("NFA tree:\n" + print(startStates));
    }

    // create evaluators
    columnNames = new String[matchRecognizeSpec.getMeasures().size()];
    columnEvaluators = new ExprEvaluator[matchRecognizeSpec.getMeasures().size()];
    int count = 0;
    for (MatchRecognizeMeasureItem measureItem : matchRecognizeSpec.getMeasures()) {
        columnNames[count] = measureItem.getName();
        columnEvaluators[count] = measureItem.getExpr().getExprEvaluator();
        count++;
    }

    // create state repository
    if (this.matchRecognizeSpec.getPartitionByExpressions().isEmpty()) {
        regexPartitionStateRepo = new RegexPartitionStateRepoNoGroup(randomAccessByIndexGetter,
                matchRecognizeSpec.getInterval() != null);
    } else {
        regexPartitionStateRepo = new RegexPartitionStateRepoGroup(randomAccessByIndexGetter,
                ExprNodeUtility.getEvaluators(matchRecognizeSpec.getPartitionByExpressions()),
                matchRecognizeSpec.getInterval() != null, agentInstanceContext);
    }
}

From source file:dev.memento.MainActivity.java

@Override
protected Dialog onCreateDialog(int id) {

    Dialog dialog = null;/* w w  w.java 2  s .c o  m*/
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    switch (id) {

    case DIALOG_ERROR:
        builder.setMessage("error message").setCancelable(false).setPositiveButton("OK", null);
        dialog = builder.create();
        break;

    case DIALOG_MEMENTO_YEARS:
        builder.setTitle(R.string.select_year);
        final TreeMap<Integer, Integer> yearCount = mMementos.getAllYears();
        if (Log.LOG)
            Log.d(LOG_TAG, "Dialog: num of years = " + yearCount.size());

        // This shouldn't happen, but just in case
        if (yearCount.size() == 0) {
            showToast("There are no years to choose from... something is wrong.");
            if (Log.LOG)
                Log.d(LOG_TAG, "Num of mementos: " + mMementos.size());
            return null;
        }

        // Build a list that shows how many dates are available for each year
        final CharSequence[] yearText = new CharSequence[yearCount.size()];

        // Parallel arrays used to determine which entry was selected.
        // Could also have used a regular expression.
        final int years[] = new int[yearCount.size()];
        final int count[] = new int[yearCount.size()];

        int selectedYear = -1;
        int displayYear = mDateDisplayed.getYear();
        int i = 0;
        for (Map.Entry<Integer, Integer> entry : yearCount.entrySet()) {
            Integer year = entry.getKey();

            // Select the year of the Memento currently displayed
            if (displayYear == year)
                selectedYear = i;

            years[i] = year;
            count[i] = entry.getValue();
            yearText[i] = Integer.toString(year) + " (" + entry.getValue() + ")";
            i++;
        }

        builder.setSingleChoiceItems(yearText, selectedYear, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                mSelectedYear = years[item];
                int numItems = count[item];

                if (numItems > MAX_NUM_MEMENTOS_PER_MONTH)
                    showDialog(DIALOG_MEMENTO_MONTHS);
                else
                    showDialog(DIALOG_MEMENTO_DATES);
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_YEARS);
            }
        });

        break;

    case DIALOG_MEMENTO_MONTHS:
        builder.setTitle(R.string.select_month);
        final LinkedHashMap<CharSequence, Integer> monthCount = mMementos.getMonthsForYear(mSelectedYear);

        // This shouldn't happen, but just in case
        if (monthCount.size() == 0) {
            showToast("There are no months to choose from... something is wrong.");
            if (Log.LOG)
                Log.d(LOG_TAG, "Num of mementos: " + mMementos.size());
            return null;
        }

        // Build a list that shows how many dates are available for each month
        final CharSequence[] monthText = new CharSequence[monthCount.size()];

        int selectedMonth = mDateDisplayed.getMonth() - 1;
        i = 0;
        for (Map.Entry<CharSequence, Integer> entry : monthCount.entrySet()) {
            CharSequence month = entry.getKey();

            monthText[i] = month + " (" + entry.getValue() + ")";
            i++;
        }

        builder.setSingleChoiceItems(monthText, selectedMonth, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                // Pull out month name so we can map it back to a number.
                // This is ugly, but it's necessary because the LinkedHashMap doesn't
                // give back the order of its keys.

                Pattern r = Pattern.compile("^(.+) ");
                Matcher m = r.matcher(monthText[item]);
                if (m.find()) {
                    String month = m.group(1);

                    mSelectedMonth = Utilities.monthStringToInt(month);
                    showDialog(DIALOG_MEMENTO_DATES);
                } else {
                    if (Log.LOG)
                        Log.e(LOG_TAG, "Could not find month in [" + monthText[item] + "]");
                }
            }
        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_MONTHS);
            }
        });

        break;

    case DIALOG_MEMENTO_DATES:

        builder.setTitle(R.string.select_day);

        // Which radio button is selected?
        int selected = -1;

        final CharSequence[] dates;

        if (Log.LOG)
            Log.d(LOG_TAG, "mSelectedMonth = " + mSelectedMonth);
        if (Log.LOG)
            Log.d(LOG_TAG, "mSelectedYear = " + mSelectedYear);

        final Memento[] mementoList;

        // See if there is a month/year filter 
        if (mSelectedMonth != -1 || mSelectedYear != -1) {

            if (mSelectedMonth != -1)
                mementoList = mMementos.getByMonthAndYear(mSelectedMonth, mSelectedYear);
            else
                mementoList = mMementos.getByYear(mSelectedYear);

            if (Log.LOG)
                Log.d(LOG_TAG, "Number of dates = " + mementoList.length);

            // Get dates for selected mementos
            dates = new CharSequence[mementoList.length];
            i = 0;
            for (Memento m : mementoList) {
                dates[i] = m.getDateAndTimeFormatted();
                i++;
            }

            // See if any of these items match.  This could take a little while if
            // there are a large number of items unfortunately.
            Memento m = mMementos.getCurrent();
            if (m != null) {
                CharSequence searchDate = m.getDateAndTimeFormatted();
                for (i = 0; i < dates.length; i++) {
                    if (searchDate.equals(dates[i])) {
                        selected = i;
                        break;
                    }
                }
            }
        } else {
            // No filter, so get all available mementos
            dates = mMementos.getAllDates();
            if (Log.LOG)
                Log.d(LOG_TAG, "Number of dates = " + dates.length);
            selected = mMementos.getCurrentIndex();
            mementoList = mMementos.toArray(new Memento[0]);
        }

        if (Log.LOG)
            Log.d(LOG_TAG, "Selected index = " + selected);

        // Reset for future selections
        mSelectedYear = -1;
        mSelectedMonth = -1;

        builder.setSingleChoiceItems(dates, selected, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                dialog.dismiss();

                // Display this Memento
                Memento m = mementoList[item];
                mCurrentMemento = m;
                final SimpleDateTime dateSelected = m.getDateTime();
                mDateDisplayed = dateSelected;
                setChosenDate(mDateDisplayed);
                if (Log.LOG)
                    Log.d(LOG_TAG, "User selected Memento with date " + dateSelected.dateFormatted());
                showToast("Time traveling to " + mDateDisplayed.dateFormatted());
                refreshDisplayedDate();

                // Load memento into the browser                 
                String redirectUrl = m.getUrl();
                surfToUrl(redirectUrl);

                setEnableForNextPrevButtons();
                mNowButton.setEnabled(true);

                // Potentially lengthly operation

                new Thread() {
                    public void run() {
                        int index = mMementos.getIndex(dateSelected);
                        if (index == -1) {
                            // This should never happen
                            if (Log.LOG)
                                Log.e(LOG_TAG, "!! Couldn't find " + dateSelected + " in the memento list!");
                        } else
                            mMementos.setCurrentIndex(index);
                    }
                }.start();
            }

        });

        dialog = builder.create();

        // Cause the dialog to be freed whenever it is dismissed.
        // This is necessary because the items are dynamic.  I couldn't find
        // a better way to solve this problem.
        dialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface arg0) {
                removeDialog(DIALOG_MEMENTO_DATES);
            }
        });

        break;
    }

    return dialog;
}