Java Collection Sort sortedByName(Collection unsorted, Comparator comparator, T... exclusions)

Here you can find the source of sortedByName(Collection unsorted, Comparator comparator, T... exclusions)

Description

sorted By Name

License

Apache License

Declaration

private static <T> List<T> sortedByName(Collection<T> unsorted, Comparator<T> comparator, T... exclusions) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Main {
    private static <T> List<T> sortedByName(Collection<T> unsorted, Comparator<T> comparator, T... exclusions) {
        if (unsorted == null) {
            return Collections.emptyList();
        }/*from  w  w  w  .  ja  va  2 s  .c o m*/

        List<T> retList = removeExclusionsFrom(unsorted, comparator, exclusions);
        Collections.sort(retList, comparator);

        return retList;
    }

    private static <T> List<T> removeExclusionsFrom(Collection<T> collectionOfT, Comparator<T> comparator,
            T... exclusions) {
        List<T> retList = new ArrayList<>();

        for (T t : collectionOfT) {
            boolean excluded = false;
            for (T excludedT : exclusions) {
                if (comparator.compare(t, excludedT) == 0) {
                    excluded = true;
                    break;
                }
            }
            if (!excluded) {
                retList.add(t);
            }
        }

        return retList;
    }
}

Related

  1. sorted(Collection collection)
  2. sorted(Collection ss)
  3. sorted(Collection c)
  4. sorted(Collection c)
  5. sorted(Collection collection)
  6. sortedCollection(final Comparator comparator, final Collection input)
  7. sortedIfPossible(Collection collection)
  8. sortEntities(Collection entities, Comparator comparator)
  9. sortMapByValues( final Map> related_region_counts, Comparator>> comparator)