Java BigInteger Calculate copyOfRange(BigInteger[] data, int from, int to)

Here you can find the source of copyOfRange(BigInteger[] data, int from, int to)

Description

copy Of Range

License

Apache License

Declaration

public static BigInteger[] copyOfRange(BigInteger[] data, int from,
            int to) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.math.BigInteger;

public class Main {
    public static byte[] copyOfRange(byte[] data, int from, int to) {
        int newLength = getLength(from, to);

        byte[] tmp = new byte[newLength];

        if (data.length - from < newLength) {
            System.arraycopy(data, from, tmp, 0, data.length - from);
        } else {//from  ww w .  ja  v a2  s  . co  m
            System.arraycopy(data, from, tmp, 0, newLength);
        }

        return tmp;
    }

    public static int[] copyOfRange(int[] data, int from, int to) {
        int newLength = getLength(from, to);

        int[] tmp = new int[newLength];

        if (data.length - from < newLength) {
            System.arraycopy(data, from, tmp, 0, data.length - from);
        } else {
            System.arraycopy(data, from, tmp, 0, newLength);
        }

        return tmp;
    }

    public static long[] copyOfRange(long[] data, int from, int to) {
        int newLength = getLength(from, to);

        long[] tmp = new long[newLength];

        if (data.length - from < newLength) {
            System.arraycopy(data, from, tmp, 0, data.length - from);
        } else {
            System.arraycopy(data, from, tmp, 0, newLength);
        }

        return tmp;
    }

    public static BigInteger[] copyOfRange(BigInteger[] data, int from,
            int to) {
        int newLength = getLength(from, to);

        BigInteger[] tmp = new BigInteger[newLength];

        if (data.length - from < newLength) {
            System.arraycopy(data, from, tmp, 0, data.length - from);
        } else {
            System.arraycopy(data, from, tmp, 0, newLength);
        }

        return tmp;
    }

    private static int getLength(int from, int to) {
        int newLength = to - from;
        if (newLength < 0) {
            StringBuffer sb = new StringBuffer(from);
            sb.append(" > ").append(to);
            throw new IllegalArgumentException(sb.toString());
        }
        return newLength;
    }
}

Related

  1. chop(BigInteger in, int bits)
  2. clip(BigInteger bi, int numberOfBytes)
  3. clone(BigInteger[] data)
  4. copy_into_byte_array(BigInteger bi, byte[] a)
  5. copyOf(BigInteger[] data, int newLength)
  6. createUnsignedBigInteger(byte[] data)
  7. createUUID(int version, String gtin, BigInteger phar)
  8. cryptRSA(byte[] data, BigInteger exponent, BigInteger modulus)
  9. decodeBigInteger(String value)