List of usage examples for org.jfree.data DefaultKeyedValues addValue
public void addValue(Comparable key, Number value)
From source file:org.jfree.data.DefaultKeyedValuesTest.java
/** * Tests sorting of data by value (ascending). *///from www .jav a2 s . c o m @Test public void testSortByValueAscending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.ASCENDING); // check key order assertEquals(data.getKey(0), "C"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "D"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // 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.DefaultKeyedValuesTest.java
/** * Tests sorting of data by key (descending). *///from w w w . java 2s . c o m @Test public void testSortByValueDescending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.DESCENDING); // check key order assertEquals(data.getKey(0), "D"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(3.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(1.0)); assertEquals(data.getValue(3), null); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Some checks for the clone() method./*from ww w . ja v a 2s . 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) { 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.DefaultKeyedValuesTests.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w . j av a2 s . c o m public void testSerialization() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("Key 1", new Double(23)); v1.addValue("Key 2", null); v1.addValue("Key 3", new Double(42)); DefaultKeyedValues v2 = null; try { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray())); v2 = (DefaultKeyedValues) in.readObject(); in.close(); } catch (Exception e) { e.printStackTrace(); } assertEquals(v1, v2); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java
/** * A simple test for the clear() method. *//* w w w . j a va 2s . c om*/ public void testClear() { DefaultKeyedValues v1 = new DefaultKeyedValues(); v1.addValue("A", 1.0); v1.addValue("B", 2.0); assertEquals(2, v1.getItemCount()); v1.clear(); assertEquals(0, v1.getItemCount()); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Check that inserting and retrieving values works as expected. *//*from w w w .j a v a 2 s .com*/ 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
/** * Tests sorting of data by key (ascending). *///from w ww.j a v a 2s.c o m public void testSortByKeyAscending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByKeys(SortOrder.ASCENDING); // 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(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(2.0)); assertEquals(data.getValue(1), null); assertEquals(data.getValue(2), new Double(1.0)); assertEquals(data.getValue(3), new Double(3.0)); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Tests sorting of data by key (descending). *//* w ww . j av a 2 s. c om*/ public void testSortByKeyDescending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByKeys(SortOrder.DESCENDING); // check key order assertEquals(data.getKey(0), "D"); assertEquals(data.getKey(1), "C"); assertEquals(data.getKey(2), "B"); assertEquals(data.getKey(3), "A"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(3.0)); assertEquals(data.getValue(1), new Double(1.0)); assertEquals(data.getValue(2), null); assertEquals(data.getValue(3), new Double(2.0)); }
From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java
/** * Tests sorting of data by value (ascending). *///from w w w. j a va 2 s .c om public void testSortByValueAscending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.ASCENDING); // check key order assertEquals(data.getKey(0), "C"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "D"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // 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
/** * Tests sorting of data by key (descending). *///from w w w . j a v a 2 s .c o m public void testSortByValueDescending() { DefaultKeyedValues data = new DefaultKeyedValues(); data.addValue("C", new Double(1.0)); data.addValue("B", null); data.addValue("D", new Double(3.0)); data.addValue("A", new Double(2.0)); data.sortByValues(SortOrder.DESCENDING); // check key order assertEquals(data.getKey(0), "D"); assertEquals(data.getKey(1), "A"); assertEquals(data.getKey(2), "C"); assertEquals(data.getKey(3), "B"); // check retrieve value by key assertEquals(data.getValue("A"), new Double(2.0)); assertEquals(data.getValue("B"), null); assertEquals(data.getValue("C"), new Double(1.0)); assertEquals(data.getValue("D"), new Double(3.0)); // check retrieve value by index assertEquals(data.getValue(0), new Double(3.0)); assertEquals(data.getValue(1), new Double(2.0)); assertEquals(data.getValue(2), new Double(1.0)); assertEquals(data.getValue(3), null); }