Java Array Sort deltaMetricToSortedIndicies( final double[][] deltaMetric)

Here you can find the source of deltaMetricToSortedIndicies( final double[][] deltaMetric)

Description

delta Metric To Sorted Indicies

License

Open Source License

Declaration

public static <TK, FV> int[][] deltaMetricToSortedIndicies(
            final double[][] deltaMetric) 

Method Source Code

//package com.java2s;
import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class Main {
    public static <TK, FV> int[][] deltaMetricToSortedIndicies(
            final double[][] deltaMetric) {
        class DeltaIndex implements Comparable<DeltaIndex> {
            public int i, j;

            public DeltaIndex(int i, int j) {
                this.i = i;
                this.j = j;
            }// w w  w.j ava  2  s  . co m

            @Override
            public int compareTo(DeltaIndex o) {
                double diff = deltaMetric[i][j] - deltaMetric[o.i][o.j];
                if (diff < 0)
                    return -1;
                else if (diff > 0)
                    return 1;
                else
                    return 0;
            }

        }
        ;
        int[][] indices = new int[deltaMetric.length][];
        for (int i = 0; i < indices.length; i++) {
            indices[i] = new int[deltaMetric[i].length];
            List<DeltaIndex> sortList = new ArrayList<DeltaIndex>(
                    indices[i].length);
            for (int j = 0; j < indices[i].length; j++) {
                sortList.add(new DeltaIndex(i, j));
            }
            Collections.sort(sortList);
            for (int j = 0; j < indices[i].length; j++) {
                indices[i][j] = sortList.get(j).j;
            }
        }
        return indices;
    }
}

Related

  1. copyAndSort(String[] input)
  2. copyAndSort(T[] builtinFunctions)
  3. copySortArray(String[] values)
  4. countingSort(int[] a, int low, int high)
  5. countingSort(int[] array, int low, int high)
  6. difference(int[] sorted1, int[] sorted2)
  7. extractFields(String[] items, int[] fields, String delim, boolean sortKeyFields)
  8. getLeftIndex(float[] sorted, float value)
  9. getMedianIndex(float[] sorted, float value)