List of usage examples for org.jfree.data DefaultKeyedValues DefaultKeyedValues
public DefaultKeyedValues()
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Some checks for the insertValue() method. *///from www. j av a 2 s . c o m @Test public void testInsertValue() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.insertValue(0, "A", 1.0); assertEquals(new Double(1.0), v1.getValue(0)); v1.insertValue(0, "B", 2.0); assertEquals(new Double(2.0), v1.getValue(0)); assertEquals(new Double(1.0), v1.getValue(1)); // it's OK to use an index equal to the size of the list v1.insertValue(2, "C", 3.0); assertEquals(new Double(2.0), v1.getValue(0)); assertEquals(new Double(1.0), v1.getValue(1)); assertEquals(new Double(3.0), v1.getValue(2)); // try replacing an existing value v1.insertValue(2, "B", 4.0); assertEquals(new Double(1.0), v1.getValue(0)); assertEquals(new Double(3.0), v1.getValue(1)); assertEquals(new Double(4.0), v1.getValue(2)); }
From source file:org.jfree.data.DataUtils.java
/** * Returns a {@link KeyedValues} instance that contains the cumulative * percentage values for the data in another {@link KeyedValues} instance. * <p>/* w w w.j ava2s. c o m*/ * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%). * * @param data the data ({@code null} not permitted). * * @return The cumulative percentages. */ public static KeyedValues getCumulativePercentages(KeyedValues data) { Args.nullNotPermitted(data, "data"); DefaultKeyedValues result = new DefaultKeyedValues(); double total = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { total = total + v.doubleValue(); } } double runningTotal = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { runningTotal = runningTotal + v.doubleValue(); } result.addValue(data.getKey(i), new Double(runningTotal / total)); } return result; }
From source file:org.jfree.data.DataUtilities.java
/** * Returns a {@link KeyedValues} instance that contains the cumulative * percentage values for the data in another {@link KeyedValues} instance. * <p>/*from w w w. j a v a2 s.c o m*/ * The percentages are values between 0.0 and 1.0 (where 1.0 = 100%). * * @param data the data (<code>null</code> not permitted). * * @return The cumulative percentages. */ public static KeyedValues getCumulativePercentages(KeyedValues data) { ParamChecks.nullNotPermitted(data, "data"); DefaultKeyedValues result = new DefaultKeyedValues(); double total = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { total = total + v.doubleValue(); } } double runningTotal = 0.0; for (int i = 0; i < data.getItemCount(); i++) { Number v = data.getValue(i); if (v != null) { runningTotal = runningTotal + v.doubleValue(); } result.addValue(data.getKey(i), new Double(runningTotal / total)); } return result; }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Some checks for the insertValue() method. *///w w w.ja v a2 s . com public void testInsertValue() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.insertValue(0, "A", 1.0); assertEquals(new Double(1.0), v1.getValue(0)); v1.insertValue(0, "B", 2.0); assertEquals(new Double(2.0), v1.getValue(0)); assertEquals(new Double(1.0), v1.getValue(1)); // it's OK to use an index equal to the size of the list v1.insertValue(2, "C", 3.0); assertEquals(new Double(2.0), v1.getValue(0)); assertEquals(new Double(1.0), v1.getValue(1)); assertEquals(new Double(3.0), v1.getValue(2)); // try replacing an existing value v1.insertValue(2, "B", 4.0); assertEquals(new Double(1.0), v1.getValue(0)); assertEquals(new Double(3.0), v1.getValue(1)); assertEquals(new Double(4.0), v1.getValue(2)); }
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Some checks for the clone() method.//ww w.jav a2 s. c o m */ @Test public void testCloning() throws CloneNotSupportedException { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("V1", new Integer(1)); v1.addValue("V2", null); v1.addValue("V3", new Integer(3)); DefaultKeyedValues v2 = (DefaultKeyedValues) v1.clone(); assertTrue(v1 != v2); assertTrue(v1.getClass() == v2.getClass()); assertTrue(v1.equals(v2)); // confirm that the clone is independent of the original v2.setValue("V1", new Integer(44)); assertFalse(v1.equals(v2)); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Some checks for the clone() method.//from w ww. j a v a 2 s . c om */ public void testCloning() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("V1", new Integer(1)); v1.addValue("V2", null); v1.addValue("V3", new Integer(3)); DefaultKeyedValues v2 = null; try { v2 = (DefaultKeyedValues) v1.clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } assertTrue(v1 != v2); assertTrue(v1.getClass() == v2.getClass()); assertTrue(v1.equals(v2)); // confirm that the clone is independent of the original v2.setValue("V1", new Integer(44)); assertFalse(v1.equals(v2)); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Some checks for the clone() method./*ww w. ja v a 2 s. co m*/ */ public void testCloning() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("V1", new Integer(1)); v1.addValue("V2", null); v1.addValue("V3", new Integer(3)); DefaultKeyedValues v2 = null; try { v2 = (DefaultKeyedValues) v1.clone(); } catch (CloneNotSupportedException e) { System.err.println("Failed to clone."); } assertTrue(v1 != v2); assertTrue(v1.getClass() == v2.getClass()); assertTrue(v1.equals(v2)); // confirm that the clone is independent of the original v2.setValue("V1", new Integer(44)); assertFalse(v1.equals(v2)); }
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Check that inserting and retrieving values works as expected. *//*from w w w .ja v a 2 s. c om*/ @Test public void testInsertAndRetrieve() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("A", new Double(1.0)); data.addValue("B", new Double(2.0)); data.addValue("C", new Double(3.0)); data.addValue("D", null); // check key order assertEquals(data.getKey(0), "A"); assertEquals(data.getKey(1), "B"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "D"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(1.0)); assertEquals(data.getValue("B"), new Double(2.0)); assertEquals(data.getValue("C"), new Double(3.0)); assertEquals(data.getValue("D"), null); // check retrieve value by index assertEquals(data.getValue(0), new Double(1.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(3.0)); assertEquals(data.getValue(3), null); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Check that inserting and retrieving values works as expected. *///from ww w . j av a 2 s.c om public void testInsertAndRetrieve() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("A", new Double(1.0)); data.addValue("B", new Double(2.0)); data.addValue("C", new Double(3.0)); data.addValue("D", null); // check key order assertEquals(data.getKey(0), "A"); assertEquals(data.getKey(1), "B"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "D"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(1.0)); assertEquals(data.getValue("B"), new Double(2.0)); assertEquals(data.getValue("C"), new Double(3.0)); assertEquals(data.getValue("D"), null); // check retrieve value by index assertEquals(data.getValue(0), new Double(1.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(3.0)); assertEquals(data.getValue(3), null); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * Check that inserting and retrieving values works as expected. *//*from w ww . ja va 2 s. c om*/ public void testInsertAndRetrieve() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("A", new Double(1.0)); data.addValue("B", new Double(2.0)); data.addValue("C", new Double(3.0)); data.addValue("D", null); // check key order assertEquals(data.getKey(0), "A"); assertEquals(data.getKey(1), "B"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "D"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(1.0)); assertEquals(data.getValue("B"), new Double(2.0)); assertEquals(data.getValue("C"), new Double(3.0)); assertEquals(data.getValue("D"), null); // check retrieve value by index assertEquals(data.getValue(0), new Double(1.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(3.0)); assertEquals(data.getValue(3), null); }