Example usage for java.util LinkedHashMap LinkedHashMap

List of usage examples for java.util LinkedHashMap LinkedHashMap

Introduction

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

Prototype

public LinkedHashMap() 

Source Link

Document

Constructs an empty insertion-ordered LinkedHashMap instance with the default initial capacity (16) and load factor (0.75).

Usage

From source file:Main.java

public static <K, V> LinkedHashMap<K, V> newLinkedHashMap() {
    return new LinkedHashMap<K, V>();
}

From source file:Main.java

public static Map<String, String> toMap(Attributes attributes) {
    Map<String, String> nameToValue = new LinkedHashMap<String, String>();
    for (int i = 0; i < attributes.getLength(); i++) {
        nameToValue.put(attributes.getQName(i), attributes.getValue(i));
    }//ww w .j a v a2s .c  o  m
    return nameToValue;
}

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/*w ww  . 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:Main.java

public static <KEY, VALUE> LinkedHashMap<KEY, VALUE> newLinkedHashMap() {
    return new LinkedHashMap<KEY, VALUE>();
}

From source file:Main.java

public static <E, V extends Comparable<? super V>, K> Map<K, V> sortByValueAsc(Map<K, V> map, int limit) {
    List<Map.Entry<K, V>> list = new LinkedList<Map.Entry<K, V>>(map.entrySet());
    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {
        public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) {
            return (o1.getValue()).compareTo(o2.getValue());
        }/*  ww w.j  av a  2 s.  c om*/
    });

    Map<K, V> result = new LinkedHashMap<K, V>();
    int counter = 0;
    for (Map.Entry<K, V> entry : list) {
        if (limit > 0 && counter >= limit) {
            break;
        }
        result.put(entry.getKey(), entry.getValue());
        counter++;
    }
    return result;
}

From source file:Main.java

public static Map<String, Object> merge(Map<String, Object>... maps) {
    Map<String, Object> ret = new LinkedHashMap<String, Object>();
    for (Map<String, Object> map : maps) {
        ret.putAll(map);/*ww w .  j a va 2 s.  c o m*/
    }
    return ret;
}

From source file:Main.java

public static Map<String, Object> getIvyParts(String allstr) {
    Map<String, Object> result = new LinkedHashMap<String, Object>();
    String ext = "";
    String[] parts;//  w  w  w  .  ja  v  a  2s  . c om
    if (allstr.contains("@")) {
        parts = allstr.split("@");
        if (parts.length > 2)
            return result;
        allstr = parts[0];
        ext = parts[1];
    }
    parts = allstr.split(":");
    if (parts.length > 4)
        return result;
    if (parts.length > 3)
        result.put("classifier", parts[3]);
    if (parts.length > 2)
        result.put("version", parts[2]);
    else
        result.put("version", "*");
    if (ext.length() > 0)
        result.put("ext", ext);
    result.put("module", parts[1]);
    result.put("group", parts[0]);
    return result;
}

From source file:Main.java

public static Map<String, String> parseArguments(String[] args) {
    Map<String, String> map = new LinkedHashMap<String, String>();

    for (String arg : args) {
        String strs[] = arg.split("\\=");
        if (strs.length != 2)
            continue;

        String key = strs[0];/*from   w ww  . j a v a2 s . co  m*/
        if (key.startsWith("-")) {
            key = key.substring(1);
        }
        if (key.startsWith("-")) {
            key = key.substring(1);
        }
        String value = strs[1];
        map.put(key, value);
    }

    return map;
}

From source file:Main.java

/*******
 * It is easy to accidentally create GStrings instead of String in a groovy file. This will auto correct the problem
 * for byon node definitions by calling the toString() methods for map keys and values.
 *
 * @param originalNodesList/*from   w  ww.j a  v a  2  s . co m*/
 *            .
 * @return the
 */
public static List<Map<String, String>> convertToStringMap(final List<Map<Object, Object>> originalNodesList) {
    List<Map<String, String>> nodesList;
    nodesList = new LinkedList<Map<String, String>>();

    for (final Map<Object, Object> originalMap : originalNodesList) {
        final Map<String, String> newMap = new LinkedHashMap<String, String>();
        final Set<Entry<Object, Object>> entries = originalMap.entrySet();
        for (final Entry<Object, Object> entry : entries) {
            newMap.put(entry.getKey().toString(), entry.getValue().toString());
        }
        nodesList.add(newMap);

    }
    return nodesList;
}

From source file:Main.java

/**
 * We are parsing a string like animal,-dog,--chihuahua*,-cat,--siamese
 * into a list of strings to put into ListBox and values. The strings
 * are used as keys and use tabs/whatever system to show hierarchy.
 * The values are the values themselves, with no dashes at the beginning.
 * A trailing asterisk denotes a default value and is parsed by a different function.
 *
 * @param categoryString Category string to parse.
 * @return Map with the parsed categories.
 *///from  w w  w.  j  ava  2 s .  co m
public static LinkedHashMap<String, String> parseCategories(final String categoryString) {
    final LinkedHashMap<String, String> result = new LinkedHashMap<String, String>();
    final String[] categories = splitCategoryString(categoryString);
    for (final String cat : categories) {
        final String category = cat.trim();
        final int i = getNumDashes(category);
        final int isDefault = isDefault(category) ? 1 : 0;
        final String value = category.substring(i, category.length() - isDefault);
        final String key = repeat(i, " - ") + value;
        result.put(key, value);
    }

    return result;
}