List of usage examples for org.jfree.data KeyToGroupMap getGroup
public Comparable getGroup(Comparable key)
From source file:org.jfree.data.KeyToGroupMapTest.java
/** * Tests the mapKeyToGroup() method.//from w w w .ja v a 2 s . c o m */ @Test public void testMapKeyToGroup() { KeyToGroupMap m1 = new KeyToGroupMap("G1"); // map a key to the default group m1.mapKeyToGroup("K1", "G1"); assertEquals("G1", m1.getGroup("K1")); // map a key to a new group m1.mapKeyToGroup("K2", "G2"); assertEquals("G2", m1.getGroup("K2")); // clear a mapping m1.mapKeyToGroup("K2", null); assertEquals("G1", m1.getGroup("K2")); // after clearing, reverts to // default group // check handling of null key boolean pass = false; try { m1.mapKeyToGroup(null, "G1"); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.KeyToGroupMapTest.java
/** * Tests the getGroup() method.//www .jav a 2 s. c om */ @Test public void testGetGroup() { KeyToGroupMap m1 = new KeyToGroupMap("Default Group"); // a key that hasn't been mapped should return the default group assertEquals("Default Group", m1.getGroup("K1")); m1.mapKeyToGroup("K1", "G1"); assertEquals("G1", m1.getGroup("K1")); m1.mapKeyToGroup("K1", "G2"); assertEquals("G2", m1.getGroup("K1")); m1.mapKeyToGroup("K1", null); assertEquals("Default Group", m1.getGroup("K1")); // a null argument should throw an exception boolean pass = false; try { Comparable g = m1.getGroup(null); } catch (IllegalArgumentException e) { pass = true; } assertTrue(pass); }
From source file:org.jfree.data.general.DatasetUtils.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset./*from ww w. j a v a 2 s. c o m*/ * @param map a structure that maps series to groups. * * @return The value range ({@code null} if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { Args.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // create an array holding the group indices for each series... int[] groupIndex = new int[dataset.getRowCount()]; for (int i = 0; i < dataset.getRowCount(); i++) { groupIndex[i] = map.getGroupIndex(map.getGroup(dataset.getRowKey(i))); } // minimum and maximum for each group... int groupCount = map.getGroupCount(); double[] minimum = new double[groupCount]; double[] maximum = new double[groupCount]; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double[] positive = new double[groupCount]; double[] negative = new double[groupCount]; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { positive[groupIndex[series]] = positive[groupIndex[series]] + value; } if (value < 0.0) { negative[groupIndex[series]] = negative[groupIndex[series]] + value; // '+', remember value is negative } } } for (int g = 0; g < groupCount; g++) { minimum[g] = Math.min(minimum[g], negative[g]); maximum[g] = Math.max(maximum[g], positive[g]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }
From source file:org.jfree.data.general.DatasetUtilities.java
/** * Returns the minimum and maximum values for the dataset's range * (y-values), assuming that the series in one category are stacked. * * @param dataset the dataset./*from w w w . j a v a 2 s . c om*/ * @param map a structure that maps series to groups. * * @return The value range (<code>null</code> if the dataset contains no * values). */ public static Range findStackedRangeBounds(CategoryDataset dataset, KeyToGroupMap map) { ParamChecks.nullNotPermitted(dataset, "dataset"); boolean hasValidData = false; Range result = null; // create an array holding the group indices for each series... int[] groupIndex = new int[dataset.getRowCount()]; for (int i = 0; i < dataset.getRowCount(); i++) { groupIndex[i] = map.getGroupIndex(map.getGroup(dataset.getRowKey(i))); } // minimum and maximum for each group... int groupCount = map.getGroupCount(); double[] minimum = new double[groupCount]; double[] maximum = new double[groupCount]; int categoryCount = dataset.getColumnCount(); for (int item = 0; item < categoryCount; item++) { double[] positive = new double[groupCount]; double[] negative = new double[groupCount]; int seriesCount = dataset.getRowCount(); for (int series = 0; series < seriesCount; series++) { Number number = dataset.getValue(series, item); if (number != null) { hasValidData = true; double value = number.doubleValue(); if (value > 0.0) { positive[groupIndex[series]] = positive[groupIndex[series]] + value; } if (value < 0.0) { negative[groupIndex[series]] = negative[groupIndex[series]] + value; // '+', remember value is negative } } } for (int g = 0; g < groupCount; g++) { minimum[g] = Math.min(minimum[g], negative[g]); maximum[g] = Math.max(maximum[g], positive[g]); } } if (hasValidData) { for (int j = 0; j < groupCount; j++) { result = Range.combine(result, new Range(minimum[j], maximum[j])); } } return result; }