danger.app
Class DataRecord

java.lang.Object
  extended by danger.app.DataRecord


public class DataRecord
extends Object

The DataRecord provides a high-level interfaces to a record consisting of some number of rows, each of which may contain a variable number of columns of 'short', 'int', or 'string' data types.

  TODO:
  - deleting some or all of the columns in a row
  - throw more meaningful exceptions than ArrayIndexOutOfBounds
  - a SanityCheck() method to provide the ability to judge if
    a records data is intact.  An intact record will never cause
    an exception to be thrown when reading from existing rows 
    and columns
  - fast searching tools
  - string extractor tools
 
  LIMITATIONS:
  - a row may only contain items of one type.
  - a record may not be larger than 32K
  - writing is inefficient, write numeric columns from right to left
    for best performance

  IMPLEMENTATION:
  - Each record contains a directory, 1 short per row, containing 
    offsets from the start of the record to the start of that row
  - There is one short, value 0, immediately after this directory 
    to serve as a terminator for the directory AND the place where 
    all empty rows are pointed at
  - each row starts with a short countaining the number of columns
    in that row
  - 'int' and 'short' rows will contain 4*count and 2*count bytes of
    data respectively
  - 'string' rows will contain one short bytecount followed by that
    number of bytes of UTF-8 character data
  - all numbers are little-endian

  (row0_offset:2) ------.
  (row1_offset:2) --.   |
  (row2_offset:2) --|-. |
  (zero:2)        <-' | |
  (row2_cols:2)   <---' |
  ...                   |
  ...                   |
  (row0_cols:2)   <-----'
  ...
  ...
  ...
  


Field Summary
static int FIND_FLAG_IGNORE_CASE
           
static int FIND_MASK_MODE
           
static int FIND_MODE_ALL_RECORDS
           
static int FIND_MODE_CONTAINS
           
static int FIND_MODE_EXACT
           
static int FIND_MODE_STARTS_WITH
           
 byte[] mData
           
 int mRows
           
 
Constructor Summary
DataRecord(byte[] data, int rows)
          Create a new record backed against a provided byte array and specified number of rows
DataRecord(int rows)
          Create a new record with the specified number of rows, all of which will be empty initially.
 
Method Summary
 void clearRowInt(int row)
          Set the number of columns in the specified row to zero.
 void clearRowShort(int row)
          Set the number of columns in the specified row to zero.
 void clearRowString(int row)
          Set the number of columns in the specified row to zero.
 int collate(DangerCollator dc, int row, int col, DataRecord other, int other_row, int other_col)
           
 int collate(DangerCollator dc, int row, int col, int skip, DataRecord other, int other_row, int other_col, int other_skip)
           
 int collate(DangerCollator dc, int row, int col, String other)
           
 int countColumns(int row)
          Return the number of columns in the specified row
 int countRows()
          Return the number of rows in this record
 void drawString(int row, int col, Pen p, int x, int y)
          Draws a string with the specified pen, at the specified xy location, without allocating a String object.
 void dump(String template)
          Dump the contents of this record to System.err, based on the description in the template string (one char per row, 'i'==Integer, 's'==Short, '*'==String
 boolean findString(DangerCollator dc, DataFinder df, byte[] key, int row, int col, int mode)
           
 boolean findString(DataFinder df, byte[] key, int row, int col, int mode)
           
 boolean findStringContains(DataFinder df, byte[] key, int row, int col)
           
 boolean findStringContainsIgnoreCase(DataFinder df, byte[] keyUpperCase, int row, int col)
           
 boolean findStringExactMatch(DataFinder df, byte[] key, int row, int col)
           
 boolean findStringExactMatchIgnoreCase(DataFinder df, byte[] keyUpperCase, int row, int col)
           
 boolean findStringStartsWith(DataFinder df, byte[] key, int row, int col)
           
 boolean findStringStartsWithIgnoreCase(DataFinder df, byte[] keyUpperCase, int row, int col)
           
 byte[] getByteArray(int row, int col)
          Read a byte[] from a specified row and column.
 int getInt(int row, int col)
          Read an Integer from a specified row and column.
 String getInternString(int row, int col)
          Read a String from a specified row and column and intern it.
 int getShort(int row, int col)
          Read a Short from a specified row and column.
 String getString(int row, int col)
          Read a String from a specified row and column.
 int getStringLength(int row, int col)
           
 int getStringOffset(int row, int col)
           
 void init(int rows)
          Recreate a record with the specified number of rows, all of which will be empty initially.
 void putByteArray(int row, int col, byte[] value)
          Write an byte[] to a specified row and column.
 void putInt(int row, int col, int value)
          Write an Integer to a specified row and column.
 void putShort(int row, int col, int value)
          Write an Short to a specified row and column.
 void putString(int row, int col, String value)
          Write an String to a specified row and column.
 boolean startsWith(DangerCollator dc, int row, int col, String other)
           
 int stringCompareIgnoreCase(int row, int col, DataRecord other, int other_row, int other_col)
           
 int stringCompareIgnoreCase(int row, int col, DataRecord other, int other_row, int other_col, byte[][] ignoredPrefixes, boolean ignoreTrailingWhitespace)
           
 int stringCompareIgnoreCase(int row, int col, int skip, DataRecord other, int other_row, int other_col, int other_skip)
           
 int stringCompareIgnoreCase(int row, int col, String other)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIND_MODE_EXACT

public static final int FIND_MODE_EXACT
See Also:
Constant Field Values

FIND_MODE_CONTAINS

public static final int FIND_MODE_CONTAINS
See Also:
Constant Field Values

FIND_MODE_STARTS_WITH

public static final int FIND_MODE_STARTS_WITH
See Also:
Constant Field Values

FIND_MODE_ALL_RECORDS

public static final int FIND_MODE_ALL_RECORDS
See Also:
Constant Field Values

FIND_MASK_MODE

public static final int FIND_MASK_MODE
See Also:
Constant Field Values

FIND_FLAG_IGNORE_CASE

public static final int FIND_FLAG_IGNORE_CASE
See Also:
Constant Field Values

mData

public byte[] mData

mRows

public int mRows
Constructor Detail

DataRecord

public DataRecord(int rows)
Create a new record with the specified number of rows, all of which will be empty initially.


DataRecord

public DataRecord(byte[] data,
                  int rows)
Create a new record backed against a provided byte array and specified number of rows

Method Detail

init

public void init(int rows)
Recreate a record with the specified number of rows, all of which will be empty initially.


countRows

public int countRows()
Return the number of rows in this record


countColumns

public int countColumns(int row)
Return the number of columns in the specified row


clearRowInt

public void clearRowInt(int row)
Set the number of columns in the specified row to zero.


clearRowShort

public void clearRowShort(int row)
Set the number of columns in the specified row to zero.


clearRowString

public void clearRowString(int row)
Set the number of columns in the specified row to zero.


getInt

public int getInt(int row,
                  int col)
Read an Integer from a specified row and column.


getShort

public int getShort(int row,
                    int col)
Read a Short from a specified row and column.


getString

public String getString(int row,
                        int col)
Read a String from a specified row and column.


getInternString

public String getInternString(int row,
                              int col)
Read a String from a specified row and column and intern it.


getByteArray

public byte[] getByteArray(int row,
                           int col)
Read a byte[] from a specified row and column.


findString

public boolean findString(DataFinder df,
                          byte[] key,
                          int row,
                          int col,
                          int mode)

findString

public boolean findString(DangerCollator dc,
                          DataFinder df,
                          byte[] key,
                          int row,
                          int col,
                          int mode)

findStringContains

public boolean findStringContains(DataFinder df,
                                  byte[] key,
                                  int row,
                                  int col)

findStringContainsIgnoreCase

public boolean findStringContainsIgnoreCase(DataFinder df,
                                            byte[] keyUpperCase,
                                            int row,
                                            int col)

findStringStartsWith

public boolean findStringStartsWith(DataFinder df,
                                    byte[] key,
                                    int row,
                                    int col)

findStringStartsWithIgnoreCase

public boolean findStringStartsWithIgnoreCase(DataFinder df,
                                              byte[] keyUpperCase,
                                              int row,
                                              int col)

findStringExactMatch

public boolean findStringExactMatch(DataFinder df,
                                    byte[] key,
                                    int row,
                                    int col)

findStringExactMatchIgnoreCase

public boolean findStringExactMatchIgnoreCase(DataFinder df,
                                              byte[] keyUpperCase,
                                              int row,
                                              int col)

drawString

public void drawString(int row,
                       int col,
                       Pen p,
                       int x,
                       int y)
Draws a string with the specified pen, at the specified xy location, without allocating a String object.


putInt

public void putInt(int row,
                   int col,
                   int value)
Write an Integer to a specified row and column. If the column has not been previously written, any missing columns between the rightmost column and the specified column will be set to 0


putShort

public void putShort(int row,
                     int col,
                     int value)
Write an Short to a specified row and column. If the column has not been previously written, any missing columns between the rightmost column and the specified column will be set to 0


putString

public void putString(int row,
                      int col,
                      String value)
Write an String to a specified row and column. If the column has not been previously written, any missing columns between the rightmost column and the specified column will be set to null


putByteArray

public void putByteArray(int row,
                         int col,
                         byte[] value)
Write an byte[] to a specified row and column. If the column has not been previously written, any missing columns between the rightmost column and the specified column will be set to null


dump

public void dump(String template)
Dump the contents of this record to System.err, based on the description in the template string (one char per row, 'i'==Integer, 's'==Short, '*'==String


getStringOffset

public int getStringOffset(int row,
                           int col)

stringCompareIgnoreCase

public int stringCompareIgnoreCase(int row,
                                   int col,
                                   DataRecord other,
                                   int other_row,
                                   int other_col)

collate

public int collate(DangerCollator dc,
                   int row,
                   int col,
                   DataRecord other,
                   int other_row,
                   int other_col)

stringCompareIgnoreCase

public int stringCompareIgnoreCase(int row,
                                   int col,
                                   int skip,
                                   DataRecord other,
                                   int other_row,
                                   int other_col,
                                   int other_skip)

collate

public int collate(DangerCollator dc,
                   int row,
                   int col,
                   int skip,
                   DataRecord other,
                   int other_row,
                   int other_col,
                   int other_skip)

stringCompareIgnoreCase

public int stringCompareIgnoreCase(int row,
                                   int col,
                                   DataRecord other,
                                   int other_row,
                                   int other_col,
                                   byte[][] ignoredPrefixes,
                                   boolean ignoreTrailingWhitespace)

stringCompareIgnoreCase

public int stringCompareIgnoreCase(int row,
                                   int col,
                                   String other)

collate

public int collate(DangerCollator dc,
                   int row,
                   int col,
                   String other)

startsWith

public boolean startsWith(DangerCollator dc,
                          int row,
                          int col,
                          String other)

getStringLength

public int getStringLength(int row,
                           int col)