JAL-1668 house keeping
authorCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 18 Mar 2015 17:05:03 +0000 (17:05 +0000)
committerCharles Ofoegbu <tcnofoegbu@dundee.ac.uk>
Wed, 18 Mar 2015 17:05:03 +0000 (17:05 +0000)
src/jalview/ws/dbsources/PDBRestClient.java
src/jalview/ws/uimodel/PDBRestResponse.java

index 1a80d65..039d23f 100644 (file)
@@ -148,10 +148,7 @@ public class PDBRestClient
                 .hasNext();)
         {
           JSONObject doc = docIter.next();
-          // if (doc.get("molecule_sequence") != null)
-          // {
           result.add(searchResult.new PDBResponseSummary(doc, pdbRestRequest));
-          // }
         }
         searchResult.setNumberOfItemsFound(numFound);
         searchResult.setResponseTime(queryTime);
@@ -161,13 +158,12 @@ public class PDBRestClient
     {
       e.printStackTrace();
     }
-
     return searchResult;
   }
 
   /**
-   * Takes a collection of PDBDocField and converts it into a comma delimited
-   * string.
+   * Takes a collection of PDBDocField and converts its code values into a comma
+   * delimited string.
    * 
    * @param pdbDocfields
    * @return
@@ -190,8 +186,9 @@ public class PDBRestClient
   }
 
   /**
-   * Determines the column index for the pdb id in the summary table. The pdb id
-   * serves as a unique identifier for a given row in the summary table
+   * Determines the column index for 'PDB Id' Fields in the dynamic summary
+   * table. The PDB Id serves as a unique identifier for a given row in the
+   * summary table
    * 
    * @param wantedFeilds
    *          the available table columns in no particular order
@@ -200,16 +197,18 @@ public class PDBRestClient
   public static int getPDBIdColumIndex(
           Collection<PDBDocField> wantedFeilds, boolean hasRefSeq)
   {
-    int pdbFeildIndex = hasRefSeq ? 1 : 0;
+    int pdbFeildIndexCounter = hasRefSeq ? 1 : 0; // If a reference sequence is
+                                           // attached then start counting from
+                                           // 1 else start from zero
     for (PDBDocField feild : wantedFeilds)
     {
       if (feild.equals(PDBDocField.PDB_ID))
       {
-        break;
+        break; // once PDB Id index is determined exit iteration
       }
-      ++pdbFeildIndex;
+      ++pdbFeildIndexCounter;
     }
-    return pdbFeildIndex;
+    return pdbFeildIndexCounter;
   }
 
   /**
index 889a324..fb227ee 100644 (file)
@@ -26,7 +26,6 @@ import jalview.ws.dbsources.PDBRestClient.PDBDocField;
 import java.util.Collection;
 import java.util.Objects;
 
-import javax.swing.DefaultListModel;
 import javax.swing.table.DefaultTableModel;
 
 import org.json.simple.JSONObject;
@@ -76,24 +75,6 @@ public class PDBRestResponse
     this.searchSummary = searchSummary;
   }
 
-  /**
-   * Convenience method to obtain a List model for a given summary list
-   * 
-   * @param summariesList
-   *          the summary list which contains the data for generating the lists
-   *          data
-   * @return the list model generated for the search summary
-   */
-  public static DefaultListModel<PDBResponseSummary> getListModel(
-          Collection<PDBResponseSummary> summariesList)
-  {
-    DefaultListModel<PDBResponseSummary> defaultListModel = new DefaultListModel<PDBResponseSummary>();
-    for (PDBResponseSummary summaryList : summariesList)
-    {
-      defaultListModel.addElement(summaryList);
-    }
-    return defaultListModel;
-  }
 
   /**
    * Convenience method to obtain a Table model for a given summary List and
@@ -110,22 +91,25 @@ public class PDBRestResponse
   public static DefaultTableModel getTableModel(PDBRestRequest request,
           Collection<PDBResponseSummary> summariesList)
   {
-    DefaultTableModel model = new DefaultTableModel();
+    DefaultTableModel tableModel = new DefaultTableModel();
 
     if (request.getAssociatedSequence() != null)
     {
-      model.addColumn("Sequence");
+      tableModel.addColumn("Sequence"); // Create sequence column header if
+                                        // exists in the request
     }
     for (PDBDocField field : request.getWantedFields())
     {
-      model.addColumn(field.getName());
+      tableModel.addColumn(field.getName()); // Create sequence column header if
+                                             // exists in the request
     }
 
     for (PDBResponseSummary res : summariesList)
     {
-      model.addRow(res.getSummaryData());
+      tableModel.addRow(res.getSummaryData()); // Populate table rows with
+                                               // summary list
     }
-    return model;
+    return tableModel;
   }
 
   /**
@@ -138,49 +122,40 @@ public class PDBRestResponse
   {
     private String pdbId;
 
-    private String concatenatedSummaryData;
-
-    private String[] summaryData;
+    private String[] summaryRowData;
 
     private String associatedSequence;
 
-    private int width = 480;
-
     public PDBResponseSummary(JSONObject doc, PDBRestRequest request)
     {
-       StringBuilder summaryBuilder = new StringBuilder();
       Collection<PDBDocField> diplayFields = request.getWantedFields();
       String associatedSeq = request.getAssociatedSequence();
       int colCounter = 0;
-      summaryData = new String[(associatedSeq != null) ? diplayFields
+      summaryRowData = new String[(associatedSeq != null) ? diplayFields
               .size() + 1 : diplayFields.size()];
       if (associatedSeq != null)
       {
         this.associatedSequence = (associatedSeq.length() > 18) ? associatedSeq
                 .substring(0, 18) : associatedSeq;
-        summaryData[0] = associatedSequence;
+        summaryRowData[0] = associatedSequence;
         colCounter = 1;
       }
 
       for (PDBDocField field : diplayFields)
       {
+        String fieldData = (doc.get(field.getCode()) == null) ? "" : doc
+                .get(field.getCode()).toString();
         if (field.equals(PDBDocField.PDB_ID)
                 && doc.get(PDBDocField.PDB_ID.getCode()) != null)
         {
-          this.pdbId = doc.get(PDBDocField.PDB_ID.getCode()).toString();
-          summaryData[colCounter++] = this.pdbId;
+          this.pdbId = fieldData;
+          summaryRowData[colCounter++] = this.pdbId;
         }
         else
         {
-          String value = (doc.get(field.getCode()) == null) ? "" : doc.get(
-                  field.getCode()).toString();
-           summaryBuilder.append(field.getName()).append(": ").append(value)
-                  .append(" | ");
-          summaryData[colCounter++] = value;
+          summaryRowData[colCounter++] = fieldData;
         }
       }
-      this.concatenatedSummaryData = summaryBuilder.toString();
-      summaryBuilder = null;
     }
 
     public String getPdbId()
@@ -193,56 +168,42 @@ public class PDBRestResponse
       this.pdbId = pdbId;
     }
 
-    public String getConcatenatedSummaryData()
-    {
-      return concatenatedSummaryData;
-    }
-
-    public void setConcatenatedSummaryData(String concatenatedSummaryData)
-    {
-      this.concatenatedSummaryData = concatenatedSummaryData;
-    }
-
     public String[] getSummaryData()
     {
-      return summaryData;
+      return summaryRowData;
     }
 
     public void setSummaryData(String[] summaryData)
     {
-      this.summaryData = summaryData;
+      this.summaryRowData = summaryData;
     }
 
+    @Override
     public String toString()
     {
-      StringBuilder html = new StringBuilder();
-      html.append("<html><div style=\"width:" + width
-              + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
-      html.append(concatenatedSummaryData);
-      html.append("</div></html>");
-      return html.toString();
+      StringBuilder summaryFieldValues = new StringBuilder();
+      for (String summaryField : summaryRowData)
+      {
+        summaryFieldValues.append(summaryField).append("\t");
+      }
+      return summaryFieldValues.toString();
     }
 
     @Override
     public int hashCode()
     {
-      return Objects.hash(this.pdbId, this.concatenatedSummaryData);
+      return Objects.hash(this.pdbId, this.toString());
     }
 
     @Override
-    public boolean equals(Object other)
+    public boolean equals(Object that)
     {
-      if (!(other instanceof PDBResponseSummary))
+      if (!(that instanceof PDBResponseSummary))
       {
         return false;
       }
-
-      PDBResponseSummary that = (PDBResponseSummary) other;
-
-      // Custom equality check here.
-      return this.pdbId.equals(that.pdbId)
-              && this.concatenatedSummaryData
-                      .equals(that.concatenatedSummaryData);
+      PDBResponseSummary another = (PDBResponseSummary) that;
+      return this.toString().equals(another.toString());
     }
 
   }