ome.util.mem
Class ReadOnlyByteArray

java.lang.Object
  extended by ome.util.mem.ReadOnlyByteArray
Direct Known Subclasses:
ByteArray

public class ReadOnlyByteArray
extends Object

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.

Since:
OME2.2
Version:
2.2 (Internal version: $Revision: 1167 $ $Date: 2005/06/09 15:01:57 $)
Author:
Jean-Marie Burel      j.burel@dundee.ac.uk,
Andrea Falconi      a.falconi@dundee.ac.uk

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

base

protected final byte[] base
The original array.


offset

protected final int offset
Marks the start of the slice.


length

public final int length
The length of the slice.

Constructor Detail

ReadOnlyByteArray

public ReadOnlyByteArray(byte[] base,
                         int offset,
                         int length)
Creates a read-only slice of 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].

Parameters:
base - The original array.
offset - The start of the slice.
length - The length of the slice.
Method Detail

checkIndex

protected void checkIndex(int i)
Makes sure that i is in [0, length). Throws an exception if this constraint is not met.

Parameters:
i - The index to verify.

get

public byte get(int index)
Reads the element at the index position within this slice.

Parameters:
index - The index. Must be in the [0, length) interval.
Returns:
The element at the index position in this slice.


OmeroJava Api

Version: Beta-4.1.1-r5927-b91

Copyright © 2009 The University of Dundee. All Rights Reserved.