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:com.twosigma.beakerx.table.TableDisplayConverter.java

public static List<Map<String, Object>> convert(int rowCount, int columnCount, List<String> columnNames,
        TableDisplay.Element tableElement) {
    List<Map<String, Object>> result = new ArrayList<>();
    for (int r = 0; r < rowCount; r++) {
        Map<String, Object> entry = new LinkedHashMap<>();
        for (int c = 0; c < columnCount; c++) {
            Object value = tableElement.get(c, r);
            String headerName = columnNames.get(c);
            if (headerName.equals("time")) {
                entry.put(headerName, convertDate(value));
            } else {
                entry.put(headerName, convertToNumber(value));
            }//from   ww  w .  j  a  va2s. c o  m
        }
        result.add(entry);
    }
    return result;
}

From source file:Main.java

/**
 * Prepares Array style form fields from a given array of values
 * @param    value   Value for the form fields
 * @return   Dictionary of form fields created from array elements
 *///ww  w  .  ja va 2  s. c o m
public static Map<String, Object> prepareFormFields(Object value) {
    Map<String, Object> formFields = new LinkedHashMap<String, Object>();
    if (value != null) {
        try {
            objectToMap("", value, formFields, new HashSet<Integer>());
        } catch (Exception ex) {
        }
    }
    return formFields;
}

From source file:Main.java

public static <K, V> Map<K, V> mapOf(K key, V value, K key2, V value2, K key3, V value3) {
    Map<K, V> map = new LinkedHashMap<K, V>();
    map.put(key, value);/*from   w  w  w  .jav a  2  s  .  co  m*/
    map.put(key2, value2);
    map.put(key3, value3);
    return map;
}

From source file:Main.java

private static Map sortByComparator(Map unsortMap) {
    List list = new LinkedList(unsortMap.entrySet());
    Collections.sort(list, new Comparator() {
        public int compare(Object o1, Object o2) {
            return ((Comparable) ((Map.Entry) (o1)).getValue()).compareTo(((Map.Entry) (o2)).getValue());
        }//www  .  ja  va  2  s  . co m
    });
    Map sortedMap = new LinkedHashMap();
    for (Iterator it = list.iterator(); it.hasNext();) {
        Map.Entry entry = (Map.Entry) it.next();
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;
}

From source file:com.reachlocal.grails.plugins.cassandra.utils.DataMapper.java

public static Map<String, Object> dataProperties(Map<String, Object> data) throws IOException {
    Map<String, Object> map = new LinkedHashMap<String, Object>();
    for (Map.Entry<String, Object> entry : data.entrySet()) {
        Object value = entry.getValue();
        map.put(entry.getKey(), dataProperty(entry.getValue()));
    }/*w w  w.j a va 2  s .c o m*/
    return map;
}

From source file:Main.java

/**
 * Sort a map according to its values in ascending order when asc=true and i descending order otherwise.
 * @param unsortedMap //from  w w  w  . j  a  v  a2  s  .co m
 * @param asc
 * @return
 */
public static Map<String, Integer> sortUsingComparator(Map<String, Integer> unsortedMap, final boolean asc) {

    // Convert Map to List
    List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortedMap.entrySet());

    // Sort a list using custom comparator, to compare the Map values
    Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
        public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
            if (asc) {
                return (o1.getValue()).compareTo(o2.getValue());
            } else {
                return -1 * (o1.getValue()).compareTo(o2.getValue());
            }
        }
    });

    // Convert the sorted map back to a Map
    Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
    for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
        Map.Entry<String, Integer> entry = it.next();
        sortedMap.put(entry.getKey(), entry.getValue());
    }
    return sortedMap;
}

From source file:Main.java

public static <K, V> Map<K, V> keyify(Stream<? extends V> stream, Function<? super V, K> keyAssigner) {
    Map<K, V> result = new LinkedHashMap<>();
    stream.forEach(v -> result.put(keyAssigner.apply(v), v));
    return result;
}

From source file:org.focusns.common.web.WebUtils.java

public static Map<String, String> getMatrixParameters(HttpServletRequest request) {
    ///*from w  ww . j  a va2  s.co m*/
    Map<String, String> parameterMap = new LinkedHashMap<String, String>();
    //
    String requestUri = request.getRequestURI();
    if (requestUri.contains(";")) {
        String paramsString = requestUri.substring(requestUri.indexOf(";") + 1);
        String[] paramsPair = new String[] { paramsString };
        if (paramsString.contains(",")) {
            paramsPair = StringUtils.tokenizeToStringArray(paramsString, ",");
        }
        for (String paramPair : paramsPair) {
            String[] nameAndValue = StringUtils.split(paramPair, "=");
            parameterMap.put(nameAndValue[0], nameAndValue[1]);
        }
    }
    return parameterMap;
}

From source file:org.openmrs.contrib.discohub.HttpUtils.java

public static Map<String, Object> getData(String url, Header[] headers) throws IOException {
    final Map<String, Object> responseMap = new LinkedHashMap<>();
    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(url);
    httpget.setHeaders(headers);//from   w  w  w . j a  v  a  2 s .  com

    // Create a custom response handler
    ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
        @Override
        public String handleResponse(final HttpResponse response) throws ClientProtocolException, IOException {
            int status = response.getStatusLine().getStatusCode();
            if (status >= 200 && status < 300) {
                HttpEntity entity = response.getEntity();
                responseMap.put("headers", response.getAllHeaders());
                //System.out.println("Ratelimit attempts left: " + response.getHeaders("X-RateLimit-Remaining")[0]);
                //System.out.println("Etag = " + response.getHeaders("ETag")[0]);
                return entity != null ? EntityUtils.toString(entity) : null;
            } else if (status == 304) {
                //System.out.println("GOT 304!!!");
                return null;
            } else {
                throw new ClientProtocolException("Unexpected response status: " + status);
            }
        }

    };
    String responseBody = httpclient.execute(httpget, responseHandler);
    responseMap.put("content", responseBody);
    return responseMap;
}

From source file:enmasse.controller.flavor.FlavorParser.java

public static Map<String, Flavor> parse(JsonNode root) {
    Map<String, Flavor> flavorMap = new LinkedHashMap<>();
    for (int i = 0; i < root.size(); i++) {
        Flavor flavor = parseFlavor(root.get(i));
        flavorMap.put(flavor.name(), flavor);
    }/*  www. j a v  a  2 s  . com*/
    return flavorMap;
}