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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now