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

@SafeVarargs
public static <K, V> Map<K, V> merge(Map<K, V>... maps) {
    if (maps == null) {
        return null;
    }//from   w ww.  j a va2s .co  m
    Map<K, V> result = null;
    for (Map<K, V> map : maps) {
        if (map != null) {
            if (result == null) {
                result = new LinkedHashMap<K, V>();
            }
            result.putAll(map);
        }
    }
    return result;
}

From source file:Main.java

public static LinkedHashMap<String, String> convertBeans(Object bean) {
    if (bean == null)
        return null;
    try {/*from   w  w w  .ja  v  a  2s .  c o m*/
        LinkedHashMap<String, String> returnMap = new LinkedHashMap<String, String>();

        Class<? extends Object> clazz = bean.getClass();
        List<Field> fleids = new ArrayList<Field>();
        for (Class<?> c = clazz; c != Object.class; c = c.getSuperclass()) {
            fleids.addAll(Arrays.asList(c.getDeclaredFields()));
        }

        for (Field field : fleids) {
            String value = "";
            field.setAccessible(true);
            try {
                Object result = field.get(bean);
                if (result == null)
                    continue;
                value = result.toString();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            //            MLogUtil.e("field.getName() "+field.getName());
            //            MLogUtil.e("value "+value);
            returnMap.put(field.getName(), value);
            field.setAccessible(false);
        }
        return returnMap;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> Map<T, Object> asMap(T key, Object... values) {
    if ((values == null || values.length == 0) && key instanceof Map) {
        return (Map<T, Object>) key;
    }//from  w w  w  . j  ava  2s.  c  o m

    Map<T, Object> result = new LinkedHashMap<>();

    if (values == null) {
        result.put(key, null);
        return result;
    }

    if (values.length % 2 == 0) {
        throw new IllegalArgumentException("value[] must be not null and an odd length");
    }

    result.put(key, values[0]);
    for (int i = 1; i < values.length; i += 2) {
        result.put((T) values[i], values[i + 1]);
    }

    return result;
}

From source file:Main.java

public static String getApplyStatus(List<Map<String, String>> certificdetals) {
    String state = "00";
    if (null == certificdetals || certificdetals.size() <= 0) {
        return state;
    }//  ww w.  j  av  a 2  s.  c o m

    int size = certificdetals.size();
    Map<String, String> CERTIFICDETAL = new LinkedHashMap<String, String>();
    CERTIFICDETAL = certificdetals.get(size - 1);

    if (null != CERTIFICDETAL) {
        state = CERTIFICDETAL.get("CERTIFICSTATUS");
    }
    return state;
}

From source file:Main.java

/**
 * get attribute map from the element/*ww w .  jav  a  2s.co m*/
 * @param el - element
 * @return mapping of attributes
 */
public static Map<String, String> getAttributes(Element el) {
    Map<String, String> list = new LinkedHashMap<String, String>();
    NamedNodeMap map = el.getAttributes();
    for (int i = 0; i < map.getLength(); i++) {
        list.put(map.item(i).getNodeName(), map.item(i).getNodeValue());
    }
    return list;
}

From source file:Main.java

/**
 * Sorts a Map by it's value//from  ww  w  . ja  v  a 2  s.com
 *
 * @param map Map
 * @param <K> Key
 * @param <V> Value
 * @return The sorted map
 */
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
    Map<K, V> result = new LinkedHashMap<>();
    Stream<Map.Entry<K, V>> st = map.entrySet().stream();

    st.sorted(Comparator.comparing(Map.Entry::getValue))
            .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));

    return result;
}

From source file:Main.java

public static String getScreenInfos(Context context) {
    Map<String, String> infos = new LinkedHashMap<>();

    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int densityDpi = dm.densityDpi;
    float density = dm.density;
    int height = dm.heightPixels;
    int width = dm.widthPixels;

    infos.put("Screen", String.valueOf(width + " x " + height));
    infos.put("Density / DPI", String.valueOf(densityDpi) + " / " + getHumanReadableDpi(density));
    infos.put("Current orientation", getHumanReadableOrientation(context));
    infos.put("Display", Build.DISPLAY);

    StringBuilder sb = new StringBuilder();

    sb.append("<table class=\"table table-striped\">");
    sb.append("<tbody>");

    for (Map.Entry<String, String> deviceInfo : infos.entrySet()) {
        sb.append("<tr><th>");
        sb.append(deviceInfo.getKey());//from   w w w.j a va 2  s . com
        sb.append("</th><td>");
        sb.append(deviceInfo.getValue());
        sb.append("</td></tr>");
    }
    sb.append("<tbody>");
    sb.append("</table>");

    return sb.toString();
}

From source file:Main.java

@SafeVarargs
public static <T> Map<T, T> createMap(T... array) {
    if (array == null || array.length == 0) {
        return null;
    }//from  w w w  . j av a  2  s  . c  o  m
    if (array.length % 2 != 0) {
        throw new IllegalArgumentException("Array size must be even number.");
    }
    Map<T, T> map = new LinkedHashMap<T, T>();
    for (int i = 0; i < array.length; i += 2) {
        map.put(array[i], array[i + 1]);
    }
    return map;
}

From source file:Main.java

/**
 * Remove duplicate values of list from map
 * @param values - Map of values// w w w  . ja v  a2s. c  om
 * @param <T> - Object class
 * @param <K> - Key
 * @return - Result Map without duplcates
 */
public static <T, K> Map<K, List<T>> removeDuplicateValues(Map<K, List<T>> values) {
    if (values == null) {
        return values;
    }
    Map<K, List<T>> newValues = new LinkedHashMap<K, List<T>>();
    for (K key : values.keySet()) {
        newValues.put(key, removeDuplicateValues(values.get(key)));
    }
    return newValues;
}

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 va2  s . c  om
    return result;
}