Skip to content

This class allows creation of a grid that can be easily created, modified, and searched.

Notifications You must be signed in to change notification settings

joelcarlton/java-grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation


Create a new grid object


Grid grid = new Grid();

Add some columns and data


grid.add("Address", "921 Thompson St");
grid.add("Phone Number", "865-555-9843");

Create a new blank row


grid.newRow();

Add some more columns and data


grid.add("Address", "923 Thompson St");
grid.add("Phone Number", "918-555-8340");

Write additional data to rows we just wrote


grid.add(0, "First Name", "Michael");
grid.add(1, "First Name", "James");
grid.add(0, "Last Name", "Johnson");
grid.add(1, "Last Name", "Smith");

Explicitly set row before writing new data


grid.setGridRow(0);
grid.add("Misc", "Misc Data");

Move between rows


grid.setGridRowNext();
grid.add("Misc", "Misc Data");
grid.setGridRowPrev();
grid.add("Misc2", "Misc Data");
grid.setGridRowNext();
grid.add("Misc2", "Misc Data");

Print a grid


grid.toString();
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
| Row |         Address | Phone Number | First Name | Last Name |      Misc |     Misc2 |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
|   0 | 921 Thompson St | 865-555-9843 |    Michael |   Johnson | Misc Data | Misc Data |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
|   1 | 923 Thompson St | 865-555-8340 |      James |     Smith | Misc Data | Misc Data |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
2 of 2

Print a list of lists


grid.getListOfLists();
[[Row, Address, Phone Number, First Name, Last Name, Misc, Misc2], [0, 921 Thompson St, 865-555-9843, Michael, Johnson, Misc Data, Misc Data], [1, 923 Thompson St, 865-555-8340, James, Smith, Misc Data, Misc Data]]

Print a list of data for supplied column


grid.getColumnData("Phone Number");
[865-555-9843, 865-555-8340]

Loop through and print out each row


grid.resetIteratorNext();
while(grid.hasIteratorNext())
{
    Map<String, Object> map 	= grid.getIteratorCurrentRow();
    int                 index 	= grid.getIteratorPosition();
    if (!map.isEmpty())
    {
	    System.out.print(index + ": ");
	    System.out.println(map);
    }
    grid.getIteratorNext();
}
0: {Address=921 Thompson St, Phone Number=865-555-9843, First Name=Michael, Last Name=Johnson, Misc=Misc Data, Misc2=Misc Data}
1: {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}

Print out rows that match a full string search


grid.getIteratorSearchFull("Address", "923 Thompson St")
1: {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}

Print out rows that match a full, case insensitive string search


grid.getIteratorSearchFullCaseInsensitive("Address", "923 thompson st");
1: {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}

Print out rows that match a partial string search


grid.getIteratorSearchPartial("Address", "Thom");
0: {Address=921 Thompson St, Phone Number=865-555-9843, First Name=Michael, Last Name=Johnson, Misc=Misc Data, Misc2=Misc Data}
1: {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}

Print out rows that match a partial, case insensitive string search


grid.getIteratorSearchPartialCaseInsensitive("Address", "thom");
0: {Address=921 Thompson St, Phone Number=865-555-9843, First Name=Michael, Last Name=Johnson, Misc=Misc Data, Misc2=Misc Data}
1: {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}

Return a list of rows matching search


List<Map<String, Object>> search1 = grid.getListSearchPartialCaseInsensitive("Address", "thom");
search1.toString();
[{Address=921 Thompson St, Phone Number=865-555-9843, First Name=Michael, Last Name=Johnson, Misc=Misc Data, Misc2=Misc Data}, {Address=923 Thompson St, Phone Number=865-555-8340, First Name=James, Last Name=Smith, Misc=Misc Data, Misc2=Misc Data}]

Return a new grid object of rows matching search


List<Map<String, Object>> search2 = grid.getObjectSearchPartialCaseInsensitive("Address", "thom");
System.out.println(search2.toString());
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
| Row |         Address | Phone Number | First Name | Last Name |      Misc |     Misc2 |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
|   0 | 921 Thompson St | 865-555-9843 |    Michael |   Johnson | Misc Data | Misc Data |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
|   1 | 923 Thompson St | 865-555-8340 |      James |     Smith | Misc Data | Misc Data |
+-----+-----------------+--------------+------------+-----------+-----------+-----------+
2 of 2

Return total amount of rows


grid.getTotalRowCount();
2

Return a map for a row number


grid.getRowByNumber(0);
{Address=921 Thompson St, Phone Number=865-555-9843, First Name=Michael, Last Name=Johnson, Misc=Misc Data, Misc2=Misc Data}

Return a value for a row number and column


grid.getValueByRowAndColumn(0, "Phone Number");
865-555-9843

Return grid column names


grid.getColumns();
[Address, Phone Number, First Name, Last Name, Misc, Misc2]

Remove some columns and verify


grid.removeColumn("Misc");
grid.removeColumn("Misc2");
grid.getColumns()
[Address, Phone Number, First Name, Last Name]

Print a grid


grid.toString();
+-----+-----------------+--------------+------------+-----------+
| Row |         Address | Phone Number | First Name | Last Name |
+-----+-----------------+--------------+------------+-----------+
|   0 | 921 Thompson St | 865-555-9843 |    Michael |   Johnson |
+-----+-----------------+--------------+------------+-----------+
|   1 | 923 Thompson St | 865-555-8340 |      James |     Smith |
+-----+-----------------+--------------+------------+-----------+
2 of 2

About

This class allows creation of a grid that can be easily created, modified, and searched.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages