Parsing through a table - looking for a matching values

Posted on 2012-04-10
Last Modified: 2012-04-17
Here is the code where I am creating my table values.
 public Object getValueAt(int row, int column) {
      Object o = null;
      try {
         switch (column) {
            case ITEMID_COL: {
               o = rds.get(row).rev.getItem().getStringProperty("item_id");
            case REVID_COL: {
               o = rds.get(row).rev.getStringProperty("item_revision_id");
            case PRL_COL: {
             String prl = getRevPrl(rds.get(row).rev);
             if (isMatrixPRLCellReadOnly == true) {
                o = prl;
             else {
                 if ((prl == null || prl.isEmpty())){
                    o = pmap.get(rds.get(row).rev);
                 else {
                    o = prl;
            case DATASETNAME_COL: {
               o = rds.get(row).componentdataset.getStringProperty("object_string");
            case DATASET_COL: {
               o = rds.get(row).componentdataset.getStringProperty("object_type");
            case COMMENT_COL: {
               o = cmap.get(rds.get(row).rev);
            case REVUID_COL: {
               o = rds.get(row).rev.getUid();
            case DSETUID_COL: {
               o = rds.get(row).componentdataset.getUid();
      catch (Exception e) {
      return o;

Open in new window

Then I am parsing information from the table to create a XML String

public void getTableXML(StringBuffer sb) {
      for(int i = 0; i < SingletonSelectTable.getInstance().getRowCount(); i++) {
         Object item_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().ITEMID_COL);
         Object rev_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().REVID_COL);
         Object prl_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().PRL_COL);
         Object datasetName_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().DATASETNAME_COL);
         Object datasetType_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().DATASET_COL);
         Object comment_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().COMMENT_COL);
         Object revu_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().REVUID_COL);
         Object dsetu_id = SingletonSelectTable.getInstance().getValueAt(i, SingletonSelectTable.getInstance().DSETUID_COL);
         sb.append("   <ItemRevision itemId=\"" + item_id + "\"");
         sb.append(" revId=\"" + rev_id + "\"");
         sb.append(" prl=\"" + prl_id+ "\"");
         sb.append(" Uid=\"" + revu_id+ "\"");
         sb.append("      <Comment>" + comment_id + "</Comment>\n");
         sb.append("      <Dataset name=\"" + datasetName_id + "\"");
         sb.append(" type=\"" + datasetType_id + "\"");
         sb.append(" Uid=\"" + dsetu_id + "\"");
         sb.append(" />\n");
         sb.append("   </ItemRevision>\n");

Open in new window

What I am trying to do is look for a matching value.

say that I have 5 entries in my table and there are 2 that have the same item_id
I want to create the logic that parsing through the table and when finds a match it will print out found match.

I am not sure what is the best way to parse the table.  I am guessing we would have to get the first value for item_id and the check the rest of the table looking for a matching item_id.  The we would have to get the second value for item_id and parse the table again?

I really  do not know how to approach this.
Question by:jkteater
  • 3
LVL 26

Accepted Solution

ksivananth earned 250 total points
ID: 37831176
you may want to deal with the underlying tablemodel. override the tablemodel in such a way that it is aware of rows having the same item ids.

Assisted Solution

sharath_kulal earned 250 total points
ID: 37835002
yeah you need to use TableModel to set/retreive data to JTable.
you'll have more control over the data manipulating the JTable.

Author Comment

ID: 37838072
Can you show me an example of what you are suggesting?

Author Comment

ID: 37839571
I really need to figure out how to do this.  I am going to increase the points.  I could really use a example to help me understand.  

In my XML string, I need to know if the data in the table is a part or a drawing.  The only time I need to check for drawing or part is when I have a drawing for a part.  If that is the case they will share the same item_id, but could be on different rows in the table.  The table can have any where from 1 to 50 entries.

Author Comment

ID: 37839659
Ok lets assume that I have a arraylist - the list looks something like this

item          rev            type
1001         1001-1       part
1002         1002-1       part
1001         1001-1       drawing

so when I am writing out to my xml string - I need it to look something like this (not formatted)

<ItemRev item="1001" rev "1001-1">
          <Masterdata  Name="foo" type="part"/>
          <ExtraData Name="foo" type="drawing"\>
<ItemRev item="1002" rev "1002-1">
          <Masterdata  Name="foo1" type="part"/>

as you see above that 1001 has 2 entries in the table/arraylist - one being a part and one a drawing.

How would you parse that arraylist - I am going to use rev as my key to look for matches

Here is what I am was thinking about the logic

get first entry in array
get rev value
check the rest of the array looking for a matching value of rev
if no match
write xml string to buffer
if match
   get name value and and type value for the first entry and the matching entry
   if type value = part
       write xml buffer for masterdata
       write xml buffer for extradata

but then what happens - if you h ave to do each line and check every line, that could take a while logically.

I hope the above makes more since at what I am trying to do

Featured Post

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 88
micro services vs rest web services 16 104
eclipse package explorer vs project explorer view 2 131
jar file executable 12 51
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question