.hasNext();)
{
JSONObject doc = docIter.next();
- // if (doc.get("molecule_sequence") != null)
- // {
result.add(searchResult.new PDBResponseSummary(doc, pdbRestRequest));
- // }
}
searchResult.setNumberOfItemsFound(numFound);
searchResult.setResponseTime(queryTime);
{
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
}
/**
- * 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
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;
}
/**
import java.util.Collection;
import java.util.Objects;
-import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;
import org.json.simple.JSONObject;
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
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;
}
/**
{
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()
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());
}
}