com.github.andyshao.lang.IntByteWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Gear Show documentation
Show all versions of Gear Show documentation
Enhance and formating the coding of JDK
The newest version!
package com.github.andyshao.lang;
import java.math.BigInteger;
/**
*
* Title:
* Descript:
* Copyright: Copryright(c) Apr 2, 2015
* Encoding:UNIX UTF-8
*
* @author Andy.Shao
*
*/
public class IntByteWrapper implements ByteWrapper {
private static final BigInteger BASE = BigInteger.valueOf(4);
@Override
public byte getByte(int[] array , BigInteger index) {
BigInteger[] indexs = index.divideAndRemainder(IntByteWrapper.BASE);
if (indexs[1].intValue() < 0) throw new ArrayIndexOutOfBoundsException(index.toString());
return IntegerOperation.getByte(array[indexs[0].intValue()] , indexs[1].intValue());
}
@Override
public void setByte(int[] array , BigInteger index , byte b) {
BigInteger[] indexs = index.divideAndRemainder(IntByteWrapper.BASE);
if (indexs[1].intValue() < 0) throw new ArrayIndexOutOfBoundsException(index.toString());
array[indexs[0].intValue()] = IntegerOperation.setByte(array[indexs[0].intValue()] , indexs[1].intValue() , b);
}
@Override
public BigInteger size(int[] array) {
return BigInteger.valueOf(array.length).multiply(IntByteWrapper.BASE);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy