Go Premium for a chance to win a PS4. Enter to Win


Parsing through a table - looking for a matching values

Posted on 2012-04-10
Medium Priority
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 1000 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 1000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

824 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