|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.fdsapi.arrays.ArrayFilter
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. The addDisplayCol(...) methods in the ArrayFilter class are analagous. In the SQL select statement you can also limit/filter rows by using where conditions. For example: select col1,col1,col2,col5 from table where col1='A' and (col2<=100 or col5 like 'john%'). The ArrayFilter has methods that can build up such conditionals. The addConditional(...) methods build each individual conditional (i.e. col1='A'), addAnd()/addOr() methods are called in between calls to addConditional() to string them together, and parenthesis are controlled with addLeftParen(), and addRightParen() (opening/left and closing/right parens respectively).
The original ArrayFilter class was designed by Ed Desrosiers. Steve Souza refactored this class, and added design patterns (Primarily the gang of 4's Composite and Decorator patterns.)
To see sample code click on view code below. The classes main method has plenty of examples.
Authors: Steve Souza and Ed Desrosiers
| Constructor Summary | |
ArrayFilter()
Creates a new instance of ArrayFilter |
|
ArrayFilter(ArrayConverter arrayConverter)
Creates a new instance of ArrayFilter |
|
ArrayFilter(java.lang.String[] header)
Creates a new instance filter and allows the columns to be referenced by the label in both display columns and where clauses. |
|
ArrayFilter(java.lang.String[] header,
ArrayConverter arrayConverter)
|
|
| Method Summary | |
void |
addAnd()
Used to indicate that two conditionals are true only if both of them are true. |
void |
addConditional(Conditional conditional)
This method can be used if you create your own Condtional and would like it to be called to see if the row should be retained. |
void |
addConditional(int col,
java.lang.String type,
java.lang.Object comparisonValue)
Add a Conditional to be called against a given column. |
void |
addConditional(java.lang.String colName,
java.lang.String type,
java.lang.Object comparisonValue)
Add a conditional against the named column. |
void |
addDisplayCol(int columnNumber)
Select a column number to be displayed. |
void |
addDisplayCol(java.lang.String columnName)
Display the named column. |
void |
addDisplayFunction(java.lang.String functionName)
|
void |
addLeftParen()
Group logicals together with parens. |
void |
addNot()
Negate the current paren level/composite. |
void |
addOr()
Used to indicate that two conditionals are true if one or both of them are true. |
void |
addRightParen()
Group logicals together with parens. |
java.lang.Object[][] |
convert(java.lang.Object[][] data)
This method executes the query against the data and converts the data with the ArrayConverter. |
java.lang.Object[][] |
filter(java.lang.Object[][] fullArray)
Return the array filtered on both rows and columns. |
ArrayConverter |
getArrayConverter()
Get the underlying ArrayConverter that backs the ArrayFilter object |
int |
getColNumFromName(java.lang.String columnName)
Returns the column number when passed a column name that matches the header array passed into the Constructor |
static void |
main(java.lang.String[] args)
Test and Sample code for the ArrayFilter. |
void |
setArrayConverter(ArrayConverter arrayConverter)
Set the underlying ArrayConverter that backs the ArrayFilter object |
java.lang.String |
toString()
Create a string representation of the ArrayFilter object. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public ArrayFilter()
public ArrayFilter(ArrayConverter arrayConverter)
public ArrayFilter(java.lang.String[] header)
Creates a new instance filter and allows the columns to be referenced by the label in both display columns and where clauses. Arrays don't have the concept of named columns and this array gives them this capability. For example in the following example after calling this constructor col0 can be referred to as fname, and col1 can be referred to as lname. The names are not case sensitive
Sample Call:
String[] header={"fname","lname"};
ArrayFilter f=new ArrayFilter(header);
f.addDisplayCol("fname");
f.addDisplayCol("lname");
f.addConditional("LNAme","=","souza");
Object[][] data=f.filter(names);
public ArrayFilter(java.lang.String[] header,
ArrayConverter arrayConverter)
| Method Detail |
public java.lang.Object[][] filter(java.lang.Object[][] fullArray)
Return the array filtered on both rows and columns. The effect of this method and the ArrayFilter in general is to return a subset of an array much like a select statement does for a database table. For example if a table has 4 columns and 100 rows, then a select statement may only bring back 3 of the columns and half of the rows based on conditions in the where clause. Note the array passed in is unchanged and a the method returns the filtered array. Note also if a null array is passed in it will be returned and no error will occur. If there are no matches on the array it will return an empty array (i.e. it will be a valid array with no rows or columns).
For examples of using this method click the view code href above
public java.lang.Object[][] convert(java.lang.Object[][] data)
This method executes the query against the data and converts the data with the ArrayConverter. This method first calls execute(...).:
Sample Code:
ArrayFilter filter=new ArrayFilter();
filter.addDisplayCol(5);
filter.convert(data);
public ArrayConverter getArrayConverter()
public void setArrayConverter(ArrayConverter arrayConverter)
public void addConditional(int col,
java.lang.String type,
java.lang.Object comparisonValue)
Add a Conditional to be called against a given column. Note ==, and = can take Objects as the comparisonValue, but any of the <,<=,>,>= must take a Comparator as an argument. Another option is to use the alternative signature that adds a Conditional directly.
Arguments: 1) int col - must be >=0 and it represents the index of the array that you would like to have the conditional act against. 2) String type - is the type of Conditional. Currently valid values are: =,==,<,<= >,>=,<>,!=,like,not like,in,not in which work as you would expect. See the ConditionalFactory for further info. 3) Object comparisonValue - is the value that will be compared against the array column.
The Conditional will be added at the current paren level
public void addConditional(java.lang.String colName,
java.lang.String type,
java.lang.Object comparisonValue)
Add a conditional against the named column. This column must match one that was passed in with the contructor that takes a String[] header. If not a RuntimeException will be thrown. The Conditional will be added at the current paren level.
public void addConditional(Conditional conditional)
This method can be used if you create your own Condtional and would like it to be called to see if the row should be retained. The Conditional will be added at the current paren level.
public void addNot()
public void addAnd()
public void addOr()
public void addLeftParen()
public void addRightParen()
public void addDisplayCol(int columnNumber)
public void addDisplayCol(java.lang.String columnName)
public void addDisplayFunction(java.lang.String functionName)
public int getColNumFromName(java.lang.String columnName)
public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||