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(Map<? extends K, ? extends V> m) 

Source Link

Document

Constructs an insertion-ordered LinkedHashMap instance with the same mappings as the specified map.

Usage

From source file:Main.java

public static <K, V> Map<K, V> valueSortedMap(Map<K, V> map, Comparator<Entry<K, V>> comparator) {
    Set<Entry<K, V>> valueSortedEntries = new TreeSet<Entry<K, V>>(comparator);

    for (Entry<K, V> entry : map.entrySet()) {
        valueSortedEntries.add(entry);/* w w w.  ja va2  s .c  o  m*/
    }

    Map<K, V> sortedMap = new LinkedHashMap<K, V>(map.size());
    for (Entry<K, V> entry : valueSortedEntries) {
        sortedMap.put(entry.getKey(), entry.getValue());
    }

    return sortedMap;
}

From source file:Main.java

@Nullable
public static Map<String, String> getAllAttributesAsMap(@Nullable final Element aSrcNode) {
    if (aSrcNode != null) {
        final NamedNodeMap aNNM = aSrcNode.getAttributes();
        if (aNNM != null) {
            final Map<String, String> aMap = new LinkedHashMap<String, String>(aNNM.getLength());
            final int nMax = aNNM.getLength();
            for (int i = 0; i < nMax; ++i) {
                final Attr aAttr = (Attr) aNNM.item(i);
                aMap.put(aAttr.getName(), aAttr.getValue());
            }// ww  w .  j a  v a 2s.  c o  m
            return aMap;
        }
    }
    return null;
}

From source file:Main.java

/**
 * Returns a linked hash map typed to the generics specified in the method
 * call with the given initial capacity/*from w  w  w  .ja va2  s. co m*/
 */
public static <K, V> Map<K, V> createLinkedHashMap(int initialCapacity) {
    return new LinkedHashMap<K, V>(initialCapacity);
}

From source file:Main.java

public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(final Map<? extends K, ? extends V> m) {
    return new LinkedHashMap<K, V>(m);
}

From source file:Main.java

/**
 * Given two maps with disjoint key sets, merges them and returns the merged map.
 *
 * @param map1  The first map to merge/*from  w  w  w.  java 2 s .  com*/
 * @param map2  The second map to merge
 * @param <T>  The key type of the maps
 * @param <U>  The value type of the maps
 *
 * @return  A new map that is the merger of the two parameters
 */
public static <T, U> LinkedHashMap<T, U> mergeMaps(Map<T, U> map1, Map<T, U> map2) {
    LinkedHashMap<T, U> newMap = new LinkedHashMap<>(map1);
    newMap.putAll(map2);
    return newMap;
}

From source file:com.iotekclass.common.util.Collections3.java

/**
 * ????(Getter), ??Map.// ww w.  ja v a  2s. c om
 * 
 * @param collection ???.
 * @param linked ??.
 * @param keyPropertyName ????MapKey??.
 * @param valuePropertyName ????MapValue??.
 */
public static Map extractToMap(final Collection collection, boolean linked, final String keyPropertyName,
        final String valuePropertyName) {

    Map map = null;
    if (linked) {
        map = new LinkedHashMap(collection.size());
    } else {
        map = new HashMap(collection.size());
    }
    try {
        for (Object obj : collection) {
            map.put(PropertyUtils.getProperty(obj, keyPropertyName),
                    PropertyUtils.getProperty(obj, valuePropertyName));
        }
    } catch (Exception e) {
        throw Reflections.convertReflectionExceptionToUnchecked(e);
    }

    return map;
}

From source file:Main.java

private static Map<String, Object> getAttributes(Node node) {
    NamedNodeMap attribs = node.getAttributes();
    int attribCount = attribs.getLength();
    Map<String, Object> map = new LinkedHashMap<>(attribCount);
    for (int j = 0; j < attribCount; j++) {
        Node attrib = attribs.item(j);
        map.put(attrib.getNodeName(), attrib.getNodeValue());
    }//from w  ww  .j  a  v a2s .  c  om
    return map;
}

From source file:org.tamacat.util.CacheLRU.java

 public CacheLRU(int maxSize) {
   this.maxSize = maxSize;
   this.cache = new LinkedHashMap<K,V>(maxSize);
   this.used = new ArrayList<K>(maxSize);
}

From source file:com.almende.eve.protocol.jsonrpc.formats.Params.java

/**
 * Instantiates a new config.
 */
public Params() {
    super(JOM.getInstance().getNodeFactory(), new LinkedHashMap<String, JsonNode>(2));
}

From source file:Main.java

/**
 * Returns a map of the passed node's attributes
 * @param node The nopde to get an attribute map for
 * @return a [possibly empty] map of the node's attributes
 *///  w w  w  .  j a  v a 2 s.  co m
public static Map<String, String> getAttributeMap(final Node node) {
    if (node == null)
        throw new IllegalArgumentException("The passed node was null");
    final NamedNodeMap nnm = node.getAttributes();
    final int size = nnm.getLength();
    if (size == 0)
        return Collections.emptyMap();
    final Map<String, String> map = new LinkedHashMap<String, String>(size);
    for (int i = 0; i < size; i++) {
        final Attr attr = (Attr) nnm.item(i);
        map.put(attr.getName(), attr.getValue());
    }
    return map;
}