Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
HCDataset |
|
| 3.0;3 |
1 | /* ======================================================================= | |
2 | * A visualisation library extension for JFreeChart. Please see JFreeChart | |
3 | * for further information. | |
4 | * ======================================================================= | |
5 | * Copyright (C) 2006 University of Helsinki, Department of Computer Science | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2.1 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | * ----------------------------- | |
21 | * Contact: ohtu@cs.helsinki.fi | |
22 | * ----------------------------- | |
23 | * | |
24 | */ | |
25 | ||
26 | ||
27 | package org.jfree.data.hc; | |
28 | ||
29 | import org.jfree.data.general.AbstractDataset; | |
30 | import org.jfree.data.hc.HeatMap; | |
31 | import org.jfree.data.hc.HCTreeNode; | |
32 | ||
33 | import java.lang.Exception; | |
34 | ||
35 | /** | |
36 | * A class representing data for the hierarchical clustering | |
37 | * and heatmap visualisation. | |
38 | * @author viski project | |
39 | */ | |
40 | public class HCDataset extends AbstractDataset { | |
41 | ||
42 | private HeatMap heatMap; | |
43 | private HCTreeNode rowTree; | |
44 | private HCTreeNode columnTree; | |
45 | ||
46 | /** | |
47 | * Creates a new dataset. | |
48 | * | |
49 | * @param heatMap the heatmap of this dataset. | |
50 | * @param columnTree the column clustering tree of this dataset or null. | |
51 | * @param rowTree the row clustering tree of this dataset or null. | |
52 | * | |
53 | * @throws IllegalArgumentException if the row or column clustering | |
54 | * trees don't match the size of the heatmaps. The row clustering tree | |
55 | * must have exactly as many leaf nodes as there are rows in the heatmap, | |
56 | * and the row clustering tree must have exactly as many leaf nodes as | |
57 | * there are rows in the heatmap, | |
58 | * @throws NullPointerException if the heatmap is null. | |
59 | * @throws IllegalArgumentException if either of the trees does | |
60 | * not meet the criteria of {@link finalizeTree}. | |
61 | */ | |
62 | public HCDataset(HeatMap heatMap, HCTreeNode rowTree, HCTreeNode columnTree) | |
63 | 28 | throws IllegalArgumentException, NullPointerException { |
64 | ||
65 | 28 | if (heatMap == null) throw new NullPointerException( |
66 | "HeatMap given to HCDataset() was null."); | |
67 | ||
68 | 27 | this.rowTree = rowTree; |
69 | 27 | this.columnTree = columnTree; |
70 | 27 | this.heatMap = heatMap; |
71 | ||
72 | // does left tree match with heatmap height? | |
73 | 27 | if ( |
74 | (this.rowTree != null) && | |
75 | (this.heatMap.getRowCount() | |
76 | != this.rowTree.getDataRange().getWidth()) | |
77 | 2 | ) throw new IllegalArgumentException( |
78 | "Left tree doesn't match heatmap height."); | |
79 | ||
80 | // does top tree match with heatmap width | |
81 | 25 | if ( |
82 | (this.columnTree != null) && | |
83 | (this.heatMap.getColumnsCount() | |
84 | != this.columnTree.getDataRange().getWidth()) | |
85 | 1 | ) throw new IllegalArgumentException( |
86 | "Top tree doesn't match heatmap width."); | |
87 | ||
88 | // these throw exceptions if something is wrong. | |
89 | 24 | if (this.rowTree != null) this.rowTree.finalizeTree(); |
90 | 24 | if (this.columnTree != null) this.columnTree.finalizeTree(); |
91 | ||
92 | 24 | } |
93 | ||
94 | /** | |
95 | * Returns the heatmap of this dataset. | |
96 | * | |
97 | * @return the heatmap. | |
98 | */ | |
99 | public HeatMap getHeatMap() { | |
100 | ||
101 | 852 | return this.heatMap; |
102 | ||
103 | } | |
104 | ||
105 | /** | |
106 | * Returns the column clustering tree. | |
107 | * | |
108 | * @return the clustering tree, or null, if the tree does not exist. | |
109 | */ | |
110 | public HCTreeNode getColumnClusteringTree() { | |
111 | ||
112 | 82 | return this.columnTree; |
113 | ||
114 | } | |
115 | ||
116 | /** | |
117 | * Returns the row clustering tree. | |
118 | * | |
119 | * @return the clustering tree, or null, if the tree does not exist. | |
120 | */ | |
121 | public HCTreeNode getRowClusteringTree() { | |
122 | ||
123 | 82 | return this.rowTree; |
124 | ||
125 | } | |
126 | ||
127 | } |