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:info.mikaelsvensson.devtools.analysis.shared.AbstractAnalyzer.java

public static String getFormattedString(String pattern, File patternArgumentSourceFile) {
    // LinkedHashMap since the values should be returned in the order of insertion (for backwards compatibility)
    final LinkedHashMap<String, Object> values = new LinkedHashMap<String, Object>();
    values.put("logFileName", patternArgumentSourceFile.getName());
    values.put("logFileNameWithoutExt",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getName(), "."));
    values.put("logFilePath",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getAbsolutePath(), "."));
    values.put("logFilePathWithoutExt",
            StringUtils.substringBeforeLast(patternArgumentSourceFile.getAbsolutePath(), "."));
    values.put("parentName", patternArgumentSourceFile.getParentFile().getName());
    values.put("parentPath", patternArgumentSourceFile.getParentFile().getAbsolutePath());

    // Add numeric "key" for each "parameter" (for backwards compability)
    int i = 0;/*from   w  ww  .  j a  va 2s .  co m*/
    for (Object value : values.values().toArray()) {
        values.put(String.valueOf(i++), value);
    }

    // Use {key} format instead of ${key}, thus providing backwards compatibility with previously used MessageFormat.
    return StrSubstitutor.replace(pattern, values, "{", "}");
}

From source file:Main.java

/**
 * We could simple return new String(displayColumns + "," + valueColumn) but we want to handle the cases
 * where the displayColumns (valueColumn) contain more commas than needed, in the middle, start or end.
 *
 * @param valueColumn    single string to appear first.
 * @param displayColumns comma-separated string
 * @return A {@link java.util.LinkedHashMap} that contains the SQL columns as keys, and the CSV columns as values
 *///w  w w . j  a v a 2s .  co m
public static LinkedHashMap<String, String> createMapWithDisplayingColumns(String valueColumn,
        String displayColumns) {
    valueColumn = valueColumn.trim();

    LinkedHashMap<String, String> columns = new LinkedHashMap<String, String>();

    columns.put(toSafeColumnName(valueColumn), valueColumn);

    if (displayColumns != null && displayColumns.trim().length() > 0) {
        displayColumns = displayColumns.trim();

        List<String> commaSplitParts = splitTrimmed(displayColumns, COLUMN_SEPARATOR,
                FALLBACK_COLUMN_SEPARATOR);

        for (String commaSplitPart : commaSplitParts) {
            columns.put(toSafeColumnName(commaSplitPart), commaSplitPart);
        }
    }

    return columns;
}

From source file:MapUtils.java

/**
 * Sorts map by values in ascending order.
 * /*from   w w  w.ja v  a2s  .c om*/
 * @param <K>
 *            map keys type
 * @param <V>
 *            map values type
 * @param map
 * @return
 */
public static <K, V extends Comparable<V>> LinkedHashMap<K, V> sortMapByValue(Map<K, V> map) {
    List<Entry<K, V>> sortedEntries = sortEntriesByValue(map.entrySet());
    LinkedHashMap<K, V> sortedMap = new LinkedHashMap<K, V>(map.size());
    for (Entry<K, V> entry : sortedEntries) {
        sortedMap.put(entry.getKey(), entry.getValue());
    }

    return sortedMap;
}

From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.IOHelper.java

/**
 * Sorts map by value (http://stackoverflow.com/a/2581754)
 *
 * @param map map/*from  www  .  jav a  2 s.c  om*/
 * @param <K> key
 * @param <V> value
 * @return sorted map by value
 */
public static <K, V extends Comparable<? super V>> LinkedHashMap<K, V> sortByValue(Map<K, V> map,
        final boolean asc) {
    List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        @Override
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            if (asc) {
                return (o1.getValue()).compareTo(o2.getValue());
            } else {
                return (o2.getValue()).compareTo(o1.getValue());
            }
        }
    });

    LinkedHashMap<K, V> result = new LinkedHashMap<>();
    for (Map.Entry<K, V> entry : list) {
        result.put(entry.getKey(), entry.getValue());
    }
    return result;
}

From source file:Main.java

public static LinkedHashMap<String, String> attrbiuteToMap(NamedNodeMap attributes) {
    if (attributes == null)
        return new LinkedHashMap<String, String>();
    LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        result.put(attributes.item(i).getNodeName(), attributes.item(i).getNodeValue());
    }/*w  ww .j a  va 2s . co  m*/
    return result;
}

From source file:com.none.tom.simplerssreader.utils.SearchUtils.java

public static LinkedHashMap<Integer, Integer> getIndicesForQuery(final String str, final String query) {
    final LinkedHashMap<Integer, Integer> indices = new LinkedHashMap<>();

    int start = StringUtils.indexOfIgnoreCase(str, query);

    indices.put(start, start + query.length());

    for (++start; (start = StringUtils.indexOfIgnoreCase(str, query, start)) > 0; start++) {
        indices.put(start, start + query.length());
    }//from w w  w.j a v  a2 s  .c om

    return indices;
}

From source file:Main.java

public static <K, V> LinkedHashMap<K, V> headMap(LinkedHashMap<K, V> map, int endIndex, boolean inclusive) {
    int index = endIndex;
    if (inclusive) {
        index++;/*from w  w  w . ja v a 2 s.co  m*/
    }
    if ((map == null) || (map.size() == 0) || (map.size() < index) || (endIndex < 0)) {
        return new LinkedHashMap<K, V>(0);
    }
    LinkedHashMap<K, V> subMap = new LinkedHashMap<K, V>(index + 1);
    int i = 0;
    for (Map.Entry<K, V> entry : map.entrySet()) {
        if (i < index) {
            subMap.put(entry.getKey(), entry.getValue());
        }
        i++;
    }
    return subMap;
}

From source file:ch.gianulli.trelloapi.TrelloList.java

public static TrelloList getList(TrelloAPI api, Board board, String id)
        throws TrelloNotAuthorizedException, TrelloNotAccessibleException {
    try {/*from  w w w.  ja  v  a2 s .c o m*/
        LinkedHashMap<String, String> args = new LinkedHashMap<>();
        args.put("cards", "open");
        args.put("card_fields", "name,desc");
        JSONObject list = api.makeJSONObjectRequest("GET", "lists/" + id, args, true);
        if (list != null) {
            JSONArray cardArray = list.getJSONArray("cards");
            ArrayList<Card> cards = new ArrayList<>(cardArray.length());
            for (int j = 0; j < cardArray.length(); ++j) {
                JSONObject card = cardArray.getJSONObject(j);
                cards.add(new Card(card.getString("id"), null, card.getString("name"), card.getString("desc"))); // list is null for now
            }
            TrelloList trelloList = new TrelloList(list.getString("id"), board, list.getString("name"), cards);
            // add list reference to cards
            for (Card c : cards) {
                c.setList(trelloList);
            }

            return trelloList;
        }
    } catch (JSONException e) {
        throw new TrelloNotAccessibleException("Server answer was not correctly formatted.");
    }

    return null;
}

From source file:com.streamsets.pipeline.stage.util.http.HttpStageUtil.java

public static Record createEnvelopeRecord(PushSource.Context context, DataParserFactory parserFactory,
        List<Record> successRecords, List<Record> errorRecords, int statusCode, String errorMessage,
        DataFormat dataFormat) {/*from   w w  w .  j a v a2s  .  com*/
    Record envelopeRecord = context.createRecord("envelopeRecord");
    LinkedHashMap<String, Field> envelopeRecordVal = new LinkedHashMap<>();
    envelopeRecordVal.put("httpStatusCode", Field.create(statusCode));
    if (errorMessage != null) {
        envelopeRecordVal.put("errorMessage", Field.create(errorMessage));
    }
    envelopeRecordVal.put("data", Field.create(convertRecordsToFields(parserFactory, successRecords)));
    envelopeRecordVal.put("error", Field.create(convertRecordsToFields(parserFactory, errorRecords)));
    if (dataFormat.equals(DataFormat.XML)) {
        // XML format requires single key map at the root
        envelopeRecord.set(Field.create(ImmutableMap.of("response", Field.createListMap(envelopeRecordVal))));
    } else {
        envelopeRecord.set(Field.createListMap(envelopeRecordVal));
    }
    return envelopeRecord;
}

From source file:Main.java

public static <T> LinkedHashMap<String, T> arraryToLinkedHashMap(T[] itemsArray) {
    LinkedHashMap<String, T> map = new LinkedHashMap<String, T>();
    T[] arrayOfObject = itemsArray;//from   w w  w  . j  a va  2  s .com
    int j = itemsArray.length;
    for (int i = 0; i < j; i++) {
        T s = arrayOfObject[i];
        map.put(s.toString(), s);
    }
    return map;
}