Example usage for org.jfree.data DefaultKeyedValues getValue

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

Introduction

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

Prototype

@Override
public Number getValue(Comparable key) 

Source Link

Document

Returns the value for a given key.

Usage

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

/**
 * Returns the value for a given row and column.
 *
 * @param row  the row index./*  w  ww  . j  a va2  s .co m*/
 * @param column  the column index.
 *
 * @return The value.
 *
 * @see #getValue(Comparable, Comparable)
 */
@Override
public Number getValue(int row, int column) {
    Number result = null;
    DefaultKeyedValues rowData = (DefaultKeyedValues) this.rows.get(row);
    if (rowData != null) {
        Comparable columnKey = (Comparable) this.columnKeys.get(column);
        // the row may not have an entry for this key, in which case the
        // return value is null
        int index = rowData.getIndex(columnKey);
        if (index >= 0) {
            result = rowData.getValue(index);
        }
    }
    return result;
}

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

/**
 * Check that inserting and retrieving values works as expected.
 *///from   w  ww.  j  a  v a 2 s . c  o m
@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.
 *//* w w  w.  ja  v  a 2s  .c o m*/
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  ww w.j a v a2s  . 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.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (ascending).
 *///from   w w w  .  j a v a  2  s  . c  om
@Test
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.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (descending).
 *//*  w w  w . j  a  v a2 s .c  om*/
@Test
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.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by value (ascending).
 *//* ww w . j a  v  a2 s . co 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).
 *//*  www .ja  v a  2  s  .com*/
@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 (ascending).
 *//*from   www  . j  a  v  a2s. co  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).
 *///from  ww  w . j a  va 2s . co  m
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));
}