Example usage for java.lang Integer SIZE

List of usage examples for java.lang Integer SIZE

Introduction

In this page you can find the example usage for java.lang Integer SIZE.

Prototype

int SIZE

To view the source code for java.lang Integer SIZE.

Click Source Link

Document

The number of bits used to represent an int value in two's complement binary form.

Usage

From source file:Main.java

/**
 * @param byteArray//www . j  ava2s .  c  o m
 * @return
 */
public static long byteArrayToUnsignedLong(byte[] byteArray) {
    int length;
    long value = 0;
    if (byteArray.length == Byte.SIZE / Byte.SIZE) {
        length = Byte.SIZE / Byte.SIZE;
    } else if (byteArray.length == Short.SIZE / Byte.SIZE) {
        length = Short.SIZE / Byte.SIZE;
    } else if (byteArray.length == Integer.SIZE / Byte.SIZE) {
        length = Integer.SIZE / Byte.SIZE;
    } else if (byteArray.length == Long.SIZE / Byte.SIZE) {
        length = Long.SIZE / Byte.SIZE;
    } else
        throw new IllegalArgumentException("Array length must match one of the following types:\n Byte=="
                + Byte.SIZE + ", Short==" + Short.SIZE + ", Integer==" + Integer.SIZE + ", Long==" + Long.SIZE);

    for (int i = 0; i < length; i++) {
        value |= ((0xffL & byteArray[i]) << (8 * (length - i - 1)));
    }
    return value;
}

From source file:Main.java

public static byte[] leIntToByteArray(int i) {
    final ByteBuffer bb = ByteBuffer.allocate(Integer.SIZE / Byte.SIZE);
    bb.order(ByteOrder.LITTLE_ENDIAN);
    bb.putInt(i);/*from   www . j  ava2s  . c  o  m*/
    return bb.array();
}

From source file:Main.java

/**
 * Convert the given byte array to 'int'
 * /* w  ww . j a  v a  2s  .  com*/
 * @param b
 *            A 4-byte array
 * 
 * @return int value of the array contents
 */
public static int convertBigEndianByteArrayToInt(byte[] b) {
    int capacity = Integer.SIZE / EIGHT;
    if (b.length > capacity) {
        return -1;
    }
    return ByteBuffer.wrap(b).getInt();
}

From source file:Main.java

/**
 * Convert the given int to a 4-byte array
 * /*from   www.ja  va  2s.co m*/
 * @param i
 *            An 'int'
 * 
 * @return A 4-byte array in big endian (MSB) ordering
 */
public static byte[] convertIntToByteArrayBigEndian(int i) {
    return ByteBuffer.allocate(Integer.SIZE / EIGHT).putInt(i).array();
}

From source file:Main.java

public static byte[] int2bytes(int a) {
    int arraySize = Integer.SIZE / Byte.SIZE;
    ByteBuffer buffer = ByteBuffer.allocate(arraySize);
    buffer.order(ByteOrder.LITTLE_ENDIAN);
    return buffer.putInt(a).array();
}

From source file:Main.java

/**android methods*/

//Only for Android
public static IntBuffer makeFloatBuffer(int[] array) {
    final int integerSize = Integer.SIZE / 8;
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(array.length * integerSize);
    byteBuffer.order(ByteOrder.nativeOrder());
    IntBuffer intBuffer = byteBuffer.asIntBuffer();
    intBuffer.put(array);//  www .j a  v  a  2  s  .  c om
    intBuffer.position(0);
    return intBuffer;
}

From source file:de.unijena.bioinf.FragmentationTreeConstruction.computation.recalibration.MedianSlope.java

public double[][] getMedianSubsetFairDistributed(final Spectrum<Peak> measured,
        final Spectrum<Peak> reference) {

    // for each mass range of 100 Da choose the most intensive peaks
    final SimpleSpectrum massOrderedSpectrum = new SimpleSpectrum(measured);
    final double highestMass = massOrderedSpectrum.getMzAt(massOrderedSpectrum.size() - 1);
    final ArrayList<Integer>[] chosenPeaks = new ArrayList[(int) Math.ceil(highestMass / 100)];
    for (int k = 0; k < chosenPeaks.length; ++k)
        chosenPeaks[k] = new ArrayList<Integer>();
    for (int k = 0; k < massOrderedSpectrum.size(); ++k) {
        final int bin = (int) Math.floor(massOrderedSpectrum.getMzAt(k) / 100);
        chosenPeaks[bin].add(k);/*w ww .  j a va 2s .co m*/
    }
    for (int k = 0; k < chosenPeaks.length; ++k) {
        Collections.sort(chosenPeaks[k], new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return new Double(measured.getIntensityAt(o2)).compareTo(measured.getIntensityAt(o1));
            }
        });
    }

    while (chosenPeaks[chosenPeaks.length - 1].size() < 4) {
        chosenPeaks[chosenPeaks.length - 1].add(massOrderedSpectrum.size() - 1);
    }

    // take median of bin size
    Arrays.sort(chosenPeaks, new Comparator<ArrayList<Integer>>() {
        @Override
        public int compare(ArrayList<Integer> o1, ArrayList<Integer> o2) {
            return o2.size() - o1.size();
        }
    });
    final int median = Math.max(5, chosenPeaks[chosenPeaks.length / 2].size());
    //System.err.println(median);

    final TIntArrayList allPeaks = new TIntArrayList();
    for (ArrayList<Integer> bin : chosenPeaks)
        allPeaks.addAll(bin.subList(0, Math.min(bin.size(), median)));

    // assuming that all peaks are correct, choose all peaks for recalibration
    final double[][] peaks = new double[2][allPeaks.size()];

    for (int k = 0; k < allPeaks.size(); ++k) {
        peaks[0][k] = measured.getMzAt(allPeaks.get(k));
        peaks[1][k] = reference.getMzAt(allPeaks.get(k));
    }
    return peaks;
}

From source file:org.jolab.springrest.web.MyRestController.java

@RequestMapping("/person")
public User getPersonDetail() {
    User user = userService.getUserById(Integer.SIZE);
    return user;
}

From source file:com.bah.culvert.util.Bytes.java

/**
 * Conver the byte [] to an int// w ww .ja va2s.c o m
 * @param b
 * @return
 */
public static int toInt(byte[] b) {
    if (b.length != Integer.SIZE / 8) {
        throw new IllegalArgumentException("byte array wrong size for Integer conversion");
    }
    int n = 0;
    for (int i = 0; i < b.length; i++) {
        n <<= 8;
        n ^= b[i] & 0xFF;
    }
    return n;
}

From source file:com.addthis.hydra.data.query.op.MergedRowFactory.java

@Override
public DiskBackedMap.DiskObject fromBytes(byte[] bytes) {
    MergedRow mergedRow = new MergedRow(conf, new ListBundle(format));
    mergedRow.numMergedRows = LessBytes.toInt(ArrayUtils.subarray(bytes, 0, Integer.SIZE / 8));
    ListBundleFormat format = new ListBundleFormat();
    ListBundle listBundle = new ListBundle(format);
    try {//  ww w.  ja va 2 s  .  c  om
        DataChannelCodec.decodeBundle(listBundle, ArrayUtils.subarray(bytes, Integer.SIZE / 8, bytes.length));
        int i = 0;
        for (MergedValue map : conf) {
            ValueObject value = listBundle.getValue(format.getField("" + i));
            i += 1;
            mergedRow.setValue(map.getTo(), value);
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return mergedRow;
}