Example usage for java.util LinkedHashMap put

List of usage examples for java.util LinkedHashMap put

Introduction

In this page you can find the example usage for java.util LinkedHashMap put.

Prototype

V put(K key, V value);

Source Link

Document

Associates the specified value with the specified key in this map (optional operation).

Usage

From source file:com.opengamma.analytics.financial.curve.ParameterUnderlyingSensitivityCalculator.java

/**
 * Computes the sensitivity with respect to the parameters from the point sensitivities to the continuously compounded rate.
 * @param sensitivity The point sensitivity.
 * @param fixedCurves The fixed curves names (for which the parameter sensitivity are not computed even if they are necessary for the instrument pricing).
 * The curve in the list may or may not be in the bundle. Not null.
 * @param bundle The curve bundle with all the curves with respect to which the sensitivity should be computed. Not null.
 * @return The sensitivity (as a DoubleMatrix1D).
 *//*from   w w w .j  a  v a  2  s.co m*/
@Override
public DoubleMatrix1D pointToParameterSensitivity(final InterestRateCurveSensitivity sensitivity,
        final Set<String> fixedCurves, final YieldCurveBundle bundle) {
    Integer nbCurve = 0;
    LinkedHashMap<String, Integer> curveNum = new LinkedHashMap<String, Integer>();
    for (final String name : bundle.getAllNames()) { // loop over all curves (by name)
        if (!fixedCurves.contains(name)) {
            curveNum.put(name, nbCurve++);
        }
    }
    nbCurve = 0;
    int[] nbNewParameters = new int[curveNum.size()];
    // Implementation note: 
    int[] startCleanParameter = new int[curveNum.size()];
    // Implementation note: 
    int[][] startDirtyParameter = new int[curveNum.size()][];
    int[][] indexOther = new int[curveNum.size()][];
    // Implementation note: the start of the different blocs of parameters. First the other curves, then the new part.
    int nbCleanParameters = 0;
    int currentDirtyStart = 0;
    for (final String name : bundle.getAllNames()) { // loop over all curves (by name)
        if (!fixedCurves.contains(name)) {
            final YieldAndDiscountCurve curve = bundle.getCurve(name);
            List<String> underlyingCurveNames = curve.getUnderlyingCurvesNames();
            startCleanParameter[nbCurve] = nbCleanParameters;
            nbNewParameters[nbCurve] = curve.getNumberOfParameters();
            List<Integer> indexOtherList = new ArrayList<Integer>();
            List<Integer> startDirtyParameterList = new ArrayList<Integer>();
            for (String u : underlyingCurveNames) {
                Integer i = curveNum.get(u);
                if (i != null) {
                    indexOtherList.add(i);
                    nbNewParameters[nbCurve] -= nbNewParameters[i];
                    startDirtyParameterList.add(currentDirtyStart);
                    currentDirtyStart += nbNewParameters[i];
                }
            }
            startDirtyParameterList.add(currentDirtyStart);
            currentDirtyStart += nbNewParameters[nbCurve];
            indexOther[nbCurve] = ArrayUtils.toPrimitive(indexOtherList.toArray(new Integer[0]));
            startDirtyParameter[nbCurve] = ArrayUtils
                    .toPrimitive(startDirtyParameterList.toArray(new Integer[0]));
            nbCleanParameters += nbNewParameters[nbCurve];
            nbCurve++;
        }
    }
    final List<Double> sensiDirtyList = new ArrayList<Double>();
    for (final String name : bundle.getAllNames()) { // loop over all curves (by name)
        if (!fixedCurves.contains(name)) {
            final YieldAndDiscountCurve curve = bundle.getCurve(name);
            List<Double> oneCurveSensitivity = pointToParameterSensitivity(
                    sensitivity.getSensitivities().get(name), curve);
            sensiDirtyList.addAll(oneCurveSensitivity);
        }
    }
    double[] sensiDirty = ArrayUtils.toPrimitive(sensiDirtyList.toArray(new Double[0]));
    double[] sensiClean = new double[nbCleanParameters];
    for (int loopcurve = 0; loopcurve < nbCurve; loopcurve++) {
        for (int loopo = 0; loopo < indexOther[loopcurve].length; loopo++) {
            for (int loops = 0; loops < nbNewParameters[indexOther[loopcurve][loopo]]; loops++) {
                sensiClean[startCleanParameter[indexOther[loopcurve][loopo]]
                        + loops] += sensiDirty[startDirtyParameter[loopcurve][loopo] + loops];
            }
        }
        for (int loops = 0; loops < nbNewParameters[loopcurve]; loops++) {
            sensiClean[startCleanParameter[loopcurve]
                    + loops] += sensiDirty[startDirtyParameter[loopcurve][indexOther[loopcurve].length]
                            + loops];
        }
    }
    return new DoubleMatrix1D(sensiClean);
}

From source file:com.dangdang.ddframe.job.cloud.executor.TaskExecutorThreadTest.java

private byte[] serialize(final Map<String, String> jobConfigurationContext) {
    // CHECKSTYLE:OFF
    LinkedHashMap<String, Object> result = new LinkedHashMap<>(2, 1);
    // CHECKSTYLE:ON
    ShardingContexts shardingContexts = new ShardingContexts(taskId, "test_job", 1, "",
            Collections.singletonMap(1, "a"));
    result.put("shardingContext", shardingContexts);
    result.put("jobConfigContext", jobConfigurationContext);
    return SerializationUtils.serialize(result);
}

From source file:com.novartis.opensource.yada.JSONParamsEntry.java

/**
 * Adds {@code row} to the entry's data list.
 * @param row the data row to add to the existing data structure in the entry.
 *//*  w ww.ja v  a  2 s.c  om*/
public void addData(JSONObject row) {
    LinkedHashMap<String, String[]> d = new LinkedHashMap<>();
    String[] k = JSONObject.getNames(row);
    for (int i = 0; i < k.length; i++) {
        d.put(k[i], new String[] { String.valueOf(row.get(k[i])) });
    }
    this.addData(d);
}

From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupBoxPlot.java

public List<JFreeChart> createChart() {
    List<JFreeChart> charts = new ArrayList<>();
    LinkedHashSet<ITreatmentGroupDescriptor> treatmentGroups = new LinkedHashSet<>(
            project.getTreatmentGroups());
    List<CategoryPlot> plots = new LinkedList<>();
    for (IPeakGroupDescriptor pgd : pgdl) {
        LinkedHashMap<ITreatmentGroupDescriptor, HashSet<IPeakAnnotationDescriptor>> map = new LinkedHashMap<>();
        for (ITreatmentGroupDescriptor itgd : treatmentGroups) {
            map.put(itgd, new LinkedHashSet<IPeakAnnotationDescriptor>());
        }/*from w w w.  j  ava  2  s .co  m*/
        List<IPeakAnnotationDescriptor> descriptors = pgd.getPeakAnnotationDescriptors();

        DefaultBoxAndWhiskerCategoryDataset baw = new DefaultBoxAndWhiskerCategoryDataset();
        for (IPeakAnnotationDescriptor ipad : descriptors) {
            ITreatmentGroupDescriptor treatmentGroup = ipad.getChromatogramDescriptor().getTreatmentGroup();
            HashSet<IPeakAnnotationDescriptor> descr = map.get(treatmentGroup);
            if (descr == null) {
                descr = new HashSet<>();
                map.put(treatmentGroup, descr);
            }
            descr.add(ipad);
        }
        List<Color> colors = new LinkedList<>();
        for (ITreatmentGroupDescriptor tgd : map.keySet()) {
            String name = getPeakName(pgd);
            baw.add(createBoxAndWhiskerItem(map.get(tgd)), tgd.getName() + " (" + map.get(tgd).size() + ")",
                    name);
            colors.add(tgd.getColor());
        }
        BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setMeanVisible(false);
        renderer.setMedianVisible(true);
        renderer.setArtifactPaint(new Color(0, 0, 0, 128));
        renderer.setMaximumBarWidth(0.1);
        renderer.setUseOutlinePaintForWhiskers(false);
        //            renderer.setAutoPopulateSeriesFillPaint(true);
        //            renderer.setAutoPopulateSeriesPaint(true);
        //            renderer.setAutoPopulateSeriesOutlinePaint(true);
        CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"),
                new NumberAxis("Normalized Peak Area"), renderer);
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Setting {0} colors!", colors.size());
        ChartCustomizer.setSeriesColors(cp, 0.6f, colors);
        //            ChartCustomizer.setSeriesColors(cp, 0.9f,colors);
        plots.add(cp);
        JFreeChart chart = new JFreeChart(cp);
        chart.setTitle(
                "Peak group " + pgd.getDisplayName() + " size: " + pgd.getPeakAnnotationDescriptors().size());
        charts.add(chart);
    }
    //        CategoryAxis ca = new CategoryAxis("Treatment Groups");
    //        NumberAxis va = new NumberAxis("Normalized Peak Area");
    //        CombinedDomainCategoryPlot cdcp = new CombinedDomainCategoryPlot(ca);
    //        for (CategoryPlot cp : plots) {
    //            cp.setRangeAxis(va);
    //            cdcp.add(cp);
    //            break;
    //        }
    //        return new JFreeChart(cdcp);
    return charts;
}

From source file:org.kmnet.com.fw.common.codelist.JdbcCodeList.java

/**
 * Retrieves the codelist from the database and returns it as a Map<br>
 * Each row is put to the codelist unless value or label of it is <code>null</code>.
 * @return Map latest codelist information
 * @see org.kmnet.com.fw.common.codelist.AbstractReloadableCodeList#retrieveMap()
 *//*from www  .ja  va  2  s .  c o m*/
@Override
protected Map<String, String> retrieveMap() {
    List<Map<String, Object>> rows = jdbcTemplate.queryForList(querySql);
    LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
    for (Map<String, Object> row : rows) {
        Object key = row.get(valueColumn);
        Object value = row.get(labelColumn);
        if (key != null && value != null) {
            result.put(key.toString(), value.toString());
        }
    }
    return result;
}

From source file:net.sf.maltcms.chromaui.normalization.spi.charts.PeakGroupRtBoxPlot.java

public List<JFreeChart> createChart() {
    List<JFreeChart> charts = new ArrayList<>();
    LinkedHashSet<ITreatmentGroupDescriptor> treatmentGroups = new LinkedHashSet<>(
            project.getTreatmentGroups());
    List<CategoryPlot> plots = new LinkedList<>();
    for (IPeakGroupDescriptor pgd : pgdl) {
        LinkedHashMap<ITreatmentGroupDescriptor, HashSet<IPeakAnnotationDescriptor>> map = new LinkedHashMap<>();
        for (ITreatmentGroupDescriptor itgd : treatmentGroups) {
            map.put(itgd, new LinkedHashSet<IPeakAnnotationDescriptor>());
        }/* w w w .  j  av a 2 s.c om*/
        List<IPeakAnnotationDescriptor> descriptors = pgd.getPeakAnnotationDescriptors();

        DefaultBoxAndWhiskerCategoryDataset baw = new DefaultBoxAndWhiskerCategoryDataset();
        for (IPeakAnnotationDescriptor ipad : descriptors) {
            ITreatmentGroupDescriptor treatmentGroup = ipad.getChromatogramDescriptor().getTreatmentGroup();
            HashSet<IPeakAnnotationDescriptor> descr = map.get(treatmentGroup);
            if (descr == null) {
                descr = new HashSet<>();
                map.put(treatmentGroup, descr);
            }
            descr.add(ipad);
        }
        List<Color> colors = new LinkedList<>();
        for (ITreatmentGroupDescriptor tgd : map.keySet()) {
            String name = getPeakName(pgd);
            baw.add(createBoxAndWhiskerItem(map.get(tgd)), tgd.getName() + " (" + map.get(tgd).size() + ")",
                    name);
            colors.add(tgd.getColor());
        }
        BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
        renderer.setFillBox(true);
        renderer.setMeanVisible(false);
        renderer.setMedianVisible(true);
        renderer.setArtifactPaint(new Color(0, 0, 0, 128));
        renderer.setMaximumBarWidth(0.1);

        renderer.setUseOutlinePaintForWhiskers(false);
        //            renderer.setAutoPopulateSeriesFillPaint(true);
        //            renderer.setAutoPopulateSeriesPaint(true);
        //            renderer.setAutoPopulateSeriesOutlinePaint(true);
        NumberAxis yAxis = new NumberAxis("Peak Apex Retention Time");
        yAxis.setAutoRange(true);
        yAxis.setAutoRangeIncludesZero(false);
        CategoryPlot cp = new CategoryPlot(baw, new CategoryAxis("Treatment Groups"), yAxis, renderer);
        Logger.getLogger(getClass().getName()).log(Level.INFO, "Setting {0} colors!", colors.size());
        ChartCustomizer.setSeriesColors(cp, 0.6f, colors);
        //            ChartCustomizer.setSeriesColors(cp, 0.9f,colors);
        plots.add(cp);
        JFreeChart chart = new JFreeChart(cp);
        chart.setTitle(
                "Peak group " + pgd.getDisplayName() + " size: " + pgd.getPeakAnnotationDescriptors().size());
        charts.add(chart);
    }
    //        CategoryAxis ca = new CategoryAxis("Treatment Groups");
    //        NumberAxis va = new NumberAxis("Normalized Peak Area");
    //        CombinedDomainCategoryPlot cdcp = new CombinedDomainCategoryPlot(ca);
    //        for (CategoryPlot cp : plots) {
    //            cp.setRangeAxis(va);
    //            cdcp.add(cp);
    //            break;
    //        }
    //        return new JFreeChart(cdcp);
    return charts;
}

From source file:com.opengamma.analytics.financial.curve.sensitivity.ParameterSensitivity.java

/**
 * Create a copy of the object with all the sensitivities multiplied by a common factor.
 * @param factor The factor.//w ww  . j a  va 2  s  .  c o m
 * @return The multiplied sensitivity.
 */
public ParameterSensitivity multipliedBy(final double factor) {
    final MatrixAlgebra algebra = MatrixAlgebraFactory.COMMONS_ALGEBRA;
    final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D>();
    for (final Pair<String, Currency> nameCcy : _sensitivity.keySet()) {
        result.put(nameCcy, (DoubleMatrix1D) algebra.scale(_sensitivity.get(nameCcy), factor));
    }
    return new ParameterSensitivity(result);
}

From source file:org.cloudfoundry.identity.uaa.login.LinkedMaskingMultiValueMap.java

@Override
public Map<K, V> toSingleValueMap() {
    LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<K, V>(this.targetMap.size());
    for (Entry<K, List<V>> entry : targetMap.entrySet()) {
        singleValueMap.put(entry.getKey(), entry.getValue().get(0));
    }//from w  ww  .jav a  2  s . co  m
    return singleValueMap;
}

From source file:controllers.impl.StandardApi.java

@Override
public F.Promise<Result> updateStagePackageVersions(final String envName, final String stageName) {
    final models.Stage stage = models.Stage.getByEnvironmentNameAndName(envName, stageName);
    if (stage == null) {
        return F.Promise.pure(notFound());
    }//from   www .  j a va2s  . c  o m

    final List<models.PackageVersion> versions = Lists.newArrayList();
    final JsonNode requestJson = request().body().asJson();
    if (requestJson == null) {
        return F.Promise.pure(badRequest());
    }
    final ArrayNode packages = (ArrayNode) requestJson.get("packages");
    for (final JsonNode node : packages) {
        final ObjectNode packageNode = (ObjectNode) node;
        final String packageName = packageNode.get("name").asText();
        final String version = packageNode.get("version").asText();
        final PackageVersion pkgVersion = getPackageVersion(packageName, version);
        versions.add(pkgVersion);
    }

    final ManifestHistory currentHistory = ManifestHistory.getCurrentForStage(stage);
    final Manifest currentManifest = currentHistory.getManifest();

    final LinkedHashMap<String, PackageVersion> newPackages = Maps
            .newLinkedHashMap(currentManifest.asPackageMap());
    versions.forEach(pv -> newPackages.put(pv.getPkg().getName(), pv));
    final Manifest newManifest = new Manifest();
    newManifest.getPackages().addAll(newPackages.values());
    newManifest.save();

    final Future<Object> ask = Patterns.ask(_deploymentManager,
            new FleetDeploymentCommands.DeployStage(stage, newManifest, "api"),
            Timeout.apply(30L, TimeUnit.SECONDS));

    return F.Promise.wrap(ask).map(o -> {
        if (o instanceof Deployment) {
            final Deployment deployment = (Deployment) o;
            return ok(JsonNodeFactory.instance.objectNode().put("deployId", deployment.getId()));
        }
        Logger.error("Expected Deployment response from deployment manager, got " + o);
        return internalServerError();
    });
}

From source file:com.opengamma.analytics.financial.curve.sensitivity.ParameterSensitivity.java

/**
 * Create a copy of the sensitivity and add a given named sensitivity to it. If the name / currency pair is in the map, the two sensitivity matrices are added.
 * Otherwise, a new entry is put into the map
 * @param nameCcy The name and the currency, not null
 * @param sensitivity The sensitivity to add, not null
 * @return The total sensitivity./*from w w w .  j  a v  a  2s . c  o m*/
 */
public ParameterSensitivity plus(final Pair<String, Currency> nameCcy, final DoubleMatrix1D sensitivity) {
    ArgumentChecker.notNull(nameCcy, "Name/currency");
    ArgumentChecker.notNull(sensitivity, "Matrix");
    final MatrixAlgebra algebra = MatrixAlgebraFactory.COMMONS_ALGEBRA;
    final LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D> result = new LinkedHashMap<Pair<String, Currency>, DoubleMatrix1D>();
    result.putAll(_sensitivity);
    if (result.containsKey(nameCcy)) {
        result.put(nameCcy, (DoubleMatrix1D) algebra.add(result.get(nameCcy), sensitivity));
    } else {
        result.put(nameCcy, sensitivity);
    }
    return new ParameterSensitivity(result);
}