Example usage for org.jfree.data DefaultKeyedValues DefaultKeyedValues

List of usage examples for org.jfree.data DefaultKeyedValues DefaultKeyedValues

Introduction

In this page you can find the example usage for org.jfree.data DefaultKeyedValues DefaultKeyedValues.

Prototype

public DefaultKeyedValues() 

Source Link

Document

Creates a new collection (initially empty).

Usage

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Tests sorting of data by value (ascending).
 *///w ww.  jav a 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.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by value (ascending).
 *//* ww  w . j a  v a2 s .  c  o m*/
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).
 *//*  w  w w . j a va2 s  .  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

/**
 * Tests sorting of data by key (descending).
 *///from  w  w w.jav  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);
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (descending).
 *///w ww  . j av  a 2s .  co 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);

}

From source file:org.jfree.data.DefaultKeyedValuesTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from w  ww .j a v  a  2s  .  c o  m
@Test
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 = (DefaultKeyedValues) TestUtilities.serialised(v1);
    assertEquals(v1, v2);
}

From source file:org.jfree.data.junit.DefaultKeyedValuesTests.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from   www  . ja  v a 2 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

/**
 * Serialize an instance, restore it, and check for equality.
 *//*from w  w w .ja va 2s. c  om*/
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) {
        System.out.println(e.toString());
    }
    assertEquals(v1, v2);

}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getPost3Pie(Session s) {
    DefaultKeyedValues data = new DefaultKeyedValues();

    int numPosts = 0;
    int numTypePosts = 0;
    String query = "select count(*) from PostModel as p where p.date > ? and "
            + "(p.group=? or p.group.parent=?)";

    for (GroupChapterModel chapter : GroupChapterModel.getChapters()) {
        numTypePosts = ((Long) s.createQuery(query).setDate(0, GraphServlet.getStartDate())
                .setEntity(1, chapter).setEntity(2, chapter).list().get(0)).intValue();
        numPosts += numTypePosts;/*w w  w .  j  av  a 2 s  .  c  o m*/
        data.addValue(chapter.getShortname(), numTypePosts);
    }

    return getChapterPareto(data, "Posts by Chapter (for " + numPosts + " posts)", "Posts", "Number of Posts");

}

From source file:ca.myewb.frame.servlet.GraphServlet.java

private JFreeChart getChapterPie(Session s) {
    DefaultKeyedValues data = new DefaultKeyedValues();

    for (GroupChapterModel chapter : GroupChapterModel.getChapters()) {
        data.addValue(chapter.getShortname(), chapter.getNumMembers());
    }/*w  ww .  j  a  va 2  s . c  om*/

    return getChapterPareto(data, "Chapter Membership Breakdown By Chapter", "Membership", "Number of Members");
}