com.github.andyshao.lang.ByteWrapper 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;
import java.util.Iterator;
/**
* Wrap any kinds of object or array. Operate them as a byte array.
* Title:
* Descript:
* Copyright: Copryright(c) Apr 2, 2015
* Encoding:UNIX UTF-8
*
* @author Andy.Shao
*
* @param the array type
*/
public interface ByteWrapper {
/**Byte byte wrapper*/
public static final ByteWrapper BYTE_BYTE_WRAPPER = new ByteByteWrapper();
/**Char byte wrapper*/
public static final ByteWrapper CHAR_BYTE_WRAPPER = new CharByteWrapper();
/**int byte wrapper*/
public static final ByteWrapper INT_BYTE_WRAPPER = new IntByteWrapper();
/**long byte wrapper*/
public static final ByteWrapper LONG_BYTE_WRAPPER = new LongByteWrapper();
/**short byte wrapper*/
public static final ByteWrapper SHORT_BYTE_WRAPPER = new ShortByteWrapper();
/**
* get byte
* @param array the array
* @param index the position
* @return the answer
*/
public byte getByte(final ARRAY array , BigInteger index);
/**
* get {@link Iterator}
* @param array the array
* @return {@link Iterator}
*/
public default Iterator iterator(final ARRAY array) {
return new Iterator() {
private volatile BigInteger index = BigInteger.ZERO;
private final BigInteger size = ByteWrapper.this.size(array);
@Override
public boolean hasNext() {
return this.index.compareTo(this.size) == -1;
}
@Override
public Byte next() {
Byte result = ByteWrapper.this.getByte(array , this.index);
this.index = this.index.add(BigInteger.ONE);
return result;
}
};
}
/**
* set byte
* @param array the array
* @param index the position
* @param b the byte
*/
public void setByte(final ARRAY array , BigInteger index , byte b);
/**
* the size of the array
* @param array array
* @return the size
*/
public BigInteger size(final ARRAY array);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy