Example usage for java.util SortedMap get

List of usage examples for java.util SortedMap get

Introduction

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

Prototype

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:no.ssb.jsonstat.v2.deser.DatasetDeserializer.java

List<Number> parseValues(JsonParser p, DeserializationContext ctxt) throws IOException {
    List<Number> result = Collections.emptyList();
    switch (p.getCurrentToken()) {
    case START_OBJECT:
        SortedMap<Integer, Number> map = p.readValueAs(VALUES_MAP);
        result = new AbstractList<Number>() {

            @Override/*from   www. j ava 2s.c  om*/
            public int size() {
                return map.lastKey() + 1;
            }

            @Override
            public Number get(int index) {
                return map.get(index);
            }
        };
        break;
    case START_ARRAY:
        result = p.readValueAs(VALUES_LIST);
        break;
    default:
        ctxt.handleUnexpectedToken(this._valueClass, p.getCurrentToken(), p, "msg");
    }
    return result;
}

From source file:org.kairosdb.datastore.remote.RemoteDatastore.java

private void flushMap() {
    Multimap<DataPointKey, DataPoint> flushMap = createNewMap();

    synchronized (m_dataFileLock) {
        try {/* ww w  .  j  a  v a 2  s  . c  om*/
            try {
                for (DataPointKey dataPointKey : flushMap.keySet()) {
                    //We have to reset the writer every time or it gets confused
                    //because we are only writing partial json each time.
                    JSONWriter writer = new JSONWriter(m_dataWriter);

                    if (!m_firstDataPoint) {
                        m_dataWriter.write(",\n");
                    }
                    m_firstDataPoint = false;

                    writer.object();

                    writer.key("name").value(dataPointKey.getName());
                    writer.key("skip_validate").value(true);
                    writer.key("tags").object();
                    SortedMap<String, String> tags = dataPointKey.getTags();
                    for (String tag : tags.keySet()) {
                        writer.key(tag).value(tags.get(tag));
                    }
                    writer.endObject();

                    writer.key("datapoints").array();
                    for (DataPoint dataPoint : flushMap.get(dataPointKey)) {
                        m_dataPointCounter++;
                        writer.array();
                        writer.value(dataPoint.getTimestamp());
                        dataPoint.writeValueToJson(writer);
                        writer.value(dataPoint.getApiDataType());
                        /*if (dataPoint.isLong())
                           writer.value(dataPoint.getLongValue());
                        else
                           writer.value(dataPoint.getDoubleValue());*/
                        writer.endArray();
                    }
                    writer.endArray();

                    writer.endObject();
                }
            } catch (JSONException e) {
                logger.error("Unable to write datapoints to file", e);
            }

            m_dataWriter.flush();
        } catch (IOException e) {
            logger.error("Unable to write datapoints to file", e);
        }
    }
}

From source file:org.apache.hadoop.hbase.regionserver.ccindex.Checker.java

@SuppressWarnings("static-access")
private boolean recoveryDataForBase(byte[] row, HTable target, SortedMap<byte[], byte[]> columnValues) {
    boolean success = false;
    for (IndexSpecification ind : this.CCITS.keySet()) {
        try {/*w  w w.  j  a v  a 2 s .co  m*/
            byte[] indexRow = ind.getKeyGenerator().createIndexKey(row,
                    columnValues.get(ind.getIndexedColumn()));
            LOG.info("recover from" + ind.getIndexId() + "recover from get row :" + new String(indexRow));
            Result recover = this.CCITS.get(ind).get(new Get(indexRow));
            SortedMap<byte[], byte[]> columns = IndexedRegion.convertToValueMap(recover);
            Put update = IndexMaintenanceUtils.recoverPut(row, columns, true, this.des);

            target.put(update);
            success = true;
            break;
        } catch (Throwable e) {
            e.printStackTrace();
            System.out.println("get from:" + ind.getIndexId() + " error");
            continue;
            // TODO Auto-generated catch block
        }
    }
    return success;
}

From source file:edu.northwestern.bioinformatics.studycalendar.restlets.SchedulePreviewResource.java

public SortedMap<Date, List<ScheduledActivity>> createActivitiesByDate(
        List<ScheduledActivity> scheduledActivities) {
    SortedMap<Date, List<ScheduledActivity>> byDate = new TreeMap<Date, List<ScheduledActivity>>();
    Collections.sort(scheduledActivities);
    for (ScheduledActivity scheduledActivity : scheduledActivities) {
        Date key = scheduledActivity.getActualDate();
        if (!byDate.containsKey(key)) {
            byDate.put(key, new ArrayList<ScheduledActivity>());
        }// w  w  w  .  j  a v a 2  s  .  co m
        byDate.get(key).add(scheduledActivity);
    }
    return byDate;
}

From source file:edu.brown.statistics.AbstractStatistics.java

/**
 * @param <T>//  www.j ava2s. co m
 * @param map
 * @param name
 * @param stringer
 * @throws JSONException
 */
protected <U> void writeMap(SortedMap<U, ?> map, String name, JSONStringer stringer) throws JSONException {
    stringer.key(name).object();
    for (U key : map.keySet()) {
        String key_name = key.toString();
        if (key instanceof CatalogType) {
            key_name = ((CatalogType) key).getName();
        }
        stringer.key(key_name).value(map.get(key));
    } // FOR
    stringer.endObject();
}

From source file:com.streamsets.pipeline.stage.processor.statsaggregation.TestMetricAggregationProcessor.java

@Test
public void testMetricEvaluation() throws StageException {

    MetricsRuleDefinition metricsRuleDefinition1 = new MetricsRuleDefinition("badRecordsAlertID",
            "High incidence of Bad Records", "pipeline.batchErrorRecords.meter", MetricType.METER,
            MetricElement.METER_COUNT, "${value() > 400}", false, true, System.currentTimeMillis());

    MetricsRuleDefinition metricsRuleDefinition2 = new MetricsRuleDefinition(
            "testMetricAggregation1458001548262", "Field Hasher Drops Records",
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1.outputRecords.meter",
            MetricType.METER, MetricElement.METER_COUNT, "${value() < 1800}", false, true,
            System.currentTimeMillis());

    Record metricRuleChangeRecord1 = AggregatorUtil.createMetricRuleChangeRecord(metricsRuleDefinition1);
    Record metricRuleChangeRecord2 = AggregatorUtil.createMetricRuleChangeRecord(metricsRuleDefinition2);
    Record metricRecord1 = createTestMetricRecord();
    Record metricRecord2 = createTestMetricRecord();
    runner.runProcess(/*from  w w  w . ja  v  a  2s . c  o  m*/
            Arrays.asList(metricRuleChangeRecord1, metricRuleChangeRecord2, metricRecord1, metricRecord2));

    // look for alert gauges
    MetricRegistry metrics = metricAggregationProcessor.getMetrics();
    SortedMap<String, Gauge> gauges = metrics.getGauges();
    Assert.assertEquals(2, gauges.size());

    Gauge gauge = gauges.get(AlertsUtil.getAlertGaugeName(metricsRuleDefinition1.getId()) + ".gauge");
    Map<String, Object> alertResponse = (Map<String, Object>) gauge.getValue();
    Assert.assertEquals(500L, alertResponse.get("currentValue"));
    Assert.assertEquals("High incidence of Bad Records",
            ((List<String>) alertResponse.get("alertTexts")).iterator().next());

    gauge = gauges.get(AlertsUtil.getAlertGaugeName(metricsRuleDefinition2.getId()) + ".gauge");
    alertResponse = (Map<String, Object>) gauge.getValue();
    Assert.assertEquals(1500L, alertResponse.get("currentValue"));
    Assert.assertEquals("Field Hasher Drops Records",
            ((List<String>) alertResponse.get("alertTexts")).iterator().next());

}

From source file:com.streamsets.pipeline.stage.processor.statsaggregation.TestMetricAggregationProcessor.java

@Test
public void testMetersForMetricRecord() throws StageException {
    MetricsRuleDefinition metricsRuleDefinition1 = TestHelper.createTestMetricRuleDefinition("a < b", true,
            System.currentTimeMillis());
    Record metricRuleChangeRecord = AggregatorUtil.createMetricRuleChangeRecord(metricsRuleDefinition1);
    Record metricRecord = createTestMetricRecord();
    runner.runProcess(Arrays.asList(metricRuleChangeRecord, metricRecord));

    MetricRegistry metrics = metricAggregationProcessor.getMetrics();

    SortedMap<String, Meter> meters = metrics.getMeters();
    Assert.assertEquals(1, meters.get("pipeline.batchCount.meter").getCount());
    Assert.assertEquals(1000, meters.get("pipeline.batchInputRecords.meter").getCount());
    Assert.assertEquals(500, meters.get("pipeline.batchOutputRecords.meter").getCount());
    Assert.assertEquals(250, meters.get("pipeline.batchErrorRecords.meter").getCount());
    Assert.assertEquals(250, meters.get("pipeline.batchErrorMessages.meter").getCount());

    Assert.assertEquals(0,/*  ww w.  j a va  2 s . c  o  m*/
            meters.get(
                    "stage.com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1.inputRecords.meter")
                    .getCount());
    Assert.assertEquals(1000,
            meters.get(
                    "stage.com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1.outputRecords.meter")
                    .getCount());
    Assert.assertEquals(0,
            meters.get(
                    "stage.com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1.errorRecords.meter")
                    .getCount());
    Assert.assertEquals(0,
            meters.get(
                    "stage.com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1.stageErrors.meter")
                    .getCount());
    Assert.assertEquals(1000, meters.get(
            "stage.com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1:com_streamsets_pipeline_stage_origin_spooldir_SpoolDirDSource_1OutputLane14578524215930.outputRecords.meter")
            .getCount());

    Assert.assertEquals(1000, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1.inputRecords.meter")
            .getCount());
    Assert.assertEquals(750, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1.outputRecords.meter")
            .getCount());
    Assert.assertEquals(250, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1.errorRecords.meter")
            .getCount());
    Assert.assertEquals(0, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1.stageErrors.meter")
            .getCount());
    Assert.assertEquals(750, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1:com_streamsets_pipeline_stage_processor_fieldhasher_FieldHasherDProcessor_1OutputLane14578524269500.outputRecords.meter")
            .getCount());

    Assert.assertEquals(750, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1.inputRecords.meter")
            .getCount());
    Assert.assertEquals(500, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1.outputRecords.meter")
            .getCount());
    Assert.assertEquals(0, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1.errorRecords.meter")
            .getCount());
    Assert.assertEquals(250, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1.stageErrors.meter")
            .getCount());
    Assert.assertEquals(500, meters.get(
            "stage.com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1:com_streamsets_pipeline_stage_processor_expression_ExpressionDProcessor_1OutputLane14578524390500.outputRecords.meter")
            .getCount());

    Assert.assertEquals(500, meters.get(
            "stage.com_streamsets_pipeline_stage_destination_localfilesystem_LocalFileSystemDTarget_1.inputRecords.meter")
            .getCount());
    Assert.assertEquals(500, meters.get(
            "stage.com_streamsets_pipeline_stage_destination_localfilesystem_LocalFileSystemDTarget_1.outputRecords.meter")
            .getCount());
    Assert.assertEquals(0, meters.get(
            "stage.com_streamsets_pipeline_stage_destination_localfilesystem_LocalFileSystemDTarget_1.errorRecords.meter")
            .getCount());
    Assert.assertEquals(0, meters.get(
            "stage.com_streamsets_pipeline_stage_destination_localfilesystem_LocalFileSystemDTarget_1.stageErrors.meter")
            .getCount());

}

From source file:de.ingrid.admin.controller.GeneralController.java

private String toJsonMap(final SortedMap<String, List<Provider>> map) {
    final StringBuilder result = new StringBuilder("{");
    for (final String key : map.keySet()) {
        result.append("'" + key + "':[");
        final Iterator<Provider> it = map.get(key).iterator();
        while (it.hasNext()) {
            final Provider p = it.next();
            result.append(/*from   w  w  w. jav  a 2  s  .  c  om*/
                    "{'shortName':'" + p.getShortName() + "','displayName':'" + p.getDisplayName() + "'}");
            if (it.hasNext()) {
                result.append(",");
            }
        }
        result.append("]");
        if (key != map.lastKey()) {
            result.append(",");
        }
    }
    result.append("}");
    return result.toString();
}

From source file:com.intuit.tank.script.util.ScriptFilterUtil.java

/**
 * /* w  w w  .  j av  a  2  s. com*/
 * @param filter
 * @param steps
 */
public static void applyFilter(ScriptFilter filter, List<ScriptStep> steps) {
    boolean allConditionsMustPass = filter.getAllConditionsMustPass();
    Set<ScriptStep> stepsToDelete = new HashSet<ScriptStep>();
    SortedMap<Integer, ScriptStep> stepsToAdd = new TreeMap<Integer, ScriptStep>();
    for (ScriptStep step : steps) {
        boolean conditionsMet = true;

        for (ScriptFilterCondition condition : filter.getConditions()) {
            conditionsMet = testConditions(condition.getScope(), condition, step, steps);

            if (!conditionsMet && allConditionsMustPass) {
                break;
            }

            else if (conditionsMet && !allConditionsMustPass) {
                break;
            }
        }

        if (conditionsMet) {
            doAction(steps, stepsToAdd, stepsToDelete, filter.getActions(), step);
        }
    }
    int reqCount = 0;
    Iterator<Integer> itr = stepsToAdd.keySet().iterator();
    while (itr.hasNext()) {
        int index = itr.next();
        steps.add(index + reqCount, stepsToAdd.get(index));
        reqCount++;
    }

    for (ScriptStep delete : stepsToDelete) {
        steps.remove(delete);
    }
}

From source file:org.web4thejob.web.util.ToolbarRenderer.java

@Override
public void render() {
    final boolean isEmpty = isEmpty();
    if (toolbar != null && isEmpty) {
        reset();/* w w w.ja v  a  2s . c  om*/
        return;
    } else if (toolbar != null || isEmpty) {
        return;
    }

    toolbar = new Toolbar();
    toolbar.setAlign(align);
    container.insertBefore(toolbar, container.getFirstChild());

    if (!HtmlViewPanel.class.isInstance(getPrimaryOwner())) {
        toolbar.setStyle("border-width: 0;");
    }

    SortedMap<CommandEnum, List<Command>> map = mergeCommands();

    for (final CommandEnum id : map.keySet()) {
        CommandDecorator commandDecorator = null;
        if (map.get(id).size() == 1) {
            commandDecorator = getDecorator(map.get(id).get(0));
        } else {
            for (Command command : map.get(id)) {
                if (commandDecorator == null) {
                    commandDecorator = new DefaultDropdownCommandDecorator(command);
                } else {
                    ((DropdownCommandDecorator) commandDecorator).add(command);
                }
            }
        }

        if (id.isRequiresStartSeparator() && id != map.firstKey() && !isPreviousSeparator()) {
            addSeparator();
        }

        if (commandDecorator != null) {
            commandDecorator.attach(toolbar);
            commandDecorator.addMessageListener(this);
            commandDecorator.render();
        }

        if (id.isRequiresEndSeparator() && id != map.lastKey()) {
            addSeparator();
        }

        Space space = new Space();
        space.setSpacing("8px");
        space.setParent(toolbar);
    }
}