com.fdsapi.arrays
Class ArraySQL

java.lang.Object
  |
  +--com.fdsapi.arrays.ArraySQL

public class ArraySQL
extends java.lang.Object

This class does for arrays what a SQL select statement for a database table. For example in a select statement you can display or not display columns by including them in the select column list. Example: select col1,col1,col2,col5 from array. In the SQL select statement you can also limit/filter rows by using where conditions. For example: select col1,col1,col2,col5 from array where col1='A' && (col2<=100 || col5 in ('jim',john')). Ordering is also possible as it is with a SQL select: select * from array where fname='steve' order by lname desc, salary asc

ArraySQL is backed by the ArrayFilter and ArrayComparator objects

To see sample code click on view code below. The classes main method has plenty of examples. Note where clauses must be of the format where col0='souza' as opposed to 'souza'=col0 (i.e. the column must come first)

Notes: Exceptions: 1) no query 2) colname that isn't in header 3) not asc or desc. Also note string checks for equality are case sensitive. like is not case senstive.



View Code


Constructor Summary
ArraySQL(java.lang.String query)
          Creates a new instance of ArraySQL
ArraySQL(java.lang.String[] header, java.lang.String query)
           
 
Method Summary
 java.lang.Object[][] convert(java.lang.Object[][] data)
          This method executes the query against the data and convers the data with the ArrayConverter.
static java.lang.Object[][] copy(java.lang.Object[][] data)
          Performs a shallow copy of the passed in array
 java.lang.String debugString()
          Get a debug String.
 java.lang.Object[][] execute(java.lang.Object[][] data)
          This method executes the query against the data.
 ArrayComparator getArrayComparator()
          Get the underlying ArrayComparator that backs the ArraySQL object.
 ArrayConverter getArrayConverter()
          Get the underlying ArrayConverter that backs the ArraySQL object
 ArrayFilter getArrayFilter()
          Get the underlying ArrayFilter that backs the ArraySQL object.
 boolean getCopyData()
          Get the copy status for any array that will be passed to the execute(...) method.
static void main(java.lang.String[] args)
          Test code for the ArraySQL class.
 void setArrayConverter(ArrayConverter arrayConverter)
           
 void setCopyData(boolean copyData)
          Copy the array passed to the execute(...) method.
 java.lang.String toString()
          The passed in query
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ArraySQL

public ArraySQL(java.lang.String query)
Creates a new instance of ArraySQL


ArraySQL

public ArraySQL(java.lang.String[] header,
                java.lang.String query)
Method Detail

copy

public static java.lang.Object[][] copy(java.lang.Object[][] data)
Performs a shallow copy of the passed in array


execute

public java.lang.Object[][] execute(java.lang.Object[][] data)

This method executes the query against the data. A side effect is that the original data is sorted. If you wish not to sort the original data then you should call setCopyData(false). Note execute can be called as many times as needed against the same or different arrays. :

Sample Code:

 ArraySQL asql=new ArraySQL("select * from array");
 asql.setCopyData(false);
 asql.execute(ArraySQL.copy(data));
 


convert

public java.lang.Object[][] convert(java.lang.Object[][] data)

This method executes the query against the data and convers the data with the ArrayConverter. This method first calls execute(...).:

Sample Code:

 ArraySQL asql=new ArraySQL("select * from array");
 asql.convert(data); 
 


toString

public java.lang.String toString()
The passed in query

Overrides:
toString in class java.lang.Object

getArrayFilter

public ArrayFilter getArrayFilter()
Get the underlying ArrayFilter that backs the ArraySQL object.


getArrayComparator

public ArrayComparator getArrayComparator()
Get the underlying ArrayComparator that backs the ArraySQL object.


getArrayConverter

public ArrayConverter getArrayConverter()
Get the underlying ArrayConverter that backs the ArraySQL object


setArrayConverter

public void setArrayConverter(ArrayConverter arrayConverter)

debugString

public java.lang.String debugString()
Get a debug String. This debug string gets its information from the backing ArrayComparator and ArrayFilter. This method should return a select statement that does the same thing as the original query passed to the constructor even if it looks slightly different.


setCopyData

public void setCopyData(boolean copyData)
Copy the array passed to the execute(...) method. This is done so the original array is not sorted. By default the original array is sorted.


getCopyData

public boolean getCopyData()
Get the copy status for any array that will be passed to the execute(...) method.


main

public static void main(java.lang.String[] args)
Test code for the ArraySQL class. This is also good to look to learn some of ArraySQL's capabilities. Use the view code button at the top of this file to view the code.