inonit.domain.game.card.hearts.ai
Class Storage

java.lang.Object
  |
  +--inonit.domain.game.card.hearts.ai.Storage

public class Storage
extends java.lang.Object

An object which can be used by an AbstractIntelligence for persistent storage of data. Storage extends the operations provided by the Intelligence.Environment.Storage interface to provide random access and methods for reading and writing arbitrary data types.

At any given time, a Storage has a cursor position. Bytes will be read starting from the cursor position and written starting at the cursor position. The cursor position can be obtained via the getPosition method and changed using the moveTo method.


Method Summary
 int getCapacity()
          Returns the number of bytes this Storage can hold.
 int getPosition()
          Returns the current position of the cursor.
 void moveTo(int position)
          Causes the cursor to move to the given position.
 byte[] read(int length)
          Returns a series of bytes starting at the cursor position.
 boolean readBoolean()
          Reads a boolean starting at the cursor position.
 byte readByte()
          Reads a byte starting at the cursor position.
 char readChar()
          Reads a char starting at the cursor position.
 double readDouble()
          Reads a double starting at the cursor position.
 float readFloat()
          Reads a float starting at the cursor position.
 int readInt()
          Reads an int starting at the cursor position.
 long readLong()
          Reads a long starting at the cursor position.
 short readShort()
          Reads a short starting at the cursor position.
 java.lang.String readString()
          Reads a String starting at the cursor position.
 void write(byte[] bytes)
          Writes a series of bytes to this Storage, starting at the cursor position.
 void writeBoolean(boolean b)
          Writes the given boolean starting at the cursor position.
 void writeByte(byte b)
          Writes the given byte starting at the cursor position.
 void writeChar(char c)
          Writes the given char starting at the cursor position.
 void writeDouble(double d)
          Writes the given double starting at the cursor position.
 void writeFloat(float f)
          Writes the given float starting at the cursor position.
 void writeInt(int i)
          Writes the given int starting at the cursor position.
 void writeLong(long l)
          Writes the given long starting at the cursor position.
 void writeShort(short s)
          Writes the given short starting at the cursor position.
 void writeString(java.lang.String s)
          Writes the given String starting at the cursor position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getCapacity

public int getCapacity()
Returns the number of bytes this Storage can hold.
Returns:
The capacity of this Storage, in bytes.

moveTo

public void moveTo(int position)
Causes the cursor to move to the given position.
Parameters:
position - The index within this Storage to which the cursor should be moved.

getPosition

public int getPosition()
Returns the current position of the cursor.
Returns:
The position of the cursor, measured in bytes from the beginning of the Storage.

read

public byte[] read(int length)
            throws java.io.IOException
Returns a series of bytes starting at the cursor position.
Parameters:
length - The number of bytes to read.
Returns:
An array of bytes of length length containing the bytes read.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

write

public void write(byte[] bytes)
           throws java.io.IOException
Writes a series of bytes to this Storage, starting at the cursor position.
Parameters:
bytes - The bytes to write to this Storage.
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

readByte

public byte readByte()
              throws java.io.IOException
Reads a byte starting at the cursor position.
Returns:
The byte at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readShort

public short readShort()
                throws java.io.IOException
Reads a short starting at the cursor position.
Returns:
The short at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readInt

public int readInt()
            throws java.io.IOException
Reads an int starting at the cursor position.
Returns:
The int at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readLong

public long readLong()
              throws java.io.IOException
Reads a long starting at the cursor position.
Returns:
The long at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readFloat

public float readFloat()
                throws java.io.IOException
Reads a float starting at the cursor position.
Returns:
The float at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readDouble

public double readDouble()
                  throws java.io.IOException
Reads a double starting at the cursor position.
Returns:
The double at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readBoolean

public boolean readBoolean()
                    throws java.io.IOException
Reads a boolean starting at the cursor position.
Returns:
The boolean at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readChar

public char readChar()
              throws java.io.IOException
Reads a char starting at the cursor position.
Returns:
The char at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

readString

public java.lang.String readString()
                            throws java.io.IOException
Reads a String starting at the cursor position.
Returns:
The String at the cursor position.
Throws:
java.io.IOException - If an input error occurs while reading from this Storage.

writeByte

public void writeByte(byte b)
               throws java.io.IOException
Writes the given byte starting at the cursor position.
Parameters:
b - The byte to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeShort

public void writeShort(short s)
                throws java.io.IOException
Writes the given short starting at the cursor position.
Parameters:
s - The short to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeInt

public void writeInt(int i)
              throws java.io.IOException
Writes the given int starting at the cursor position.
Parameters:
i - The int to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeLong

public void writeLong(long l)
               throws java.io.IOException
Writes the given long starting at the cursor position.
Parameters:
l - The long to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeFloat

public void writeFloat(float f)
                throws java.io.IOException
Writes the given float starting at the cursor position.
Parameters:
f - The float to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeDouble

public void writeDouble(double d)
                 throws java.io.IOException
Writes the given double starting at the cursor position.
Parameters:
d - The double to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeBoolean

public void writeBoolean(boolean b)
                  throws java.io.IOException
Writes the given boolean starting at the cursor position.
Parameters:
b - The boolean to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeChar

public void writeChar(char c)
               throws java.io.IOException
Writes the given char starting at the cursor position.
Parameters:
c - The char to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.

writeString

public void writeString(java.lang.String s)
                 throws java.io.IOException
Writes the given String starting at the cursor position.
Parameters:
s - The String to write
Throws:
java.io.IOException - If an output error occurs while writing to this Storage.