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:de.upb.wdqa.wdvd.datamodel.oldjson.jackson.JsonNormalizer.java

private static Map<String, JacksonMonolingualTextValue> getNewLabels(LinkedHashMap<String, String> labels) {
    LinkedHashMap<String, JacksonMonolingualTextValue> result = new LinkedHashMap<String, JacksonMonolingualTextValue>();

    if (labels != null) {
        for (Entry<String, String> entry : labels.entrySet()) {
            JacksonMonolingualTextValue mltv = new JacksonMonolingualTextValue(entry.getKey(),
                    entry.getValue());/* w  ww.  j  a  v  a  2 s. c  o m*/
            result.put(entry.getKey(), mltv);
        }
    }

    return result;
}

From source file:com.ikanow.infinit.e.harvest.extraction.document.file.XmlToMetadataParser.java

static public LinkedHashMap<String, Object> convertJsonObjectToLinkedHashMap(JSONObject json,
        boolean bHtmlUnescape) {
    LinkedHashMap<String, Object> list = new LinkedHashMap<String, Object>();
    String[] names = JSONObject.getNames(json);
    if (null == names) { // (empty object)
        return null;
    }/*  w w  w  .  jav  a 2  s.  c o  m*/
    for (String name : names) {
        JSONObject rec = null;
        JSONArray jarray = null;
        try {
            jarray = json.getJSONArray(name);
            list.put(name, handleJsonArray(jarray, bHtmlUnescape));
        } catch (JSONException e2) {
            try {
                rec = json.getJSONObject(name);
                list.put(name, convertJsonObjectToLinkedHashMap(rec, bHtmlUnescape));
            } catch (JSONException e) {
                try {
                    if (bHtmlUnescape) {
                        list.put(name, StringEscapeUtils.unescapeHtml(json.getString(name)));
                    } else {
                        list.put(name, json.getString(name));
                    }
                } catch (JSONException e1) {
                    e1.printStackTrace();
                }
            }
        }
    }
    if (list.size() > 0) {
        return list;
    }
    return null;
}

From source file:ai.susi.mind.SusiTransfer.java

private static LinkedHashMap<String, String> parse(String mapping) {
    LinkedHashMap<String, String> columns;
    String[] column_list = mapping.trim().split(",");
    if (column_list.length == 1 && column_list[0].equals("*")) {
        columns = null;/*from   w w  w . java 2  s  .com*/
    } else {
        columns = new LinkedHashMap<>();
        for (String column : column_list) {
            String c = column.trim();
            int p = c.indexOf(" AS ");
            if (p < 0) {
                c = trimQuotes(c);
                columns.put(c, c);
            } else {
                columns.put(trimQuotes(c.substring(0, p).trim()), trimQuotes(c.substring(p + 4).trim()));
            }
        }
    }
    return columns;
}

From source file:com.opengamma.analytics.financial.interestrate.InstrumentSingleCurveSensitivityCalculatorTest.java

private static YieldCurveBundle getYieldCurveMap(final YieldCurveFittingTestDataBundle data,
        final DoubleMatrix1D yieldCurveNodes) {
    final HashMap<String, double[]> yields = unpackYieldVector(data, yieldCurveNodes);
    final LinkedHashMap<String, YieldAndDiscountCurve> curves = new LinkedHashMap<String, YieldAndDiscountCurve>();
    for (final String name : data.getCurveNames()) {
        final YieldAndDiscountCurve curve = makeYieldCurve(yields.get(name),
                data.getCurveNodePointsForCurve(name), data.getInterpolatorForCurve(name));
        curves.put(name, curve);
    }/*from ww  w. j av  a2s  . co  m*/
    return new YieldCurveBundle(curves);
}

From source file:org.loklak.geo.GeoNames.java

/**
 * Helper function which generates the same result as the mix method using a list of single-word tags.
 * Because these words are not sorted in any way the creation of the mix result is much easier.
 * @param tags//from ww w.  j a  va 2 s . c om
 * @return a hastable where the key is the hash code of the lowercase of the tags and the value is the original tag
 */
public static LinkedHashMap<Integer, String> nomix(final String[] tags) {
    LinkedHashMap<Integer, String> r = new LinkedHashMap<>();
    if (tags != null)
        for (String t : tags)
            r.put(normalize(t).hashCode(), t);
    return r;
}

From source file:ch.astina.hesperid.web.services.SecurityModule.java

static LinkedHashMap<RequestKey, Collection<ConfigAttribute>> convertCollectionToLinkedHashMap(
        Collection<RequestInvocationDefinition> urls) {

    LinkedHashMap<RequestKey, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<RequestKey, Collection<ConfigAttribute>>();
    for (RequestInvocationDefinition url : urls) {

        requestMap.put(url.getRequestKey(), url.getConfigAttributeDefinition());
    }//from w w  w .  jav a2s. c  om
    return requestMap;
}

From source file:annis.visualizers.component.grid.EventExtractor.java

/**
* Converts Salt document graph to rows.//from   w w  w .j a  v a2s .  com
*
* @param graph
* @param annotationNames
* @param startTokenIndex token index of the first token in the match
* @param endTokenIndex token index of the last token in the match
* @return
*/
public static LinkedHashMap<String, ArrayList<Row>> parseSalt(VisualizerInput input,
        List<String> annotationNames, long startTokenIndex, long endTokenIndex) {

    SDocumentGraph graph = input.getDocument().getSDocumentGraph();

    // only look at annotations which were defined by the user
    LinkedHashMap<String, ArrayList<Row>> rowsByAnnotation = new LinkedHashMap<String, ArrayList<Row>>();

    for (String anno : annotationNames) {
        rowsByAnnotation.put(anno, new ArrayList<Row>());
    }

    int eventCounter = 0;

    PDFPageHelper pageNumberHelper = new PDFPageHelper(input);

    for (SSpan span : graph.getSSpans()) {
        // calculate the left and right values of a span
        // TODO: howto get these numbers with Salt?
        long leftLong = span.getSFeature(ANNIS_NS, FEAT_LEFTTOKEN).getSValueSNUMERIC();
        long rightLong = span.getSFeature(ANNIS_NS, FEAT_RIGHTTOKEN).getSValueSNUMERIC();

        leftLong = clip(leftLong, startTokenIndex, endTokenIndex);
        rightLong = clip(rightLong, startTokenIndex, endTokenIndex);

        int left = (int) (leftLong - startTokenIndex);
        int right = (int) (rightLong - startTokenIndex);

        for (SAnnotation anno : span.getSAnnotations()) {
            ArrayList<Row> rows = rowsByAnnotation.get(anno.getQName());
            if (rows == null) {
                // try again with only the name
                rows = rowsByAnnotation.get(anno.getSName());
            }
            if (rows != null) {
                // only do something if the annotation was defined before

                // 1. give each annotation of each span an own row
                Row r = new Row();

                String id = "event_" + eventCounter++;
                GridEvent event = new GridEvent(id, left, right, anno.getSValueSTEXT());

                // check if the span is a matched node
                SFeature featMatched = span.getSFeature(ANNIS_NS, FEAT_MATCHEDNODE);
                Long match = featMatched == null ? null : featMatched.getSValueSNUMERIC();
                event.setMatch(match);

                // calculate overlapped SToken
                EList<Edge> outEdges = graph.getOutEdges(span.getSId());
                if (outEdges != null) {
                    for (Edge e : outEdges) {
                        if (e instanceof SSpanningRelation) {
                            SSpanningRelation spanRel = (SSpanningRelation) e;

                            SToken tok = spanRel.getSToken();
                            event.getCoveredIDs().add(tok.getSId());

                            // get the STextualDS of this token and add it to the event
                            EList<Edge> tokenOutEdges = graph.getOutEdges(tok.getSId());
                            if (tokenOutEdges != null) {
                                for (Edge tokEdge : tokenOutEdges) {
                                    if (tokEdge instanceof STextualRelation) {
                                        event.setTextID(((STextualRelation) tokEdge).getSTextualDS().getSId());
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                // try to get time annotations
                double[] startEndTime = TimeHelper.getOverlappedTime(span);
                if (startEndTime.length == 1) {
                    event.setStartTime(startEndTime[0]);
                } else if (startEndTime.length == 2) {
                    event.setStartTime(startEndTime[0]);
                    event.setEndTime(startEndTime[1]);
                }

                r.addEvent(event);
                rows.add(r);

                String page = pageNumberHelper.getPageFromAnnotation(span);
                if (page != null) {
                    event.setPage(page);
                }
            }
        } // end for each annotation of span
    } // end for each span

    // 2. merge rows when possible
    for (Map.Entry<String, ArrayList<Row>> e : rowsByAnnotation.entrySet()) {
        mergeAllRowsIfPossible(e.getValue());
    }

    // 3. sort events on one row by left token index
    for (Map.Entry<String, ArrayList<Row>> e : rowsByAnnotation.entrySet()) {
        for (Row r : e.getValue()) {
            sortEventsByTokenIndex(r);
        }
    }

    // 4. split up events if they have gaps
    for (Map.Entry<String, ArrayList<Row>> e : rowsByAnnotation.entrySet()) {
        for (Row r : e.getValue()) {
            splitRowsOnGaps(r, graph, startTokenIndex, endTokenIndex);
        }
    }
    return rowsByAnnotation;
}

From source file:com.ikanow.aleph2.harvest.script.services.TestScriptHarvestService.java

private static DataBucketBean getTestbucket(final String full_name, final Optional<String> script,
        final Optional<String> local_script_file, Optional<String> resource_file,
        final Map<String, String> args, final List<String> required_assets) {
    final LinkedHashMap<String, Object> config = new LinkedHashMap<String, Object>();
    if (script.isPresent())
        config.put("script", script.get());
    if (local_script_file.isPresent())
        config.put("local_script_url", local_script_file.get());
    if (resource_file.isPresent())
        config.put("resource_name", resource_file.get());
    config.put("args", args);
    config.put("required_assets", required_assets);
    final List<HarvestControlMetadataBean> harvest_configs = new ArrayList<HarvestControlMetadataBean>();
    harvest_configs.add(/*from  ww w .  j a v  a  2s. c om*/
            new HarvestControlMetadataBean("harvester_1", true, null, new ArrayList<String>(), null, config));
    return BeanTemplateUtils.build(DataBucketBean.class).with(DataBucketBean::full_name, full_name)
            .with(DataBucketBean::harvest_configs, harvest_configs)
            .with(DataBucketBean::owner_id, "test_owner_id1234").done().get();
}

From source file:com.feilong.taglib.display.pager.PagerBuilder.java

/**
 * ? index end  =href map./*from   w w w . jav  a2s .  c  o  m*/
 *
 * @param indexAndHrefMap
 *            the index and href map
 * @param startIteratorIndex
 *            ?
 * @param endIteratorIndex
 *            ??
 * @return the iterator index and href map
 * @since 1.8.1 change method param
 */
private static LinkedHashMap<Integer, String> getIteratorIndexAndHrefMap(Map<Integer, String> indexAndHrefMap,
        int startIteratorIndex, int endIteratorIndex) {
    LinkedHashMap<Integer, String> map = newLinkedHashMap(endIteratorIndex - startIteratorIndex + 1);
    for (int i = startIteratorIndex; i <= endIteratorIndex; ++i) {
        map.put(i, indexAndHrefMap.get(i));
    }
    return map;
}

From source file:Main.java

/**
 * This method will find all the parameters under this <code>paramsElement</code> and return them as
 * Map<String, String>. For example,
 * <pre>// w  ww  .  j a  v a  2 s.c o  m
 *   <result ... >
 *      <param name="param1">value1</param>
 *      <param name="param2">value2</param>
 *      <param name="param3">value3</param>
 *   </result>
 * </pre>
 * will returns a Map<String, String> with the following key, value pairs :-
 * <ul>
 *  <li>param1 - value1</li>
 *  <li>param2 - value2</li>
 *  <li>param3 - value3</li>
 * </ul>
 *
 * @param paramsElement
 * @return
 */
public static Map getParams(Element paramsElement) {
    LinkedHashMap params = new LinkedHashMap();

    if (paramsElement == null) {
        return params;
    }

    NodeList childNodes = paramsElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);

        if ((childNode.getNodeType() == Node.ELEMENT_NODE) && "param".equals(childNode.getNodeName())) {
            Element paramElement = (Element) childNode;
            String paramName = paramElement.getAttribute("name");

            String val = getContent(paramElement);
            if (val.length() > 0) {
                params.put(paramName, val);
            }
        }
    }
    return params;
}