Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.fts.core

File FTSRestResponse.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

12
33
10
1
176
114
18
0.55
3.3
10
1.8

Classes

Class Line # Actions
FTSRestResponse 41 33 18
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21   
22    package jalview.fts.core;
23   
24    import jalview.datamodel.SequenceI;
25    import jalview.fts.api.FTSData;
26    import jalview.fts.api.FTSDataColumnI;
27   
28    import java.util.Collection;
29    import java.util.Map;
30   
31    import javax.swing.JTable;
32    import javax.swing.table.DefaultTableModel;
33   
34    /**
35    * Represents the response model generated by the FTSRestClient upon successful
36    * execution of a given FTS request
37    *
38    * @author tcnofoegbu
39    *
40    */
 
41    public class FTSRestResponse
42    {
43    private int numberOfItemsFound;
44   
45    private String responseTime;
46   
47    private Collection<FTSData> searchSummary;
48   
 
49  0 toggle public int getNumberOfItemsFound()
50    {
51  0 return numberOfItemsFound;
52    }
53   
 
54  0 toggle public void setNumberOfItemsFound(int itemFound)
55    {
56  0 this.numberOfItemsFound = itemFound;
57    }
58   
 
59  0 toggle public String getResponseTime()
60    {
61  0 return responseTime;
62    }
63   
 
64  0 toggle public void setResponseTime(String responseTime)
65    {
66  0 this.responseTime = responseTime;
67    }
68   
 
69  0 toggle public Collection<FTSData> getSearchSummary()
70    {
71  0 return searchSummary;
72    }
73   
 
74  0 toggle public void setSearchSummary(Collection<FTSData> searchSummary)
75    {
76  0 this.searchSummary = searchSummary;
77    }
78   
79    /**
80    * Convenience method to obtain a Table model for a given summary List based
81    * on the request parameters
82    *
83    * @param request
84    * the FTSRestRequest object which holds useful information for
85    * creating a table model
86    * @param summariesList
87    * the summary list which contains the data for populating the
88    * table's rows
89    * @return the table model which was dynamically generated
90    */
 
91  0 toggle public static DefaultTableModel getTableModel(FTSRestRequest request,
92    Collection<FTSData> summariesList)
93    {
94  0 final FTSDataColumnI[] cols = request.getWantedFields()
95    .toArray(new FTSDataColumnI[0]);
96  0 final int colOffset = request.getAssociatedSequence() == null ? 0 : 1;
97  0 DefaultTableModel tableModel = new DefaultTableModel()
98    {
 
99  0 toggle @Override
100    public boolean isCellEditable(int row, int column)
101    {
102  0 return false;
103    }
104   
 
105  0 toggle @Override
106    public Class<?> getColumnClass(int columnIndex)
107    {
108  0 if (colOffset == 1 && columnIndex == 0)
109    {
110  0 return SequenceI.class;
111    }
112  0 return cols[columnIndex - colOffset].getDataType()
113    .getDataTypeClass();
114    }
115   
116    };
117  0 if (request.getAssociatedSequence() != null)
118    {
119  0 tableModel.addColumn("Ref Sequence"); // Create sequence column header if
120    // exists in the request
121    }
122  0 for (FTSDataColumnI field : request.getWantedFields())
123    {
124  0 tableModel.addColumn(field.getName()); // Create sequence column header if
125    // exists in the request
126    }
127   
128  0 for (FTSData res : summariesList)
129    {
130  0 tableModel.addRow(res.getSummaryData()); // Populate table rows with
131    // summary list
132    }
133   
134  0 return tableModel;
135    }
136   
 
137  0 toggle public static void configureTableColumn(JTable tbl_summary,
138    Collection<FTSDataColumnI> wantedFields,
139    Map<String, Integer> columnPrefs)
140    {
141  0 for (FTSDataColumnI wantedField : wantedFields)
142    {
143  0 try
144    {
145  0 tbl_summary.getColumn(wantedField.getName())
146    .setMinWidth(wantedField.getMinWidth());
147  0 tbl_summary.getColumn(wantedField.getName())
148    .setMaxWidth(wantedField.getMaxWidth());
149  0 int prefedWidth = columnPrefs.get(wantedField.getName()) == null
150    ? wantedField.getPreferredWidth()
151    : columnPrefs.get(wantedField.getName());
152  0 tbl_summary.getColumn(wantedField.getName())
153    .setPreferredWidth(prefedWidth);
154    } catch (Exception e)
155    {
156  0 e.printStackTrace();
157    }
158  0 if (wantedField.getDataType().getDataTypeClass() == Double.class)
159    {
160  0 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
161    wantedField.getDataType().isFormtted(),
162    wantedField.getDataType().getSignificantFigures());
163  0 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
164    }
165  0 else if (wantedField.getDataType()
166    .getDataTypeClass() == Integer.class)
167    {
168  0 DecimalFormatTableCellRenderer dfr = new DecimalFormatTableCellRenderer(
169    wantedField.getDataType().isFormtted(),
170    wantedField.getDataType().getSignificantFigures());
171  0 tbl_summary.getColumn(wantedField.getName()).setCellRenderer(dfr);
172    }
173    }
174    }
175   
176    }