Example usage for java.util TreeMap get

List of usage examples for java.util TreeMap get

Introduction

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

Prototype

public V get(Object key) 

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartValues(Iterator<TestStepInstance> values) {
    if (values == null || !values.hasNext()) {
        return null;
    }/*w  ww  .j  a  v a  2  s.c o  m*/

    XYSeriesCollection dataset = new XYSeriesCollection();
    int count = 0;
    TreeMap<String, XYSeries> map = new TreeMap<String, XYSeries>();
    while (values.hasNext()) {
        TestStepInstance step = values.next();
        Number num = getNumber(step);
        if (num != null) {
            String groupName = getGroupName(step);
            XYSeries pop = map.get(groupName);
            if (pop == null) {
                pop = new XYSeries(groupName);
                map.put(groupName, pop);
            }

            pop.add(++count, num.doubleValue());
        }

    }
    for (Iterator<XYSeries> it = map.values().iterator(); it.hasNext();) {
        dataset.addSeries(it.next());
    }

    //        NumberAxis xAxis = new NumberAxis("#");
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(getValueString());
    yAxis.setAutoRangeIncludesZero(false);
    XYLineAndShapeRenderer renderer6 = new XYLineAndShapeRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer6);
    plot.setOrientation(PlotOrientation.VERTICAL);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairVisible(true);
    renderer6.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer6.setBaseSeriesVisibleInLegend(false);

    //        StandardXYItemLabelGenerator itemlabels=new StandardXYItemLabelGenerator();
    //        renderer.setBaseItemLabelGenerator(itemlabels);
    //        renderer.setBaseItemLabelsVisible(true);

    JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, isGrouping());
    //chart.setTitle(title);
    placeLimitMarkers(plot, true);
    /* coloring */
    if (isCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            Color c = ChartCategories.getColor(i);
            for (int j = 0; j < dataset.getSeriesCount(); j++) {
                XYSeries s = dataset.getSeries(j);
                if (s.getKey().equals(groupName)) {
                    renderer6.setSeriesPaint(j, c);
                }
            }
        }
    } else {
        renderer6.setSeriesPaint(0, ChartCategories.getColor(0));
    }
    chart.setTextAntiAlias(false);
    return chart;
}

From source file:ca.sqlpower.sqlobject.TestSQLTable.java

public void testGetDerivedInstance() throws Exception {
    SQLTable derivedTable;/*from w  w w  . j ava  2  s  .  com*/
    SQLTable table1;
    // Check to make sure it can be added to a playpen like database
    SQLDatabase pp = new SQLDatabase();
    pp.setPlayPenDatabase(true);
    pp.setParent(new StubSQLObject());
    assertNotNull(table1 = db.getTableByName("REGRESSION_TEST1"));
    derivedTable = table1.createInheritingInstance(pp);

    TreeMap<String, Object> derivedPropertyMap = new TreeMap<String, Object>(BeanUtils.describe(derivedTable));
    TreeMap<String, Object> table1PropertyMap = new TreeMap<String, Object>(BeanUtils.describe(table1));

    table1PropertyMap.remove("parent");
    table1PropertyMap.remove("SQLParent");
    table1PropertyMap.remove("schemaName");
    table1PropertyMap.remove("schema");
    table1PropertyMap.remove("parentDatabase");
    table1PropertyMap.remove("shortDisplayName");
    table1PropertyMap.remove("UUID");
    table1PropertyMap.remove("workspaceContainer");
    table1PropertyMap.remove("runnableDispatcher");
    table1PropertyMap.remove("SPListeners");

    for (Map.Entry<String, Object> property : table1PropertyMap.entrySet()) {
        assertEquals("Property \"" + property.getKey() + "\" has changed;", property.getValue(),
                derivedPropertyMap.get(property.getKey()));
    }

}

From source file:org.commoncrawl.service.listcrawler.CrawlHistoryManager.java

private static void testWriteMapFileToHDFS(EventLoop eventLoop) {
    try {//from  w ww  .  ja  v a2  s  .c  o  m
        // initialize log manager
        CrawlHistoryManager logManager = initializeTestLogManager(eventLoop, true);

        // initialize item list
        TreeMap<URLFP, ProxyCrawlHistoryItem> items = buildTestList(urlList1);
        final TreeMap<String, URLFP> urlToURLFPMap = new TreeMap<String, URLFP>();

        for (Map.Entry<URLFP, ProxyCrawlHistoryItem> item : items.entrySet()) {
            urlToURLFPMap.put(item.getValue().getOriginalURL(), item.getKey());
        }

        // add to local item map in log manager
        for (ProxyCrawlHistoryItem item : items.values()) {
            logManager.appendItemToLog(item);
        }
        // ok shutdown log manager ...
        logManager.shutdown();

        // restart - reload log file ...
        logManager = initializeTestLogManager(eventLoop, false);

        // write to 'hdfs'
        logManager.doCheckpoint();

        syncAndValidateItems(items, logManager);

        logManager.shutdown();

        // restart
        logManager = initializeTestLogManager(eventLoop, false);

        // tweak original items
        updateTestItemStates(items);

        // ok append items
        for (ProxyCrawlHistoryItem item : items.values()) {
            logManager.appendItemToLog(item);
        }

        syncAndValidateItems(items, logManager);

        // ok now checkpoint the items
        logManager.doCheckpoint();

        // ok now validate one last time
        syncAndValidateItems(items, logManager);

        // shutown
        logManager.shutdown();

        logManager = null;

        {
            // start from scratch ...
            final CrawlHistoryManager logManagerTest = initializeTestLogManager(eventLoop, true);

            // create a final version of the tree map reference
            final TreeMap<URLFP, ProxyCrawlHistoryItem> itemList = items;
            // create filename
            File urlInputFile = new File(logManagerTest.getLocalDataDir(),
                    "testURLS-" + System.currentTimeMillis());
            // ok create a crawl list from urls
            CrawlList.generateTestURLFile(urlInputFile, urlList1);
            long listId = logManagerTest.loadList(urlInputFile, 0);

            CrawlList listObject = logManagerTest.getList(listId);

            final Semaphore listCompletionSemaphore = new Semaphore(-(itemList.size() - 1));

            listObject.setEventListener(new CrawlList.CrawlListEvents() {

                @Override
                public void itemUpdated(URLFP itemFingerprint) {
                    // TODO Auto-generated method stub
                    listCompletionSemaphore.release();
                }
            });

            // ok start the appropriate threads
            logManagerTest.startLogWriterThread(0);
            logManagerTest.startListLoaderThread();
            logManagerTest.startQueueLoaderThread(new CrawlQueueLoader() {

                @Override
                public void queueURL(URLFP urlfp, String url) {
                    logManagerTest.crawlComplete(
                            proxyCrawlHitoryItemToCrawlURL(itemList.get(urlToURLFPMap.get(url))));
                }

                @Override
                public void flush() {
                    // TODO Auto-generated method stub

                }
            });

            LOG.info("Waiting for Release");

            // and wait for the finish
            listCompletionSemaphore.acquireUninterruptibly();

            LOG.info("Got Here");

        }

    } catch (IOException e) {
        LOG.error(CCStringUtils.stringifyException(e));
    }
}

From source file:com.vgi.mafscaling.OpenLoop.java

private boolean sortRunData(TreeMap<Integer, ArrayList<Double>> result) {
    int closestVoltIdx;
    double rpm;//  www. ja  va  2  s.c om
    double voltage;
    double error;
    ArrayList<Double> closestVolatageArray;
    for (int i = 0; i < runTables.length; ++i) {
        JTable table = runTables[i];
        String tableName = RunTableName + (i + 1);
        String rpmValue;
        String mafvValue;
        String afrValue;
        for (int j = 0; j < table.getRowCount(); ++j) {
            rpmValue = table.getValueAt(j, 0).toString();
            mafvValue = table.getValueAt(j, 1).toString();
            afrValue = table.getValueAt(j, 2).toString();
            if (rpmValue.isEmpty() || mafvValue.isEmpty() || afrValue.isEmpty())
                continue;
            if (!Utils.validateDouble(rpmValue, j, 0, tableName)
                    || !Utils.validateDouble(mafvValue, j, 1, tableName)
                    || !Utils.validateDouble(afrValue, j, 2, tableName))
                return false;
            rpm = Double.parseDouble(rpmValue);
            voltage = Double.parseDouble(mafvValue);
            error = Double.parseDouble(afrValue);
            rpmArray.add(rpm);
            mafvArray.add(voltage);
            afrArray.add(error);
            closestVoltIdx = Utils.closestValueIndex(voltage, voltArray);
            closestVolatageArray = result.get(closestVoltIdx);
            if (closestVolatageArray == null) {
                closestVolatageArray = new ArrayList<Double>();
                result.put(closestVoltIdx, closestVolatageArray);
            }
            closestVolatageArray.add(error);
        }
    }
    return true;
}

From source file:biblivre3.administration.ReportsDAO.java

public TreeMap<String, Set<Integer>> searchAuthors(String authorName) {
    TreeMap<String, Set<Integer>> results = new TreeMap<String, Set<Integer>>();

    String[] terms = authorName.split(" ");
    Connection con = null;// w w  w . ja  v a  2 s  .  c o  m
    try {
        con = getDataSource().getConnection();
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT DISTINCT B.record_serial, B.record FROM cataloging_biblio B ");
        sql.append("INNER JOIN idx_author I ON I.record_serial = B.record_serial WHERE B.database = 0 ");

        for (int i = 0; i < terms.length; i++) {
            sql.append(
                    "AND B.record_serial in (SELECT record_serial FROM idx_author WHERE index_word >= ? and index_word < ?) ");
        }

        PreparedStatement st = con.prepareStatement(sql.toString());
        int index = 1;
        for (int i = 0; i < terms.length; i++) {
            st.setString(index++, terms[i]);
            st.setString(index++, TextUtils.incrementLastChar(terms[i]));
        }

        ResultSet rs = st.executeQuery();
        if (rs != null) {
            while (rs.next()) {
                Integer id = rs.getInt("record_serial");
                String iso2709 = new String(rs.getBytes("record"), "UTF-8");
                Record record = MarcUtils.iso2709ToRecord(iso2709);
                String name = Indexer.listPrimaryAuthor(record);
                if (results.containsKey(name)) {
                    Set<Integer> ids = results.get(name);
                    ids.add(id);
                } else {
                    Set<Integer> ids = new HashSet<Integer>();
                    ids.add(id);
                    results.put(name, ids);
                }
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        throw new ExceptionUser("ERROR_REPORT_DAO_EXCEPTION");
    } finally {
        closeConnection(con);
    }
    return results;
}

From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.Comparison.java

/**
 * Aim is to produce an aggregated data set for comparison totalling males
 * and females by MSOA to compare with CASUV003DataRecord
 *///  ww  w  .  j av  a2 s . c o m
private void run3() throws IOException {
    boolean aggregateToMSOA = true;
    // boolean aggregateToMSOA = false;
    ToyModelDataHandler tToyModelDataHandler = new ToyModelDataHandler();
    String startOfFilename = "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_HSARHP_ISARCEP_0_5_5000_3_30_12_20";
    // String startOfFilename = new String(
    // "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_HSARHP_ISARCEP_0_5_1000_3_30_12_20"
    // );
    // String startOfFilename = new String(
    // "C:/Work/Projects/MoSeS/Workspace/Leeds/ToyModel_SWR_OA_ISARHP_ISARCEP_0_5_200_3_30_12_20"
    // );
    File tToyModelDataRecord2CSVFile = new File(startOfFilename + ".csv");
    File tToyModelDataRecordMaleFemaleComparisonFile;
    if (aggregateToMSOA) {
        tToyModelDataRecordMaleFemaleComparisonFile = new File(
                startOfFilename + "_MSOAMaleFemaleComparison.csv");
    } else {
        tToyModelDataRecordMaleFemaleComparisonFile = new File(startOfFilename + "_OAMaleFemaleComparison.csv");
    }
    if (!tToyModelDataRecordMaleFemaleComparisonFile.exists()) {
        tToyModelDataRecordMaleFemaleComparisonFile.createNewFile();
    }
    PrintWriter tToyModelDataRecordMaleFemaleComparisonFilePrintWriter = new PrintWriter(
            tToyModelDataRecordMaleFemaleComparisonFile);
    // CASUV003DataHandler tCASUV003DataHandler = new CASUV003DataHandler(
    // new File(
    // "C:/Work/Projects/MoSeS/Workspace/Leeds/CASUV003DataRecordsMSOA.dat"
    // ) );
    CASUV003DataHandler tCASUV003DataHandler;
    CAS001DataHandler tCAS001DataHandler;
    if (aggregateToMSOA) {
        tCASUV003DataHandler = new CASUV003DataHandler(
                new File("C:/Work/Projects/MoSeS/Workspace/Leeds/CASUV003DataRecordsMSOA.dat"));
        tCAS001DataHandler = new CAS001DataHandler(
                new File("C:/Work/Projects/MoSeS/Workspace/Leeds/CAS001DataRecordsMSOA.dat"));
    } else {
        tCASUV003DataHandler = new CASUV003DataHandler(
                new File("C:/Work/Projects/MoSeS/Workspace/CASUV003DataRecords.dat"));
        tCAS001DataHandler = new CAS001DataHandler(
                new File("C:/Work/Projects/MoSeS/Workspace/CAS001DataRecords.dat"));
    }
    CASUV003DataRecord aCASUV003DataRecord;
    CAS001DataRecord aCAS001DataRecord;
    BufferedReader tBufferedReader = new BufferedReader(
            new InputStreamReader(new FileInputStream(tToyModelDataRecord2CSVFile)));
    StreamTokenizer tStreamTokenizer = new StreamTokenizer(tBufferedReader);
    Generic_StaticIO.setStreamTokenizerSyntax1(tStreamTokenizer);
    // Initialise
    int tMaleCount;
    int tFemaleCount;
    int tMaleCEPCount;
    int tMaleHPCount;
    int tFemaleCEPCount;
    int tFemaleHPCount;
    int tokenType = tStreamTokenizer.nextToken();
    ToyModelDataRecord_2 aToyModelDataRecord2;
    String aZoneCode;
    HashMap tLookUpMSOAfromOAHashMap = null;
    CASDataHandler tCASDataHandler = new CASDataHandler();
    if (aggregateToMSOA) {
        tLookUpMSOAfromOAHashMap = tCASDataHandler.get_LookUpMSOAfromOAHashMap();
    }
    Counts aCounts;
    tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.println(
            "ZoneCode,CAS001HPFemales,CAS001CEPFemales,CAS001Females,CASUV003Females,ToyModelFemales,ToyModelHPFemales,ToyModelCEPFemales,CAS001HPMales,CAS001CEPMales,CAS001Males,CASUV003Males,ToyModelMales,ToyModelHPMales,ToyModelCEPMales");
    TreeMap result = new TreeMap();
    while (tokenType != StreamTokenizer.TT_EOF) {
        switch (tokenType) {
        case StreamTokenizer.TT_WORD:
            aToyModelDataRecord2 = new ToyModelDataRecord_2(tToyModelDataHandler, tStreamTokenizer.sval);
            if (aggregateToMSOA) {
                aZoneCode = (String) tLookUpMSOAfromOAHashMap
                        .get(new String(aToyModelDataRecord2.getZone_Code()));
            } else {
                aZoneCode = String.valueOf(aToyModelDataRecord2.getZone_Code());
            }
            if (aToyModelDataRecord2.SEX == 0) {
                tFemaleCount = 1;
                if (aToyModelDataRecord2.tHouseholdID != -9) {
                    tFemaleHPCount = 1;
                    tFemaleCEPCount = 0;
                } else {
                    tFemaleHPCount = 0;
                    tFemaleCEPCount = 1;
                }
                tMaleCount = 0;
                tMaleHPCount = 0;
                tMaleCEPCount = 0;
            } else {
                tMaleCount = 1;
                if (aToyModelDataRecord2.tHouseholdID != -9) {
                    tMaleHPCount = 1;
                    tMaleCEPCount = 0;
                } else {
                    tMaleHPCount = 0;
                    tMaleCEPCount = 1;
                }
                tFemaleCount = 0;
                tFemaleHPCount = 0;
                tFemaleCEPCount = 0;
            }
            if (result.containsKey(aZoneCode)) {
                aCounts = (Counts) result.get(aZoneCode);
                result.remove(aZoneCode);
                aCounts.addToCounts(tMaleCount, tMaleCEPCount, tMaleHPCount, tFemaleCount, tFemaleCEPCount,
                        tFemaleHPCount);
                result.put(aZoneCode, aCounts);
            } else {
                aCounts = new Counts();
                aCounts.addToCounts(tMaleCount, tMaleCEPCount, tMaleHPCount, tFemaleCount, tFemaleCEPCount,
                        tFemaleHPCount);
                result.put(aZoneCode, aCounts);
            }
        }
        tokenType = tStreamTokenizer.nextToken();
    }
    Iterator aIterator = result.keySet().iterator();
    Object key;
    while (aIterator.hasNext()) {
        key = aIterator.next();
        aCounts = (Counts) result.get(key);
        aZoneCode = (String) key;
        aCASUV003DataRecord = (CASUV003DataRecord) tCASUV003DataHandler.getDataRecord(aZoneCode);
        aCAS001DataRecord = (CAS001DataRecord) tCAS001DataHandler.getDataRecord(aZoneCode);
        tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.println("" + aZoneCode + ", "
                + aCAS001DataRecord.getHouseholdResidentsFemales() + ", "
                + aCAS001DataRecord.getCommunalEstablishmentResidentsFemales() + ", "
                + (aCAS001DataRecord.getHouseholdResidentsFemales()
                        + aCAS001DataRecord.getCommunalEstablishmentResidentsFemales())
                + ", " + aCASUV003DataRecord.getFemales() + ", " + aCounts.tFemaleCount + ", "
                + aCounts.tFemaleHPCount + ", " + aCounts.tFemaleCEPCount + ", "
                + aCAS001DataRecord.getHouseholdResidentsMales() + ", "
                + aCAS001DataRecord.getCommunalEstablishmentResidentsMales() + ", "
                + (aCAS001DataRecord.getHouseholdResidentsMales()
                        + aCAS001DataRecord.getCommunalEstablishmentResidentsMales())
                + ", " + aCASUV003DataRecord.getMales() + ", " + aCounts.tMaleCount + ", "
                + aCounts.tMaleHPCount + ", " + aCounts.tMaleCEPCount);
    }
    tBufferedReader.close();
    tToyModelDataRecordMaleFemaleComparisonFilePrintWriter.close();
}

From source file:com.jtstand.swing.StatsPanel.java

public JFreeChart getChartTime() {
    TreeMap<String, List<TestStepInstance>> s = getGroupedSteps(getFilteringIterator());
    if (s == null || s.size() == 0) {
        return null;
    }//from   w  ww . ja va  2s  . co  m
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    for (Iterator<String> en = s.keySet().iterator(); en.hasNext();) {
        String groupName = en.next();
        List<TestStepInstance> stps = s.get(groupName);
        //            TimeSeries pop = new TimeSeries(groupName, Millisecond.class);
        TimeSeries pop = new TimeSeries(groupName);
        for (Iterator<TestStepInstance> it = stps.iterator(); it.hasNext();) {
            TestStepInstance step = it.next();
            Number num = getNumber(step);
            if (num != null) {
                switch (chartMode) {
                case STEP_TIME:
                    pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class,
                            new Date(step.getStartTime()), TimeZone.getDefault()), num);
                    break;
                case SEQUENCE_TIME:
                    //                            pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date(step.getTestSequenceInstance().getStartTime()), RegularTimePeriod.DEFAULT_TIME_ZONE), num);
                    pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class,
                            new Date(step.getTestSequenceInstance().getCreateTime()), TimeZone.getDefault()),
                            num);
                    break;
                }
            }
        }
        dataset.addSeries(pop);
    }
    JFreeChart chart = null;
    switch (chartMode) {
    case STEP_TIME:
        chart = ChartFactory.createTimeSeriesChart(null, "Step Started Time", getValueString(), dataset,
                isGrouping(), true, false);
        break;
    case SEQUENCE_TIME:
        chart = ChartFactory.createTimeSeriesChart(null, "Sequence Started Time", getValueString(), dataset,
                isGrouping(), true, false);
        break;
    }
    chart.setBackgroundPaint((Paint) UIManager.get("Panel.background"));

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    XYLineAndShapeRenderer renderer5 = new XYLineAndShapeRenderer();
    renderer5.setBaseSeriesVisibleInLegend(false);
    plot.setRenderer(renderer5);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairVisible(true);
    //        chart.setTitle(valueName);
    placeLimitMarkers(plot, true);

    //renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer5.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance());

    /* coloring */
    if (isCategorization()) {
        //            TreeMap<String, Color> cmap = new TreeMap<String, Color>();
        int i = 0;
        for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) {
            String groupName = it.next();
            Color c = ChartCategories.getColor(i);
            for (int j = 0; j < dataset.getSeriesCount(); j++) {
                TimeSeries ts = dataset.getSeries(j);
                if (ts.getKey().equals(groupName)) {
                    renderer5.setSeriesPaint(j, c);
                }
            }
        }
    } else {
        renderer5.setSeriesPaint(0, ChartCategories.getColor(0));
    }

    //        chart.addProgressListener(new ChartProgressListener() {
    //
    //            public void chartProgress(final ChartProgressEvent progress) {
    //                SwingUtilities.invokeLater(
    //                        new Runnable() {
    //
    //                            @Override
    //                            public void run() {
    //
    //                                System.out.println("progress:" + progress + " " + progress.getType());
    //                                if (progress.getType() == ChartProgressEvent.DRAWING_FINISHED) {
    //                                    if (plot != null) {
    //                                        if (plot.isDomainCrosshairVisible() && plot.isDomainCrosshairLockedOnData()) {
    ////                            System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue());
    //                                            double xx = plot.getDomainCrosshairValue();
    //                                            if (xx != 0.0) {
    //                                                long x = (long) xx;
    //                                                System.out.println(new Date(x));
    //                                                for (TestStepInstance step : testStepInstances.getSteps()) {
    //                                                    if (step.getStartTime() != null && step.getStartTime().equals(x)) {
    //                                                        testStepInstances.selectStep(step);
    //                                                    }
    //                                                }
    //                                                System.out.println(new Date(x));
    //                                            }
    //                                        }
    ////                        if (plot.isRangeCrosshairVisible()) {
    ////                            System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue());
    ////                        }
    //                                    }
    //                                }
    //                            }
    //                        });
    //            }
    //        });

    //        chart.addChangeListener(new ChartChangeListener() {
    //
    //            public void chartChanged(ChartChangeEvent event) {
    //                System.out.println("event:" + event);
    //                if (event != null) {
    ////                    JFreeChart chart = event.getChart();
    ////                    System.out.println("chart:" + chart);
    ////                    if (chart != null) {
    ////                        System.out.println("title:" + event.getChart().getTitle());
    ////                    }
    //                    System.out.println("type:" + event.getType());
    //                    if (plot != null) {
    //                        if (plot.isDomainCrosshairVisible()) {
    //                            System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue());
    //                            long x = (long) plot.getDomainCrosshairValue();
    //                            for (TestStepInstance step : testStepInstances.getSteps()) {
    //                                if (step.getStartTime() != null && step.getStartTime().equals(x)) {
    //                                    testStepInstances.selectStep(step);
    //                                }
    //                            }
    //                            System.out.println(new Date(x));
    //                        }
    //                        if (plot.isRangeCrosshairVisible()) {
    //                            System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue());
    //                        }
    //                    }
    //                }
    //            }
    //        });
    chart.setTextAntiAlias(false);
    return chart;
}

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  .  j  a va2  s.c o m*/
 * @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:com.cyberway.issue.net.UURIFactoryTest.java

/**
* Tests from rfc2396 with amendments to accomodate differences
* intentionally added to make our URI handling like IEs.
*
* <pre>/*from www .j  a  v a  2 s .c o m*/
*       g:h           =  g:h
*       g             =  http://a/b/c/g
*       ./g           =  http://a/b/c/g
*       g/            =  http://a/b/c/g/
*       /g            =  http://a/g
*       //g           =  http://g
*       ?y            =  http://a/b/c/?y
*       g?y           =  http://a/b/c/g?y
*       #s            =  (current document)#s
*       g#s           =  http://a/b/c/g#s
*       g?y#s         =  http://a/b/c/g?y#s
*       ;x            =  http://a/b/c/;x
*       g;x           =  http://a/b/c/g;x
*       g;x?y#s       =  http://a/b/c/g;x?y#s
*       .             =  http://a/b/c/
*       ./            =  http://a/b/c/
*       ..            =  http://a/b/
*       ../           =  http://a/b/
*       ../g          =  http://a/b/g
*       ../..         =  http://a/
*       ../../        =  http://a/
*       ../../g       =  http://a/g
* </pre>
*
* @throws URIException
*/
public final void testRFC2396Relative() throws URIException {
    UURI base = UURIFactory.getInstance("http://a/b/c/d;p?q");
    TreeMap<String, String> m = new TreeMap<String, String>();
    m.put("..", "http://a/b/");
    m.put("../", "http://a/b/");
    m.put("../g", "http://a/b/g");
    m.put("../..", "http://a/");
    m.put("../../", "http://a/");
    m.put("../../g", "http://a/g");
    m.put("g#s", "http://a/b/c/g#s");
    m.put("g?y#s ", "http://a/b/c/g?y#s");
    m.put(";x", "http://a/b/c/;x");
    m.put("g;x", "http://a/b/c/g;x");
    m.put("g;x?y#s", "http://a/b/c/g;x?y#s");
    m.put(".", "http://a/b/c/");
    m.put("./", "http://a/b/c/");
    m.put("g", "http://a/b/c/g");
    m.put("./g", "http://a/b/c/g");
    m.put("g/", "http://a/b/c/g/");
    m.put("/g", "http://a/g");
    m.put("//g", "http://g");
    // CHANGED BY RFC3986
    // m.put("?y", "http://a/b/c/?y");
    m.put("g?y", "http://a/b/c/g?y");
    // EXTRAS beyond the RFC set.
    // TODO: That these resolve to a path of /a/g might be wrong.  Perhaps
    // it should be '/g'?.
    m.put("/../../../../../../../../g", "http://a/g");
    m.put("../../../../../../../../g", "http://a/g");
    m.put("../G", "http://a/b/G");
    for (Iterator i = m.keySet().iterator(); i.hasNext();) {
        String key = (String) i.next();
        String value = (String) m.get(key);
        UURI uuri = UURIFactory.getInstance(base, key);
        assertTrue("Unexpected " + key + " " + value + " " + uuri, uuri.equals(UURIFactory.getInstance(value)));
    }
}