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.DefaultKeyedValuesTest.java

/**
 * Some tests for the removeValue() method.
 *///from  w ww  .j  a va 2  s .  c om
@Test
public void testRemoveValue() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", null);
    data.addValue("C", new Double(3.0));
    data.addValue("D", new Double(2.0));
    assertEquals(1, data.getIndex("B"));
    data.removeValue("B");
    assertEquals(-1, data.getIndex("B"));

    boolean pass = false;
    try {
        data.removeValue("XXX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Adds or updates a value.//from   ww w.j a  v a  2s  . co 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);
    }
}

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

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

/**
 * Some tests for the removeValue() method.
 *///from   ww  w  . j a  v  a 2 s . co  m
public void testRemoveValue() {
    DefaultKeyedValues data = new DefaultKeyedValues();
    data.addValue("A", new Double(1.0));
    data.addValue("B", null);
    data.addValue("C", new Double(3.0));
    data.addValue("D", new Double(2.0));
    assertEquals(1, data.getIndex("B"));
    data.removeValue("B");
    assertEquals(-1, data.getIndex("B"));

    boolean pass = false;
    try {
        data.removeValue("XXX");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

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

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

/**
 * Tests sorting of data by key (descending).
 *///from w w  w . j  ava 2 s . co m
@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.junit.DefaultKeyedValuesTests.java

/**
 * Tests sorting of data by key (descending).
 *//*  w w w. ja  v  a 2  s  .  com*/
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.junit.DefaultKeyedValuesTest.java

/**
 * Tests sorting of data by key (descending).
 *//*from  w  w w  .  ja v a2  s. c  o 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));

}

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

/**
 * Tests sorting of data by value (ascending).
 *//*from ww  w  .  j  a  va2 s .  c om*/
@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);

}