Example usage for org.jfree.data DefaultKeyedValues2D getValue

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

Introduction

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

Prototype

@Override
public Number getValue(Comparable rowKey, Comparable columnKey) 

Source Link

Document

Returns the value for the given row and column keys.

Usage

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

/**
 * Some basic checks for the getValue(int, int) method.
 */// ww w .  j a  va  2s  .c o  m
@Test
public void testGetValue2() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    boolean pass = false;
    try {
        d.getValue(0, 0);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);
    d.addValue(new Double(1.0), "R1", "C1");
    assertEquals(1.0, d.getValue(0, 0).doubleValue(), EPSILON);
    d.addValue(new Double(2.0), "R2", "C2");
    assertEquals(2.0, d.getValue(1, 1).doubleValue(), EPSILON);
    assertNull(d.getValue(1, 0));
    assertNull(d.getValue(0, 1));

    pass = false;
    try {
        d.getValue(2, 0);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the getValue() method.
 *//*from w w w .  ja v  a  2  s.  c o m*/
@Test
public void testGetValue() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    d.addValue(new Double(1.0), "R1", "C1");
    assertEquals(new Double(1.0), d.getValue("R1", "C1"));
    boolean pass = false;
    try {
        d.getValue("XX", "C1");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    pass = false;
    try {
        d.getValue("R1", "XX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Populates a data structure with sparse entries, then checks that
 * the unspecified entries return null./*from w w w  . j  a  v  a  2s . co m*/
 */
@Test
public void testSparsePopulation() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    d.addValue(new Integer(11), "R1", "C1");
    d.addValue(new Integer(22), "R2", "C2");

    assertEquals(new Integer(11), d.getValue("R1", "C1"));
    assertNull(d.getValue("R1", "C2"));
    assertEquals(new Integer(22), d.getValue("R2", "C2"));
    assertNull(d.getValue("R2", "C1"));
}

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

/**
 * Some basic checks for the removeColumn(Comparable) method.
 *//* ww w.  j  a  v  a2  s.  c  o m*/
@Test
public void testRemoveColumnByKey() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    d.addValue(new Double(1.0), "R1", "C1");
    d.addValue(new Double(2.0), "R2", "C2");
    d.removeColumn("C2");
    d.addValue(new Double(3.0), "R2", "C2");
    assertEquals(3.0, d.getValue("R2", "C2").doubleValue(), EPSILON);

    // check for unknown column
    boolean pass = false;
    try {
        d.removeColumn("XXX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * A test for bug 1690654./* w ww  . j a v  a 2 s .c o m*/
 */
@Test
public void testRemoveValueBug1690654() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    d.addValue(new Double(1.0), "R1", "C1");
    d.addValue(new Double(2.0), "R2", "C2");
    assertEquals(2, d.getColumnCount());
    assertEquals(2, d.getRowCount());
    d.removeValue("R2", "C2");
    assertEquals(1, d.getColumnCount());
    assertEquals(1, d.getRowCount());
    assertEquals(new Double(1.0), d.getValue(0, 0));
}

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

/**
 * Some basic checks for the removeValue() method.
 *//*  ww w.  j  a v  a2  s  .  c  o  m*/
@Test
public void testRemoveValue() {
    DefaultKeyedValues2D d = new DefaultKeyedValues2D();
    d.removeValue("R1", "C1");
    d.addValue(new Double(1.0), "R1", "C1");
    d.removeValue("R1", "C1");
    assertEquals(0, d.getRowCount());
    assertEquals(0, d.getColumnCount());

    d.addValue(new Double(1.0), "R1", "C1");
    d.addValue(new Double(2.0), "R2", "C1");
    d.removeValue("R1", "C1");
    assertEquals(new Double(2.0), d.getValue(0, 0));
}