Java Array Invert invert(byte abyte0[])

Here you can find the source of invert(byte abyte0[])

Description

invert

License

Open Source License

Declaration

public static final byte[] invert(byte abyte0[]) 

Method Source Code

//package com.java2s;
/**//from w w  w .j  av a 2s  .  c o m
 * This file is part of JEMMA - http://jemma.energy-home.org
 * (C) Copyright 2013 Telecom Italia (http://www.telecomitalia.it)
 *
 * JEMMA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License (LGPL) version 3
 * or later as published by the Free Software Foundation, which accompanies
 * this distribution and is available at http://www.gnu.org/licenses/lgpl.html
 *
 * JEMMA is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License (LGPL) for more details.
 *
 */

public class Main {
    public static final byte[] invert(byte abyte0[]) {
        if (abyte0 == null || abyte0.length == 0)
            return abyte0;
        byte abyte1[] = new byte[abyte0.length];
        for (int i = 0; i < abyte0.length; i++)
            abyte1[i] = abyte0[abyte0.length - i - 1];

        return abyte1;
    }

    public static final void invert(byte abyte0[], int i, byte abyte1[],
            int j, int k) {
        if (abyte0 == null || abyte0.length == 0 || k == 0)
            return;
        int l = Math.min(abyte0.length - 1, (i + k) - 1);
        for (int i1 = l; i1 >= i; i1--) {
            if (j >= abyte1.length)
                throw new ArrayIndexOutOfBoundsException(
                        "Destination array has insuffiecient length. Destination offset reached "
                                + j + " while dest length is "
                                + abyte1.length);
            abyte1[j] = abyte0[i1];
            j++;
        }

    }
}

Related

  1. invert(boolean[] binary)
  2. invert(boolean[] result)
  3. invert(byte[] array)
  4. invert(byte[] bytes)
  5. invert(byte[] key)
  6. invert(byte[] v)