Example usage for org.apache.commons.lang3 ArrayUtils reverse

List of usage examples for org.apache.commons.lang3 ArrayUtils reverse

Introduction

In this page you can find the example usage for org.apache.commons.lang3 ArrayUtils reverse.

Prototype

public static void reverse(final short[] array, final int startIndexInclusive, final int endIndexExclusive) 

Source Link

Document

Reverses the order of the given array in the given range.

Usage

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Rotates portion of input array in specified range in place by specified
 * number of points. {@code n>0} corresponds to shift to the right,
 * {@code n<0} corresponds to shift to the left. No error checking is
 * performed on range limits; if the values are negative or outside the
 * range of the array, a runtime exception may be thrown. No action is
 * performed if {@code a} is {@code null} or zero-length, if
 * {@code to-from<=0}, or if {@code abs(n)<0}.
 *
 * @param a      input array/*from ww  w.  j  a  v  a  2s. c  om*/
 * @param n    number of places to shift
 * @param from initial index of the range in which to rotate elements,
 *             inclusive
 * @param to   final index of the range in which to rotate elements,
 *             exclusive
 */
public static final void rotateArrayInPlace(double[] a, int n, int from, int to) {
    int absN = Math.abs(n);
    int size = to - from;

    if (a != null && size > 0 && absN > 0 && a.length > 0) {

        if (absN > size) {
            absN = absN % size;
        }

        if (n > 0) {
            ArrayUtils.reverse(a, from, from + size);
        }

        ArrayUtils.reverse(a, from, from + absN);
        ArrayUtils.reverse(a, from + absN, from + size);

        if (n < 0) {
            ArrayUtils.reverse(a, from, from + size);
        }
    }
}

From source file:com.github.jonmarsh.waveform_processing_for_imagej.WaveformUtils.java

/**
 * Rotates portion of input array in specified range in place by specified
 * number of points.{@code n>0} corresponds to shift to the right,
 * {@code n<0} corresponds to shift to the left. No error checking is
 * performed on range limits; if the values are negative or outside the
 * range of the array, a runtime exception may be thrown. No action is
 * performed if {@code a} is {@code null} or zero-length, if
 * {@code to-from<=0}, or if {@code abs(n)<0}.
 *
 * @param a      input array//from  ww w.j  av  a  2 s.  c o m
 * @param n      number of places to shift
 * @param from initial index of the range in which to rotate elements,
 *             inclusive
 * @param to   final index of the range in which to rotate elements,
 *             exclusive
 */
public static final void rotateArrayInPlace(float[] a, int n, int from, int to) {
    int absN = Math.abs(n);
    int size = to - from;

    if (a != null && size > 0 && absN > 0 && a.length > 0) {

        if (absN > size) {
            absN = absN % size;
        }

        if (n > 0) {
            ArrayUtils.reverse(a, from, from + size);
        }

        ArrayUtils.reverse(a, from, from + absN);
        ArrayUtils.reverse(a, from + absN, from + size);

        if (n < 0) {
            ArrayUtils.reverse(a, from, from + size);
        }
    }
}