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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

752 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