Example usage for java.util Arrays sort

List of usage examples for java.util Arrays sort

Introduction

In this page you can find the example usage for java.util Arrays sort.

Prototype

public static void sort(Object[] a) 

Source Link

Document

Sorts the specified array of objects into ascending order, according to the Comparable natural ordering of its elements.

Usage

From source file:de.qaware.chronix.solr.query.analysis.functions.math.NElements.java

/**
 * @param type        the calculation type: BOTTOM or TOP
 * @param n           the number of values n bottom or top values
 * @param timesStamps the time stamps of the time series
 * @param values      the belonging values of the time series
 * @return a result containing the top / bottom measurements (timestamp + value) of the time series
 *///from  w  w  w .  ja va 2 s .c  om
public static NElementsResult calc(NElementsCalculation type, int n, long[] timesStamps, double[] values) {
    //we have to convert them to a pair array, to not loose the reference to the time stamps
    Pair[] pairs = create(values);
    Arrays.sort(pairs);

    double[] nValues = new double[n];
    long[] nTimes = new long[n];

    switch (type) {
    case TOP:
        int j = 0;
        for (int i = timesStamps.length - 1; timesStamps.length - n <= i; i--) {
            nValues[j] = pairs[i].value;
            nTimes[j] = timesStamps[pairs[i].index];
            j++;
        }
        break;
    case BOTTOM:
        for (int i = 0; i < n; i++) {
            nValues[i] = pairs[i].value;
            nTimes[i] = timesStamps[pairs[i].index];
        }
        break;
    default:
        throw new EnumConstantNotPresentException(NElementsCalculation.class,
                "Type: " + type + " not available");
    }

    return new NElementsResult(nTimes, nValues);
}

From source file:fastcall.FArrayUtils.java

/**
 * Return sorted unique array of string/*from   ww w  .  ja va2  s  .co  m*/
 * @param input
 * @return 
 */
public static String[] getUniqueStringArray(String[] input) {
    HashSet<String> t = new HashSet();
    for (int i = 0; i < input.length; i++) {
        t.add(input[i]);
    }
    String[] result = t.toArray(new String[t.size()]);
    Arrays.sort(result);
    return result;
}

From source file:com.wallellen.wechat.common.util.crypto.SHA1.java

/**
 * arr??sha1 digest//from  www .  java 2 s.  c  o m
 *
 * @param arr
 * @return
 */
public static String gen(String... arr) throws NoSuchAlgorithmException {
    Arrays.sort(arr);
    StringBuilder sb = new StringBuilder();
    for (String a : arr) {
        sb.append(a);
    }
    return DigestUtils.sha1Hex(sb.toString());
}

From source file:com.github.frankfarrell.snowball.Application.java

private static void printBeans() {
    System.out.println("Beans List:");

    String[] beanNames = ctx.getBeanDefinitionNames();
    Arrays.sort(beanNames);
    for (String beanName : beanNames) {
        System.out.println(beanName);
    }//from w ww . j ava2s  . c  o m
}

From source file:com.opengamma.analytics.math.statistics.descriptive.robust.InterquartileRangeCalculator.java

@Override
public Double evaluate(final double[] x) {
    Validate.notNull(x, "x");
    final int n = x.length;
    Validate.isTrue(n > 3, "Need at least four points to calculate IQR");
    final double[] copy = Arrays.copyOf(x, n);
    Arrays.sort(copy);
    double[] lower, upper;
    if (n % 2 == 0) {
        lower = Arrays.copyOfRange(copy, 0, n / 2);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    } else {/*from w ww  .  j  av a  2  s  .com*/
        lower = Arrays.copyOfRange(copy, 0, n / 2 + 1);
        upper = Arrays.copyOfRange(copy, n / 2, n);
    }
    return MEDIAN.evaluate(upper) - MEDIAN.evaluate(lower);
}

From source file:metrolink.MetrolinkCalculator.java

public long getNextArrivalTime(List<StopTime> stopTimes, String time) {
    LocalTime[] timeArray = new LocalTime[stopTimes.size()];
    for (int i = 0; i < stopTimes.size(); i++) {
        timeArray[i] = convertTime(stopTimes.get(i).getArrivalTime());
    }/*w ww  .j  a  va 2  s  .c  o  m*/
    Arrays.sort(timeArray);
    LocalTime convertedTime = convertTime(time);
    LocalTime timeResult = null;
    for (LocalTime currentTime : timeArray) {
        //            System.out.println( currentTime );
        if (currentTime.compareTo(convertedTime) >= 0) {
            timeResult = currentTime;
            break;
        }
    }
    if (timeResult == null) {
        timeResult = timeArray[0];
    }
    long difference = convertedTime.until(timeResult, ChronoUnit.MINUTES);
    if (difference < 0) {
        difference += ONEDAYINMINUTES;
    }
    return difference;
}

From source file:com.insightml.utils.io.IoUtils.java

public static File[] files(final File dir) {
    final File[] files = dir.listFiles();
    if (files == null) {
        return null;
    }/*w  w w.  jav  a  2s . c o m*/
    Arrays.sort(files);
    return files;
}

From source file:name.abhijitsarkar.programminginterviews.hashtables.PracticeQuestionsCh12.java

@SuppressWarnings("unchecked")
public static List<List<String>> anagrams(final List<String> dictionary) {
    final MultiMap<Integer, Integer> anagramMap = new MultiValueMap<Integer, Integer>();

    char[] arr = null;
    int hashCode = -1;

    for (int i = 0; i < dictionary.size(); ++i) {
        arr = dictionary.get(i).toCharArray();
        Arrays.sort(arr);

        hashCode = String.valueOf(arr).hashCode();

        anagramMap.put(hashCode, i);/* w  ww . j a  v a 2 s.co m*/
    }

    final List<List<String>> anagrams = new ArrayList<>();
    final Set<Entry<Integer, Object>> anagramIndices = anagramMap.entrySet();
    List<Integer> aSet = null;

    for (final Object o : anagramIndices) {
        aSet = (List<Integer>) ((Entry<Integer, Object>) o).getValue();

        if (aSet.size() > 1) {
            final List<String> an = new ArrayList<>();

            for (final int i : aSet) {
                an.add(dictionary.get(i));
            }
            anagrams.add(an);
        }
    }

    return anagrams;
}

From source file:net.darkmist.clf.DirTraverser.java

private static <T> T[] sort(T... a) {
    Arrays.sort(a);
    return a;
}

From source file:docbook.ArticleRoundTripTest.java

private static TestSuite listCases(File dir) {
    TestSuite cases = new TestSuite(dir.getName());
    String[] testFiles = dir.list(new FilenameFilter() {
        public boolean accept(File file, String filename) {
            return !filename.startsWith(".") && filename.endsWith(".docbook");
        }/*www  .  ja  v a 2s  .  c  o  m*/
    });
    Arrays.sort(testFiles);
    for (String filename : testFiles) {
        File f = new File(dir, filename);
        if (f.isDirectory()) {
            cases.addTest(listCases(f));
        } else {
            String name = f.getAbsolutePath();
            if (f.getPath().startsWith(testDir.getPath() + '/')) {
                name = f.getPath().substring(testDir.getPath().length() + 1);
            }
            cases.addTest(new ArticleRoundTripTest(name));
        }
    }
    return cases;
}