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.aliyun.odps.graph.local.utils.LocalGraphRunUtils.java

private static TableInfo[] getTables(JobConf conf, String descKey) throws IOException {
    String inputDesc = conf.get(descKey, "[]");
    if (inputDesc != "[]") {
        JSONArray inputs = JSON.parseArray(inputDesc);
        TableInfo[] infos = new TableInfo[inputs.size()];
        for (int i = 0; i < inputs.size(); i++) {
            JSONObject input = inputs.getJSONObject(i);
            String projName = input.getString("projName");
            if (StringUtils.isEmpty(projName)) {
                projName = SessionState.get().getOdps().getDefaultProject();
            }//  w  ww  .j  a  v  a  2 s  .com
            String tblName = input.getString("tblName");
            if (StringUtils.isEmpty(tblName)) {
                throw new IOException(
                        ExceptionCode.ODPS_0720001 + " - input table name cann't be empty: " + input);
            }

            JSONArray parts = input.getJSONArray("partSpec");
            LinkedHashMap<String, String> partSpec = new LinkedHashMap<String, String>();
            for (int j = 0; j < parts.size(); j++) {
                String part = parts.getString(j);
                String[] part_val = part.split("=");
                partSpec.put(part_val[0], part_val[1]);
            }
            String[] cols = null;
            if (input.get("cols") != null) {
                String readCols = input.getString("cols");

                // check column duplicate
                cols = readCols.split("\\,");
                for (int cur = 0; cur < cols.length; ++cur) {
                    for (int k = cur + 1; k < cols.length; ++k) {
                        if (cols[cur].equals(cols[k])) {
                            throw new IOException(ExceptionCode.ODPS_0720091 + " - " + cols[cur]);
                        }
                    }
                }
            }
            String label = TableInfo.DEFAULT_LABEL;
            if (input.get("label") != null) {
                String tmpLabel = input.getString("label");
                if (!StringUtils.isEmpty(tmpLabel)) {
                    label = tmpLabel;
                }
            }
            TableInfo info = TableInfo.builder().tableName(tblName).projectName(projName).partSpec(partSpec)
                    .cols(cols).label(label).build();
            infos[i] = info;
        }
        return infos;
    }
    return new TableInfo[0];
}

From source file:mitm.common.postfix.PostfixMainConfigParser.java

public static LinkedHashMap<String, String> parse(Reader config) {
    LinkedHashMap<String, String> values = new LinkedHashMap<String, String>();

    List<String> lines = normalize(config);

    int i = 0;//from  w  w  w.j  av a 2s .  c  om

    for (String line : lines) {
        Matcher matcher = NAME_VALUE.matcher(line);

        if (!line.startsWith("#") && matcher.matches()) {
            String value = matcher.group(2);

            if (value == null) {
                value = "";
            }

            values.put(matcher.group(1), value);
        } else {
            values.put(OTHER_LINE_NAME + i++, line);
        }
    }

    return values;
}

From source file:Main.java

@SuppressWarnings("unchecked")
static public LinkedHashMap<Object, Comparable> sortHashMapByValues(HashMap<Object, Comparable> passedMap) {
    ArrayList mapKeys = new ArrayList(passedMap.keySet());
    ArrayList mapValues = new ArrayList(passedMap.values());
    Collections.sort(mapValues);// ww w.j  a  v a2 s.  c o m
    Collections.sort(mapKeys);

    LinkedHashMap<Object, Comparable> sortedMap = new LinkedHashMap<Object, Comparable>();

    Iterator<Comparable> valueIt = mapValues.iterator();
    while (valueIt.hasNext()) {
        Comparable val = valueIt.next();
        Iterator keyIt = mapKeys.iterator();

        while (keyIt.hasNext()) {
            Object key = keyIt.next();
            Comparable comp = passedMap.get(key);

            if (comp.equals(val)) {
                passedMap.remove(key);
                mapKeys.remove(key);
                sortedMap.put(key, val);
                break;
            }

        }
    }
    return sortedMap;
}

From source file:nu.localhost.tapestry5.springsecurity.services.SecurityModule.java

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

    LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();
    for (RequestInvocationDefinition url : urls) {
        requestMap.put(url.getRequestMatcher(), url.getConfigAttributeDefinition());
    }/*from w  ww .j a  va 2  s .co m*/
    return requestMap;
}

From source file:com.uksf.mf.core.utility.ClassNames.java

/**
 * Gets class names from file on uksf server
 * @return map of class names: old, new/*from w  w w .j a  v a  2  s  .  c om*/
 */
public static LinkedHashMap<String, String> getClassNames() {
    LinkedHashMap<String, String> classNames = new LinkedHashMap<>();
    try {
        URL url = new URL("http://www.uk-sf.com/mf/CLASSES.txt");
        if (checkConnection(url)) {
            throw new IOException();
        }
        InputStream stream = url.openStream();
        List<String> lines = IOUtils.readLines(stream, "UTF-8");
        for (String line : lines) {
            String parts[] = line.split(",", -1);
            if (parts[1] == null)
                parts[1] = "";
            classNames.put(parts[0], parts[1]);
        }
    } catch (IOException e) {
        LogHandler.logSeverity(WARNING, "Cannot reach 'www.uk-sf.com', class name swap will not run");
        return null;
    }
    return classNames;
}

From source file:com.amazon.android.utils.JsonHelper.java

/**
 * Helper method to parse a JSONObject.//from w ww  . ja  v  a 2s  . c om
 *
 * @param object The JSONObject to parse.
 * @return A Map containing the key/value pairs of the JSONObject. If the object passed in is
 * null, an empty map is returned.
 * @throws Exception if the JSON-encoded object is malformed.
 */
private static Map parseObject(JSONObject object) throws Exception {

    LinkedHashMap<String, Object> map = new LinkedHashMap<>();

    if (object != null) {

        Iterator<String> keys = object.keys();

        // Loop through all keys
        while (keys.hasNext()) {

            String key = keys.next();

            try {
                // Parse the value associated with the key and add it to the map.
                map.put(key, parseValue(object.get(key)));

            } catch (JSONException e) {

                Log.e(TAG, "Invalid key-value mapping for key: " + key, e);
                throw new MalformedJSONException("Malformed JSON. Contains a bad key: " + key, e);
            }
        }
    }
    return map;
}

From source file:com.atinternet.tracker.Tool.java

/**
 * Get parameters// w  w  w  .  jav a 2  s  . c om
 *
 * @param hit String
 * @return HashMap
 */
static LinkedHashMap<String, String> getParameters(String hit) {
    LinkedHashMap<String, String> map = new LinkedHashMap<String, String>();
    try {
        URL url = new URL(hit);
        map.put("ssl", url.getProtocol().equals("http") ? "Off" : "On");
        map.put("log", url.getHost());
        String[] queryComponents = url.getQuery().split("&");
        for (String queryComponent : queryComponents) {
            String[] elem = queryComponent.split("=");
            if (elem.length > 1) {
                elem[1] = Tool.percentDecode(elem[1]);
                if (Tool.parseJSON(elem[1]) instanceof JSONObject) {
                    JSONObject json = (JSONObject) Tool.parseJSON(elem[1]);
                    if (json != null && elem[0].equals(Hit.HitParam.JSON.stringValue())) {
                        map.put(elem[0], json.toString(3));
                    } else {
                        map.put(elem[0], elem[1]);
                    }
                } else {
                    map.put(elem[0], elem[1]);
                }
            } else {
                map.put(elem[0], "");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return map;
}

From source file:org.fusesource.meshkeeper.util.internal.IntrospectionSupport.java

public static String toString(Object target, Class<?> stopClass, Map<String, Object> overrideFields) {
    LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
    addFields(target, target.getClass(), stopClass, map);
    if (overrideFields != null) {
        for (String key : overrideFields.keySet()) {
            Object value = overrideFields.get(key);
            map.put(key, value);
        }//  w w w . ja  v  a  2 s. com

    }
    StringBuffer buffer = new StringBuffer(simpleName(target.getClass()));
    buffer.append(" {");
    Set<Entry<String, Object>> entrySet = map.entrySet();
    boolean first = true;
    for (Iterator<Entry<String, Object>> iter = entrySet.iterator(); iter.hasNext();) {
        Entry<String, Object> entry = iter.next();
        if (first) {
            first = false;
        } else {
            buffer.append(", ");
        }
        buffer.append(entry.getKey());
        buffer.append(" = ");
        appendToString(buffer, entry.getValue());
    }
    buffer.append("}");
    return buffer.toString();
}

From source file:max.hubbard.bettershops.Utils.ItemUtils.java

public static Map<String, Object> deserialize(String s) {
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();

    s = s.substring(1, s.length() - 1); //remove curly brackets
    String[] keyValuePairs = s.split(",");

    for (String pair : keyValuePairs) {
        String[] entry = pair.split("=");
        String g = entry[1];//from ww w . j av a 2 s . co  m
        if (entry.length > 2) {
            for (int i = 2; i < entry.length; i++) {
                g = g + "=" + entry[i];
            }
        }

        map.put(entry[0].trim(), g.trim());

    }

    return map;
}

From source file:com.act.lcms.db.model.StandardIonResult.java

private static LinkedHashMap<String, XZ> deserializeStandardIonAnalysisResult(String jsonEntry)
        throws IOException {
    // We have to re-sorted the deserialized results so that we meet the contract expected by the caller.
    Map<String, XZ> deserializedResult = OBJECT_MAPPER.readValue(jsonEntry, typeRefForStandardIonAnalysis);
    TreeMap<Double, String> sortedIntensityToIon = new TreeMap<>(Collections.reverseOrder());

    for (Map.Entry<String, XZ> val : deserializedResult.entrySet()) {
        sortedIntensityToIon.put(val.getValue().getIntensity(), val.getKey());
    }/* w w  w .  j  av  a2  s  .  c om*/

    LinkedHashMap<String, XZ> sortedResult = new LinkedHashMap<>();
    for (Map.Entry<Double, String> val : sortedIntensityToIon.entrySet()) {
        String ion = val.getValue();
        sortedResult.put(ion, deserializedResult.get(ion));
    }

    return sortedResult;
}