Java Map Sort sortClustersKeys(final Map> clusters)

Here you can find the source of sortClustersKeys(final Map> clusters)

Description

Sort cluster keys by their packages size.

License

Open Source License

Parameter

Parameter Description
clusters Package cluster.

Return

Sorted cluster keys.

Declaration

private static List<String> sortClustersKeys(final Map<String, Set<String>> clusters) 

Method Source Code

//package com.java2s;
/*//ww  w  .j  a  v  a 2s . com
 * Copyright 2011 jccastrejon
 *  
 * This file is part of Web2MexADL.
 *
 * Web2MexADL is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * Web2MexADL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
    
 * You should have received a copy of the GNU General Public License
 * along with Web2MexADL.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.ArrayList;

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

import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
    /**
     * Sort cluster keys by their packages size.
     * 
     * @param clusters
     *            Package cluster.
     * @return Sorted cluster keys.
     */
    private static List<String> sortClustersKeys(final Map<String, Set<String>> clusters) {
        List<String> returnValue;

        returnValue = new ArrayList<String>(clusters.keySet());
        Collections.sort(returnValue, new Comparator<String>() {
            public int compare(final String first, final String second) {
                return new Integer(clusters.get(first).size()).compareTo(clusters.get(second).size());
            }
        });

        return returnValue;
    }
}

Related

  1. sortByValues(Map map)
  2. sortByValues(Map map)
  3. sortByValues(Map map)
  4. sortByValues(Map map)
  5. sortByValuesDesc(final Map map)
  6. sortDoubleMap(Map map)
  7. sortedByRankThenLength(Map map)
  8. sortedKeys(Map map)
  9. sortedMap(Map map, Comparator comparator)