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.silverpeas.util.CollectionUtil.java

/**
 * Transforming a collection into a map//from  www  .  ja va  2  s  . c o  m
 * @param <T> collection type elements
 * @param <K> map type key
 * @param <V> map type value
 * @param collection
 * @param extractor extractor interface
 * @return a map initialized from a list by an extractor
 */
public static <T extends Object, K extends Object, V extends Object> HashMap<K, V> listToMap(
        final Collection<T> collection, final ExtractionList<T, K, V> extractor) {
    final LinkedHashMap<K, V> result;
    if (collection == null) {
        result = null;
    } else if (collection.isEmpty()) {
        result = new LinkedHashMap<K, V>();
    } else {
        result = new LinkedHashMap<K, V>((int) (collection.size() * 0.75f));
        if (extractor instanceof ExtractionComplexList<?, ?, ?>) {
            ((ExtractionComplexList<T, K, V>) extractor).setMap(result);
        }
        for (final T toPerform : collection) {
            result.put(extractor.getKey(toPerform), extractor.getValue(toPerform));
        }
    }
    return result;
}

From source file:ca.sfu.federation.utils.IContextUtils.java

public static Map<String, INamed> getDependancies(Map<String, INamed> ElementMap) {
    // init//  www. java2  s .c  om
    LinkedHashMap<String, INamed> results = new LinkedHashMap<String, INamed>();
    HashSet dependancies = new HashSet();
    // scenario dependancies come from contextual object references
    Iterator iter = ElementMap.values().iterator();
    while (iter.hasNext()) {
        INamed named = (INamed) iter.next();
        dependancies.add(named.getContext());
    }
    // convert set to map
    iter = dependancies.iterator();
    while (iter.hasNext()) {
        INamed named = (INamed) iter.next();
        results.put(named.getName(), named);
    }
    // return result
    return results;
}

From source file:de.zib.scalaris.InterOpTest.java

private static int read_write_map(final String basekey, final TransactionSingleOp sc, final Mode mode) {
    int failed = 0;
    String key;//from   ww w.  j  a v a 2 s.c  o m
    Object value;

    key = basekey + "_map_empty";
    value = new LinkedHashMap<String, Object>();
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Integer> map1 = new LinkedHashMap<String, Integer>();
    map1.put("x", 0);
    map1.put("y", 1);
    key = basekey + "_map_x=0_y=1";
    value = map1;
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Object> map2 = new LinkedHashMap<String, Object>();
    map2.put("a", 0);
    map2.put("b", "foo");
    map2.put("c", 1.5);
    map2.put("d", "foo\nbar");
    final ArrayList<Integer> list1 = new ArrayList<Integer>();
    list1.add(0);
    list1.add(1);
    list1.add(2);
    list1.add(3);
    map2.put("e", list1);
    map2.put("f", map1);
    key = basekey + "_map_a=0_b=foo_c=1.5_d=foo<nl>bar_e=list0123_f=mapx0y1";
    value = map2;
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Integer> map3 = new LinkedHashMap<String, Integer>();
    map3.put("", 0);
    key = basekey + "_map_=0";
    value = map3;
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Object> map4 = new LinkedHashMap<String, Object>();
    // some (arbitrary) unicode characters
    // (please don't be offended if they actually mean something)
    map4.put("x", 0);
    map4.put("y", "foo\u0180\u01E3\u11E5");
    key = basekey + "_map_x=0_y=foo\u0180\u01E3\u11E5";
    value = map4;
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Integer> map5 = new LinkedHashMap<String, Integer>();
    // some (arbitrary) unicode characters
    // (please don't be offended if they actually mean something)
    map5.put("x", 0);
    map5.put("foo\u0180\u01E3\u11E5", 1);
    key = basekey + "_map_x=0_foo\u0180\u01E3\u11E5=1";
    value = map5;
    failed += read_or_write(sc, key, value, mode);

    return failed;
}

From source file:com.act.lcms.db.analysis.ChemicalToMapOfMetlinIonsToIntensityTimeValues.java

/**
 * This function plots a combination of positive and negative control intensity-time values.
 * @param searchMzs A list of mass charge values
 * @param plottingPath The wells used for the analysis. This variable is mainly used for
 * @param peakDataPos The postive intensity-time value
 * @param peakDataNegs The negative controls intensity-time values
 * @param plottingDirectory The directory where the plots are going to be placed in
 * @return//from  w ww  .  j  av a  2s. co m
 * @throws IOException
 */
public static Map<String, String> plotPositiveAndNegativeControlsForEachMZ(Set<Pair<String, Double>> searchMzs,
        String plottingPath, ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataPos,
        List<ChemicalToMapOfMetlinIonsToIntensityTimeValues> peakDataNegs, String plottingDirectory)
        throws IOException {

    Map<String, String> result = new HashMap<>();
    Map<String, Double> individualMaxIntensities = new HashMap<>();
    WriteAndPlotMS1Results plottingUtil = new WriteAndPlotMS1Results();

    for (Pair<String, Double> mz : searchMzs) {
        LinkedHashMap<String, List<XZ>> ms1s = new LinkedHashMap<>();
        Map<String, Double> metlinMasses = new HashMap<>();
        Double maxIntensity = 0.0d;

        String chemicalAndIonName = mz.getLeft();
        Double massChargeValue = mz.getRight();

        // Get positive ion results
        String positiveChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName,
                ScanData.KIND.POS_SAMPLE);
        List<XZ> ionValuesPos = peakDataPos.peakData.get(positiveChemicalName).get(chemicalAndIonName);
        ms1s.put(positiveChemicalName, ionValuesPos);
        Double localMaxIntensityPos = findPeakMaxIntensity(ionValuesPos);
        maxIntensity = Math.max(maxIntensity, localMaxIntensityPos);
        individualMaxIntensities.put(positiveChemicalName, localMaxIntensityPos);
        metlinMasses.put(positiveChemicalName, massChargeValue);

        // Get negative control results
        Integer negNameCounter = 0;
        for (ChemicalToMapOfMetlinIonsToIntensityTimeValues peakDataNeg : peakDataNegs) {
            String negativeChemicalName = AnalysisHelper.constructChemicalAndScanTypeName(chemicalAndIonName,
                    ScanData.KIND.NEG_CONTROL);
            String negativeChemicalNameId = negativeChemicalName + "_" + negNameCounter.toString();
            List<XZ> ionValuesNeg = peakDataNeg.peakData.get(negativeChemicalName).get(chemicalAndIonName);
            ms1s.put(negativeChemicalNameId, ionValuesNeg);
            Double localMaxIntensityNeg = findPeakMaxIntensity(ionValuesNeg);
            maxIntensity = Math.max(maxIntensity, localMaxIntensityNeg);
            individualMaxIntensities.put(negativeChemicalNameId, localMaxIntensityNeg);
            metlinMasses.put(negativeChemicalNameId, massChargeValue);
            negNameCounter++;
        }

        String relativePath = massChargeValue.toString() + "_" + plottingPath + "_" + chemicalAndIonName;
        File absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath);
        String absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath();
        String absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT;

        // Check if the plotting file already exists. If it does, we should not overwrite it. Instead, we just change
        // the path name by appending a counter till the collision no longer exists.
        // TODO: Implement an elegant solution to this problem.
        File duplicateFile = new File(absolutePathWithExtension);
        Integer fileDuplicateCounter = 0;
        while (duplicateFile.exists() && !duplicateFile.isDirectory()) {
            LOGGER.warn("Duplicate file exists for %s, writing to another file",
                    duplicateFile.getAbsolutePath());
            fileDuplicateCounter++;
            relativePath = relativePath + "_" + fileDuplicateCounter.toString();
            absolutePathFileWithoutExtension = new File(plottingDirectory, relativePath);
            absolutePathWithoutExtension = absolutePathFileWithoutExtension.getAbsolutePath();
            absolutePathWithExtension = absolutePathWithoutExtension + "." + FMT;
            duplicateFile = new File(absolutePathWithExtension);
        }

        LOGGER.info("Wrote plot to %s", absolutePathWithoutExtension);

        plottingUtil.plotSpectra(ms1s, maxIntensity, individualMaxIntensities, metlinMasses,
                absolutePathWithoutExtension, FMT, false, false);

        result.put(mz.getLeft(), relativePath + "." + FMT);
    }

    return result;
}

From source file:de.zib.scalaris.InterOpTest.java

private static int read_write_list(final String basekey, final TransactionSingleOp sc, final Mode mode) {
    int failed = 0;
    String key;/*from  w  w w .j  a  v  a2  s  .  c om*/
    Object value;

    key = basekey + "_list_empty";
    value = new ArrayList<Object>();
    failed += read_or_write(sc, key, value, mode);

    final ArrayList<Integer> list1 = new ArrayList<Integer>();
    list1.add(0);
    list1.add(1);
    list1.add(2);
    list1.add(3);
    key = basekey + "_list_0_1_2_3";
    value = list1;
    failed += read_or_write(sc, key, value, mode);

    final ArrayList<Integer> list2 = new ArrayList<Integer>();
    list2.add(0);
    list2.add(123);
    list2.add(456);
    list2.add(65000);
    key = basekey + "_list_0_123_456_65000";
    value = list2;
    failed += read_or_write(sc, key, value, mode);

    final ArrayList<Integer> list3 = new ArrayList<Integer>();
    list3.add(0);
    list3.add(123);
    list3.add(456);
    list3.add(0x10ffff);
    key = basekey + "_list_0_123_456_0x10ffff";
    value = list3;
    failed += read_or_write(sc, key, value, mode);

    final ArrayList<Object> list4 = new ArrayList<Object>();
    list4.add(0);
    list4.add("foo");
    list4.add(1.5);
    list4.add(false);
    key = basekey + "_list_0_foo_1.5_false";
    value = list4;
    failed += read_or_write(sc, key, value, mode);

    // note: we do not support binaries in lists anymore because JSON would
    // need special handling for each list element which introduces too
    // much overhead
    //        ArrayList<Object> list5 = new ArrayList<Object>();
    //        list5.add(0);
    //        list5.add("foo");
    //        list5.add(1.5);
    //        list5.add(new byte[] {0, 1, 2, 3});
    //        key = basekey + "_list_0_foo_1.5_<<0123>>"; value = list5;
    //        failed += read_or_write(sc, key, value, mode);

    final ArrayList<Object> list6 = new ArrayList<Object>();
    list6.add(0);
    list6.add("foo");
    list6.add(1.5);
    list6.add(false);
    list6.add(list4);
    key = basekey + "_list_0_foo_1.5_false_list4";
    value = list6;
    failed += read_or_write(sc, key, value, mode);

    final LinkedHashMap<String, Integer> map1 = new LinkedHashMap<String, Integer>();
    map1.put("x", 0);
    map1.put("y", 1);
    final ArrayList<Object> list7 = new ArrayList<Object>();
    list7.add(0);
    list7.add("foo");
    list7.add(1.5);
    list7.add(false);
    list7.add(list4);
    list7.add(map1);
    key = basekey + "_list_0_foo_1.5_false_list4_map_x=0_y=1";
    value = list7;
    failed += read_or_write(sc, key, value, mode);

    return failed;
}

From source file:com.none.tom.simplerssreader.feed.CurrentFeed.java

public static LinkedHashMap<Integer, String> getItunesMetadataForEntry(final Context context,
        final SyndEntry entry) {
    final FeedInformation itunesFeed = (FeedInformation) sCurrentFeed.getModule(FeedInformation.URI);
    final EntryInformation itunesEntry = (EntryInformation) entry.getModule(EntryInformation.URI);

    final LinkedHashMap<Integer, String> itunesMetaData = new LinkedHashMap<>(5);
    final StringBuilder owner = new StringBuilder();

    if (itunesFeed != null) {
        if (!TextUtils.isEmpty(itunesFeed.getOwnerName())) {
            owner.append(itunesFeed.getOwnerName());
        }/*from ww w  .  ja v  a2  s . c  om*/

        if (!TextUtils.isEmpty(itunesFeed.getOwnerEmailAddress())) {
            if (owner.length() > 0) {
                owner.append('\n');
            }
            owner.append(itunesFeed.getOwnerEmailAddress());
        }

        itunesMetaData.put(ITUNES_OWNER, owner.toString());
    }

    if (itunesEntry != null) {
        itunesMetaData.put(ITUNES_AUTHOR,
                !TextUtils.isEmpty(itunesEntry.getAuthor()) ? itunesEntry.getAuthor()
                        : (!TextUtils.isEmpty(sCurrentFeed.getManagingEditor())
                                ? sCurrentFeed.getManagingEditor()
                                : "-"));
        itunesMetaData.put(ITUNES_EXPLICIT,
                itunesEntry.getExplicit() ? context.getString(R.string.yes) : context.getString(R.string.no));
        itunesMetaData.put(ITUNES_DURATION,
                itunesEntry.getDuration() != null ? itunesEntry.getDuration().toString() : "-");
        itunesMetaData.put(ITUNES_SUBTITLE_SUMMARY,
                !TextUtils.isEmpty(itunesEntry.getSummary()) ? itunesEntry.getSummary()
                        : itunesEntry.getSubtitle());
    }

    return itunesMetaData;
}

From source file:com.opengamma.analytics.math.rootfinding.YieldCurveFittingSetup.java

protected static YieldCurveFittingTestDataBundle getYieldCurveFittingTestDataBundle(
        final List<InstrumentDerivative> instruments, final YieldCurveBundle knownCurves,
        final List<String> curveNames, final List<double[]> curvesKnots, final Interpolator1D extrapolator,
        final InstrumentDerivativeVisitor<YieldCurveBundle, Double> marketValueCalculator,
        final InstrumentDerivativeVisitor<YieldCurveBundle, Map<String, List<DoublesPair>>> marketValueSensitivityCalculator,
        final double[] marketRates, final DoubleMatrix1D startPosition, final List<double[]> curveYields,
        final boolean useFiniteDifferenceByDefault, final FXMatrix fxMatrix) {

    Validate.notNull(curveNames);/*w ww. ja  v  a  2s .c  o  m*/
    Validate.notNull(curvesKnots);
    Validate.notNull(instruments);
    Validate.notNull(extrapolator);

    final int n = curveNames.size();
    Validate.isTrue(n == curvesKnots.size());
    int count = 0;
    for (int i = 0; i < n; i++) {
        Validate.notNull(curvesKnots.get(i));
        count += curvesKnots.get(i).length;
    }
    Validate.isTrue(count <= instruments.size(), "more nodes than instruments");

    final LinkedHashMap<String, Interpolator1D> unknownCurveInterpolators = new LinkedHashMap<String, Interpolator1D>();
    final LinkedHashMap<String, double[]> unknownCurveNodes = new LinkedHashMap<String, double[]>();

    for (int i = 0; i < n; i++) {
        unknownCurveInterpolators.put(curveNames.get(i), extrapolator);
        unknownCurveNodes.put(curveNames.get(i), curvesKnots.get(i));
    }
    if (curveYields == null) {
        return new YieldCurveFittingTestDataBundle(instruments, knownCurves, unknownCurveNodes,
                unknownCurveInterpolators, marketValueCalculator, marketValueSensitivityCalculator, marketRates,
                startPosition, useFiniteDifferenceByDefault, fxMatrix);
    }

    Validate.isTrue(curveYields.size() == n, "wrong number of true yields");
    final HashMap<String, double[]> yields = new HashMap<String, double[]>();
    for (int i = 0; i < n; i++) {
        yields.put(curveNames.get(i), curveYields.get(i));
    }
    return new YieldCurveFittingTestDataBundle(instruments, knownCurves, unknownCurveNodes,
            unknownCurveInterpolators, marketValueCalculator, marketValueSensitivityCalculator, marketRates,
            startPosition, yields, useFiniteDifferenceByDefault, fxMatrix);
}

From source file:ded.model.Diagram.java

public static LinkedHashMap<String, Color> makeDefaultColors() {
    LinkedHashMap<String, Color> m = new LinkedHashMap<String, Color>();

    // These colors are non-standard.  I chose them manually,
    // based on factors like readability, garishness and
    // ability to differentiate from each other.  One of them
    // is the same as the selection color, which introduces
    // some ambiguity, but it is a really nice color so I do
    // not want to lose it in either place.
    m.put("Gray", new Color(192, 192, 192));
    m.put("White", Color.WHITE);
    m.put("Light Gray", new Color(224, 224, 224));
    m.put("Orange", new Color(236, 125, 70));
    m.put("Yellow", new Color(234, 236, 52));
    m.put("Green", new Color(76, 222, 76));
    m.put("Sky Blue", new Color(135, 193, 255)); // Selection color.
    m.put("Purple", new Color(161, 140, 237));
    m.put("Pink", new Color(227, 120, 236));
    m.put("Red", new Color(248, 50, 50)); // Very intense...

    return m;//  w  w  w. j a v a2s.c  o m
}

From source file:azkaban.util.json.JSONUtils.java

/**
 * Recurses through the json object to create a Map/List/Object equivalent.
 * /*from   ww w  .  j a  v  a2  s . c o  m*/
 * @param obj
 * @return
 */
@SuppressWarnings("unchecked")
private static Map<String, Object> createObject(JSONObject obj) {
    LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();

    Iterator<String> iterator = obj.keys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = null;
        try {
            value = obj.get(key);
        } catch (JSONException e) {
            // Since we get the value from the key given by the JSONObject, 
            // this exception shouldn't be thrown.
        }

        if (value instanceof JSONArray) {
            value = createArray((JSONArray) value);
        } else if (value instanceof JSONObject) {
            value = createObject((JSONObject) value);
        }

        map.put(key, value);
    }

    return map;
}

From source file:br.ufrgs.inf.dsmoura.repository.model.loadData.LoadLists.java

private static void loadSystemProperties() {
    LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();
    values.put(SystemPropertyEnum.FEEDBACK_EMAIL.getKey(), "lavoi@mydomain.com");

    values.put(SystemPropertyEnum.REPOSITORY_SUBTITLE.getKey(), "Lavoi Reuse Repository");

    values.put(SystemPropertyEnum.REPOSITORY_URL.getKey(), "http://localhost:8080/lavoi");
    values.put(SystemPropertyEnum.HOME_PAGE_URL.getKey(), "https://github.com/dsmoura/lavoi");

    values.put(SystemPropertyEnum.SMTP_HOSTNAME.getKey(), "smtp.mydomain.com");
    values.put(SystemPropertyEnum.SMTP_SSL.getKey(), "true");

    values.put(SystemPropertyEnum.EMAIL_DOMAIN_RESTRICTION.getKey(), "@mydomain.com");

    values.put(SystemPropertyEnum.REPOSITORY_EMAIL.getKey(), "lavoi@mydomain.com");
    values.put(SystemPropertyEnum.REPOSITORY_EMAIL_PASSWORD.getKey(), "password");
    values.put(SystemPropertyEnum.REPOSITORY_EMAIL_USER.getKey(), "lavoi@mydomain.com");
    values.put(SystemPropertyEnum.REPOSITORY_EMAIL_PASSWORD.getKey(), "password");

    values.put(SystemPropertyEnum.SOLR_SERVER_URL.getKey(), "http://localhost:8080/solr/");
    values.put(SystemPropertyEnum.USER_AUTHENTICATION_MODE.getKey(), "DATABASE");
    values.put(SystemPropertyEnum.USER_AUTHENTICATION_DOMAIN_PREFIX.getKey(), "mydomain-");

    for (String key : values.keySet()) {
        SystemPropertyDTO systemPropertyDTO = new SystemPropertyDTO();
        systemPropertyDTO.setKey(key);//w  w w.  ja v a  2s .c  o  m
        systemPropertyDTO.setValue(values.get(key));
        GenericDAO.getInstance().insert(systemPropertyDTO);
        logger.info("Property inserted: " + systemPropertyDTO.getKey() + " -> " + systemPropertyDTO.getValue());
    }
}