1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.internal.macro.chart.source.table

File TableCategoryDatasetBuilder.java

 

Coverage histogram

../../../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

6
17
11
1
144
82
14
0.82
1.55
11
1.27

Classes

Class Line # Actions
TableCategoryDatasetBuilder 37 17 0% 14 4
0.8823529588.2%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.internal.macro.chart.source.table;
21   
22    import java.util.HashSet;
23    import java.util.Map;
24    import java.util.Set;
25   
26    import org.jfree.data.category.DefaultCategoryDataset;
27    import org.jfree.data.general.Dataset;
28    import org.xwiki.rendering.internal.macro.chart.source.LocaleConfiguration;
29    import org.xwiki.rendering.macro.MacroExecutionException;
30   
31    /**
32    * A builder of category datasets ({@see org.jfree.data.category.CategoryDataset}) from table data sources.
33    *
34    * @version $Id: b4625b901526dd5d55292909d26da2b14dad3510 $
35    * @since 4.2M1
36    */
 
37    public class TableCategoryDatasetBuilder implements TableDatasetBuilder
38    {
39    /**
40    * The catetegory dataset.
41    */
42    private final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
43   
44    /**
45    * The array of row keys.
46    */
47    private String[] rowKeys;
48   
49    /**
50    * The array of column keys.
51    */
52    private String[] columnKeys;
53   
54    /**
55    * Indicates if the transpose of the table should be used.
56    */
57    private boolean transpose;
58   
59    /**
60    * Row key set used for validating the absense of duplicate row keys.
61    */
62    private final Set<String> rowKeySet = new HashSet<String>();
63   
64    /**
65    * Column key set used for validating the absense of duplicate column keys.
66    */
67    private final Set<String> columnKeySet = new HashSet<String>();
68   
 
69  16 toggle @Override
70    public void setNumberOfRows(int numberOfRows)
71    {
72  16 rowKeys = new String[numberOfRows];
73    }
74   
 
75  16 toggle @Override
76    public void setNumberOfColumns(int numberOfColumns)
77    {
78  16 columnKeys = new String[numberOfColumns];
79    }
80   
 
81  11 toggle @Override
82    public void setTranspose(boolean transpose)
83    {
84  11 this.transpose = transpose;
85    }
86   
 
87  35 toggle @Override
88    public void setColumnHeading(int columnIndex, String heading) throws MacroExecutionException
89    {
90  35 if (columnKeySet.contains(heading)) {
91  0 throw new MacroExecutionException(String.format("Duplicate column keys in table: [%s]", heading));
92    }
93  35 columnKeySet.add(heading);
94  35 columnKeys[columnIndex] = heading;
95    }
96   
 
97  19 toggle @Override
98    public void setRowHeading(int rowIndex, String heading) throws MacroExecutionException
99    {
100  19 if (rowKeySet.contains(heading)) {
101  0 throw new MacroExecutionException(String.format("Duplicate row keys in table: [%s]", heading));
102    }
103  19 rowKeySet.add(heading);
104  19 rowKeys[rowIndex] = heading;
105    }
106   
 
107  58 toggle @Override
108    public void setValue(int rowIndex, int columnIndex, Number value)
109    {
110  58 if (transpose) {
111  28 dataset.addValue(value, columnKeys[columnIndex], rowKeys[rowIndex]);
112    } else {
113  30 dataset.addValue(value, rowKeys[rowIndex], columnKeys[columnIndex]);
114    }
115    }
116   
 
117  16 toggle @Override
118    public Dataset getDataset()
119    {
120  16 return dataset;
121    }
122   
 
123  16 toggle @Override
124    public void setParameters(Map<String, String> parameters)
125    {
126    }
127   
 
128  4 toggle @Override
129    public boolean forceColumnHeadings()
130    {
131  4 return false;
132    }
133   
 
134  4 toggle @Override
135    public boolean forceRowHeadings()
136    {
137  4 return false;
138    }
139   
 
140  16 toggle @Override
141    public void setLocaleConfiguration(LocaleConfiguration localeConfiguration)
142    {
143    }
144    }