Java ListIterator Usage partialSort(List list, int numTop, Comparator c)

Here you can find the source of partialSort(List list, int numTop, Comparator c)

Description

partial Sort

License

Apache License

Declaration

public static <T> void partialSort(List<T> list, int numTop, Comparator<? super T> c) 

Method Source Code

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

import java.util.Arrays;

import java.util.Comparator;

import java.util.List;
import java.util.ListIterator;

public class Main {
    public static <T> void partialSort(List<T> list, int numTop, Comparator<? super T> c) {
        Object[] a = list.toArray();
        partialSort(a, numTop, (Comparator) c);
        ListIterator<T> i = list.listIterator();
        for (int j = 0; j < a.length; j++) {
            i.next();/* ww  w . java 2s .  co m*/
            i.set((T) a[j]);
        }
    }

    public static <T> void partialSort(T[] list, int numTop, Comparator<? super T> c) {
        // Select out the numTop-th ranked element
        // TODO
        Arrays.sort(list, c); // For now, sort everything
    }

    public static int[] toArray(List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i < array.length; i++)
            array[i] = list.get(i);
        return array;
    }

    public static int[] set(int[] v, int x) {
        for (int i = 0; i < v.length; i++)
            v[i] = x;
        return v;
    }

    public static int[] set(int[] v, int x[], int n) {
        for (int i = 0; i < n; i++)
            v[i] = x[i];
        return v;
    }

    public static int[] set(int[] v, int x[]) {
        return set(v, x, v.length);
    }

    public static double[] set(double[] v, double x[]) {
        for (int i = 0; i < v.length; i++)
            v[i] = x[i];
        return v;
    }

    public static double[] set(double[] v, double x) {
        for (int i = 0; i < v.length; i++)
            v[i] = x;
        return v;
    }

    public static double[][] set(double[][] v, double[][] x) {
        for (int i = 0; i < v.length; i++)
            for (int j = 0; j < v[i].length; j++)
                v[i][j] = x[i][j];
        return v;
    }

    public static double[][] set(double[][] v, double x) {
        for (int i = 0; i < v.length; i++)
            set(v[i], x);
        return v;
    }

    public static double[][][] set(double[][][] v, double x) {
        for (int i = 0; i < v.length; i++)
            set(v[i], x);
        return v;
    }

    public static double[][][][] set(double[][][][] v, double x) {
        for (int i = 0; i < v.length; i++)
            set(v[i], x);
        return v;
    }

    public static double[][][][][] set(double[][][][][] v, double x) {
        for (int i = 0; i < v.length; i++)
            set(v[i], x);
        return v;
    }

    public static <T> T get(List<T> l, int i) {
        return get(l, i, null);
    }

    public static <T> T get(List<T> l, int i, T defValue) {
        if (i < 0)
            i += l.size();
        if (i < 0 || i >= l.size())
            return defValue;
        return l.get(i);
    }

    public static <T> T get(T[] l, int i) {
        return get(l, i, null);
    }

    public static <T> T get(T[] l, int i, T defValue) {
        if (i < 0)
            i += l.length;
        if (i < 0 || i >= l.length)
            return defValue;
        return l[i];
    }

    public static double get(double[] l, int i, double defValue) {
        if (i < 0)
            i += l.length;
        if (i < 0 || i >= l.length)
            return defValue;
        return l[i];
    }
}

Related

  1. makeSortFieldFallbackExpr(List fieldNames)
  2. normalizeVersion(String version, int length)
  3. numberToDigits(int num)
  4. overlap(List> lists, int before, int after)
  5. parsePath(String sPath)
  6. peekNext(ListIterator it)
  7. peekNext(ListIterator iterator)
  8. print(final List concatenatables)
  9. removeCustomFilters(List filters)