danger.app
Class DataRecord

java.lang.Object
  |
  +--danger.app.DataRecord

public class DataRecord
extends java.lang.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 kFindFlagIgnoreCase
           
static int kFindMaskMode
           
static int kFindModeAllRecords
           
static int kFindModeContains
           
static int kFindModeExact
           
static int kFindModeStartsWith
           
 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 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(java.lang.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(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.
 int getShort(int row, int col)
          Read a Short from a specified row and column.
 java.lang.String getString(int row, int col)
          Read a String from a specified row and column.
 int getStringLength(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, java.lang.String value)
          Write an String to a specified row and column.
 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, java.lang.String other)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kFindModeExact

public static final int kFindModeExact

kFindModeContains

public static final int kFindModeContains

kFindModeStartsWith

public static final int kFindModeStartsWith

kFindModeAllRecords

public static final int kFindModeAllRecords

kFindMaskMode

public static final int kFindMaskMode

kFindFlagIgnoreCase

public static final int kFindFlagIgnoreCase

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 java.lang.String getString(int row,
                                  int col)
Read a String from a specified row and column.

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)

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,
                      java.lang.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(java.lang.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

stringCompareIgnoreCase

public int stringCompareIgnoreCase(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)

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,
                                   java.lang.String other)

getStringLength

public int getStringLength(int row,
                           int col)


Danger Confidential. Copyright © 2000-2003, Danger Inc.