Example usage for org.jfree.data DefaultKeyedValues setValue

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

Introduction

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

Prototype

public void setValue(Comparable key, Number value) 

Source Link

Document

Updates an existing value, or adds a new value to the collection.

Usage

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

/**
 * Some checks for the clone() method.//  www.ja v  a2 s. c o  m
 */
@Test
public void testCloning() throws CloneNotSupportedException {
    DefaultKeyedValues v1 = new DefaultKeyedValues();
    v1.addValue("V1", new Integer(1));
    v1.addValue("V2", null);
    v1.addValue("V3", new Integer(3));
    DefaultKeyedValues v2 = (DefaultKeyedValues) v1.clone();
    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

/**
 * Some checks for the clone() method./*w ww.j  a  va  2  s  . c  om*/
 */
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.DefaultKeyedValuesTest.java

/**
 * Some checks for the clone() method.//  w w  w  .jav a  2 s  . c om
 */
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) {
        System.err.println("Failed to clone.");
    }
    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.DefaultKeyedValues2D.java

/**
 * Adds or updates a value./*from www . j  ava 2  s.  c o  m*/
 *
 * @param value  the value (<code>null</code> permitted).
 * @param rowKey  the row key (<code>null</code> not permitted).
 * @param columnKey  the column key (<code>null</code> not permitted).
 *
 * @see #addValue(Number, Comparable, Comparable)
 * @see #removeValue(Comparable, Comparable)
 */
public void setValue(Number value, Comparable rowKey, Comparable columnKey) {

    DefaultKeyedValues row;
    int rowIndex = getRowIndex(rowKey);

    if (rowIndex >= 0) {
        row = (DefaultKeyedValues) this.rows.get(rowIndex);
    } else {
        row = new DefaultKeyedValues();
        if (this.sortRowKeys) {
            rowIndex = -rowIndex - 1;
            this.rowKeys.add(rowIndex, rowKey);
            this.rows.add(rowIndex, row);
        } else {
            this.rowKeys.add(rowKey);
            this.rows.add(row);
        }
    }
    row.setValue(columnKey, value);

    int columnIndex = this.columnKeys.indexOf(columnKey);
    if (columnIndex < 0) {
        this.columnKeys.add(columnKey);
    }
}