Java BigDecimal sortMapByBDValue(Map oriMap)

Here you can find the source of sortMapByBDValue(Map oriMap)

Description

sort Map By BD Value

License

Open Source License

Declaration

public static <T> Map<T, BigDecimal> sortMapByBDValue(Map<T, BigDecimal> oriMap) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

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

import java.util.Map.Entry;

public class Main {
    public static <T> Map<T, BigDecimal> sortMapByBDValue(Map<T, BigDecimal> oriMap) {
        Map<T, BigDecimal> sortedMap = new LinkedHashMap<T, BigDecimal>();
        if (oriMap != null && !oriMap.isEmpty()) {
            List<Map.Entry<T, BigDecimal>> entryList = new ArrayList<Map.Entry<T, BigDecimal>>(oriMap.entrySet());
            Collections.sort(entryList, new Comparator<Map.Entry<T, BigDecimal>>() {
                public int compare(Entry<T, BigDecimal> entry1, Entry<T, BigDecimal> entry2) {
                    BigDecimal value1 = entry1.getValue();
                    BigDecimal value2 = entry2.getValue();

                    return value2.compareTo(value1);
                }//from   w  w  w  .j a  v  a  2s  .  co m
            });
            Iterator<Map.Entry<T, BigDecimal>> iter = entryList.iterator();
            Map.Entry<T, BigDecimal> tmpEntry = null;
            while (iter.hasNext()) {
                tmpEntry = iter.next();
                sortedMap.put(tmpEntry.getKey(), tmpEntry.getValue());
            }
        }
        return sortedMap;
    }
}

Related

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