1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
public interface BitArray
{
public byte get(int index);
public byte set(int index, byte b);
public BitArray range(int start, int length);
public int length();
}
public class BitArrayImpl
{
private byte[] bytes;
public BitArrayImpl(final byte[] bs)
{
bytes = bs;
}
public byte get(int index)
{
return bytes[index];
}
public byte set(index index, byte b)
{
byte old = bytes[index];
bytes[index] = b;
return old;
}
public int length()
{
return bytes.length;
}
public BitArray range(int start, int length)
{
return new BitArrayRange(this, start, length);
}
}
public class BitArrayRange
{
private BitArray underlying;
private int start;
private int length;
public BitArrayRange(BitArray array, int from, int count)
{
underlying = array;
start = from;
length = count;
}
public byte get(int index)
{
if (index >= length) throw new ArrayOutOfBoundsException();
return underlying.get(start + index);
}
public byte set(index index, byte b)
{
if (index >= length) throw new ArrayOutOfBoundsException();
return underlying.set(start + index, b);
}
public int length()
{
return length;
}
public BitArray range(int start, int length)
{
return new BitArrayRange(this, start, length);
}
} |
Partager