org.foray.common
Class ByteVector

java.lang.Object
  extended by org.foray.common.ByteVector
All Implemented Interfaces:
Serializable

public class ByteVector
extends Object
implements Serializable

A vector of bytes.

See Also:
Serialized Form

Constructor Summary
ByteVector()
          No-argument constructor.
ByteVector(int capacity)
          Constructor.
 
Method Summary
 void add(byte value)
          Adds one element to the vector.
 int alloc(int size)
          Allocates or uses a specified number of elements (bytes).
 int capacity()
          Returns the current capacity of the vector.
 byte get(int index)
          Retrieve a value from a specific index in the vector.
 int length()
          Returns the number of items in the vector.
 void set(int index, byte val)
          Place an item in the vector at a specific index.
 void trimToSize()
          Sets the capacity of this vector equal to its size, to that there is no unused capacity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteVector

public ByteVector()
No-argument constructor.


ByteVector

public ByteVector(int capacity)
Constructor.

Parameters:
capacity - The initial capacity, in bytes, of the new vector.
Method Detail

length

public int length()
Returns the number of items in the vector.

Returns:
The number of items in the vector.

capacity

public int capacity()
Returns the current capacity of the vector.

Returns:
The currect capacity of the vector.

add

public void add(byte value)
Adds one element to the vector.

Parameters:
value - The byte value to be added to the vector.

set

public void set(int index,
                byte val)
Place an item in the vector at a specific index.

Parameters:
index - The 0-based index into the vector.
val - The byte value to be placed in the vector.

get

public byte get(int index)
Retrieve a value from a specific index in the vector.

Parameters:
index - The 0-based index whose value should be returned.
Returns:
The value at index.

alloc

public int alloc(int size)
Allocates or uses a specified number of elements (bytes). If needed, this method automatically increases the vector's capacity.

Parameters:
size - The number of elements (bytes) to be allocated.
Returns:
The index to the beginning of the allocated elements (bytes).

trimToSize

public void trimToSize()
Sets the capacity of this vector equal to its size, to that there is no unused capacity.



Copyright © 2017. All rights reserved.