Example usage for org.jfree.data DefaultKeyedValues insertValue

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

Introduction

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

Prototype

public void insertValue(int position, Comparable key, Number value) 

Source Link

Document

Inserts a new value at the specified position in the dataset or, if there is an existing item with the specified key, updates the value for that item and moves it to the specified position.

Usage

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

/**
 * Some checks for the insertValue() method.
 */// w ww.ja v  a  2 s .c om
@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.junit.DefaultKeyedValuesTest.java

/**
 * Some checks for the insertValue() method.
 *//* w  w  w .j av  a 2 s .c o m*/
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));
}