Java BigDecimal sortByValues( Map map)

Here you can find the source of sortByValues( Map map)

Description

sort By Values

License

Open Source License

Parameter

Parameter Description
map a parameter

Declaration

@SuppressWarnings({ "unchecked", "rawtypes" })
public static Map<String, BigDecimal> sortByValues(
        Map<String, BigDecimal> map) 

Method Source Code

//package com.java2s;
import java.math.BigDecimal;

import java.util.Collections;
import java.util.Comparator;

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import java.util.Map.Entry;

public class Main {
    /***/*from   www  . j a  v  a  2  s.c  om*/
     * 
     * @param map
     * @return
     */
    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static Map<String, BigDecimal> sortByValues(
            Map<String, BigDecimal> map) {
        List sortedByValueList = new LinkedList(map.entrySet());
        Collections.sort(sortedByValueList,
                new Comparator<Map.Entry<String, BigDecimal>>() {
                    public int compare(Entry<String, BigDecimal> o1,
                            Entry<String, BigDecimal> o2) {
                        return ((Comparable) (o2).getValue())
                                .compareTo((o1).getValue());
                    }
                });
        Map<String, BigDecimal> sortedHashMap = new LinkedHashMap<String, BigDecimal>();
        for (Iterator it = sortedByValueList.iterator(); it.hasNext();) {
            Map.Entry<String, BigDecimal> entry = (Map.Entry) it.next();
            sortedHashMap.put(entry.getKey(), entry.getValue());
        }
        return sortedHashMap;
    }
}

Related

  1. scale2(BigDecimal valor)
  2. scaleCurrency(BigDecimal amount)
  3. secondsBigDecimalFromDuration(long s, int n)
  4. signum(final BigDecimal value)
  5. sine(BigDecimal x)
  6. sortMapByBDValue(Map oriMap)
  7. stdBigDecimal(List vector, BigDecimal avg)
  8. stddev(List numbers, boolean biasCorrected, MathContext context)
  9. stdDevMaxFromMapField(List> dataList, String fieldName, BigDecimal stdDevMultiplier)