|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectome.util.mem.ReadOnlyByteArray
public class ReadOnlyByteArray
A read-only slice of a given array. Given a base
array and an
interval [offset, offset+length]
contained within
[0, base.length]
, an instance of this class provides read
access to the elements from base[offset]
to
base[offset+length-1]
. However, you access the elements by
specifying relative indeces to the get
method so
get(0)
returns base[offset]
,
get(1)
returns base[offset+1]
, and so on. One
thing to bear in mind is that changes to the original base
array will be reflected to the corresponding ReadOnlyByteArray
object as this class simply keeps a reference to the original
base
array, without making an internal copy. This can be
useful in those situations when you want to emulate a memory pointer.
Field Summary | |
---|---|
protected byte[] |
base
The original array. |
int |
length
The length of the slice. |
protected int |
offset
Marks the start of the slice. |
Constructor Summary | |
---|---|
ReadOnlyByteArray(byte[] base,
int offset,
int length)
Creates a read-only slice of base . |
Method Summary | |
---|---|
protected void |
checkIndex(int i)
Makes sure that i is in [0, length) . |
byte |
get(int index)
Reads the element at the index position within this slice. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final byte[] base
protected final int offset
public final int length
Constructor Detail |
---|
public ReadOnlyByteArray(byte[] base, int offset, int length)
base
. The
offset
argument marks the start of the slice, at
base[offset]
. The length
argument defines
the length of the slice, the last element being
base[offset+length-1]
. Obviously enough, these two
arguments must define an interval [offset, offset+length]
in [0, base.length]
.
base
- The original array.offset
- The start of the slice.length
- The length of the slice.Method Detail |
---|
protected void checkIndex(int i)
i
is in [0, length)
.
Throws an exception if this constraint is not met.
i
- The index to verify.public byte get(int index)
index
position within this slice.
index
- The index. Must be in the [0, length
)
interval.
index
position in this slice.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Version: 4.3.4-dbcbce5a-b4
Copyright © 2009 The University of Dundee. All Rights Reserved.