swap to values of the array

@param array
@param left left value to swap
@param right right value to swap
@throws ExpressionException
424074
public static void swap(Array array, int left, int right) throws ExpressionException {
	int len = array.size();

	if (len == 0) throw new ExpressionException("array is empty");
	if (left < 1 || left > len) throw new ExpressionException("invalid index [" + left + "]", "valid indexes are from 1 to " + len);
	if (right < 1 || right > len) throw new ExpressionException("invalid index [" + right + "]", "valid indexes are from 1 to " + len);

	try {
	    Object leftValue = array.get(left, null);
	    Object rightValue = array.get(right, null);

	    array.setE(left, rightValue);
	    array.setE(right, leftValue);
	}
	catch (PageException e) {
	    throw new ExpressionException("can't swap values of array", e.getMessage());
	}

    }
439190
private static Expression infix(String infix, String left, String right) {
        return new Expression(left + " " + infix + " " + right);
    }
499758
public static void sort(double[] doubleArray) {
        boolean swapped = true;
        
        while(swapped) {
            swapped = false;
            
            for(int i = 0; i < (doubleArray.length - 1 ); i++) {
                if(doubleArray[i] > doubleArray[i + 1]) {
                    TrivialSwap.swap(doubleArray, i, i + 1);
                    
                    swapped = true;
                }
            }            
        }
    }
1034671
public static void swap(long[] longArray, int index1, int index2) {
        XORSwap.swap(longArray, index1, longArray, index2);
    }
881224
public static void swap(double[] doubleArray, int index1, int index2) {
        TrivialSwap.swap(doubleArray, index1, doubleArray, index2);
    }
754159
public static void shuffle(float[] floatArray) {
		int swapPlace = -1;

		for(int i = 0; i < floatArray.length; i++) {
            swapPlace = (int) (Math.random() * (floatArray.length - 1 ));
            TrivialSwap.swap(floatArray, i, swapPlace);
		}
	}
504933
public static void swap(short[] shortArray, int index1, int index2) {
        TrivialSwap.swap(shortArray, index1, shortArray, index2);
    }
72379
function swap(array, i, j) {
    var temp = array[i];
    array[i] = array[j];
    array[j] = temp;
  }
341872
protected Expression reOrder(Expression left, Expression right, BinaryOperation.Op op) {
        if (right instanceof BinaryOperation) {
            BinaryOperation rightOp = (BinaryOperation) right;
            if (!rightOp.isSealed() && rightOp.getOp().getPriority() == op.getPriority()) {
                replaceLeft(rightOp, left, op);
                return right;
            }
        }
        return new BinaryOperation(op, left, right);
    }
1181769
public static void swapCols(double[][] matrix, int col1, int col2) {
		double temp = 0;
		int rows = matrix.length;
		double[] r = null;
		for (int row = 0; row < rows; row++) {
			r = matrix[row];
			temp = r[col1];
			r[col1] = r[col2];
			r[col2] = temp;
		}
	}
860642
public static void swap(float arr[], int i, int j) {
        float a = arr[i];
        arr[i] = arr[j];
        arr[j] = a;
    }
787788
public static void swap(final int[][] array, final long first, final long second)
    {
        final int t = array[segment(first)][displacement(first)];
        array[segment(first)][displacement(first)] = array[segment(second)][displacement(second)];
        array[segment(second)][displacement(second)] = t;
    }
521844
@Override
    public void swap(INDArray x, INDArray y) {
        if (Nd4j.getExecutioner().getProfilingMode() == OpExecutioner.ProfilingMode.ALL)
            OpProfiler.getInstance().processBlasCall(false, x, y);

        if (x.isSparse() || y.isSparse()) {
            Nd4j.getSparseBlasWrapper().level1().swap(x, y);
            return;
        }

        if (x.data().dataType() == DataType.DOUBLE) {
            DefaultOpExecutioner.validateDataType(DataType.DOUBLE, x, y);
            dswap(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y));
        } else {
            DefaultOpExecutioner.validateDataType(DataType.FLOAT, x, y);
            sswap(x.length(), x, BlasBufferUtil.getBlasStride(x), y, BlasBufferUtil.getBlasStride(y));
        }
    }
275363
private static void reverse(int[] array, int start, int end) {
		for (int i = start, j = end; i < --j; ++i) {
			int t = array[i];
			array[i] = array[j];
			array[j] = t;
		}
	}
219005
private static <T extends Comparable<? super T>> 
    void mergeSort( T[] arr, T[] tmpArr, int left, int right )
    {
        //recursive way
        if ( left < right ) {
            int center = ( left + right ) / 2;
            mergeSort(arr, tmpArr, left, center);
            mergeSort(arr, tmpArr, center + 1, right);
            merge(arr, tmpArr, left, center + 1, right);
        }
        
        //loop instead
/*        int len = 2, pos;
        int rpos, offset, cut;
        while ( len <= right ) {
            pos = 0;
            offset = len / 2;
            while ( pos + len <= right  ) {
                rpos = pos + offset;
                merge( arr, tmpArr, pos, rpos, rpos + offset - 1 );
                pos += len;
            }
            
            //merge the rest
            cut = pos + offset;
            if ( cut <= right ) 
                merge( arr, tmpArr, pos, cut, right );
            
            len *= 2;
        }
        merge( arr, tmpArr, 0, len / 2, right );*/
    }
722417
public static void shuffle (Object[] values, int offset, int length)
    {
        shuffle(values, offset, length, _rnd);
    }
1180806
public static <T> void arrangeByIndex(T[] array, Integer[] indexes) {
        if(array.length != indexes.length) {
            throw new IllegalArgumentException("The length of the two arrays must match.");
        }
        
        //sort the array based on the indexes
        for(int i=0;i<array.length;i++) {
            int index = indexes[i];
            
            //swap
            T tmp = array[i];
            array[i] = array[index];
            array[index] = tmp;
        }
    }