Example usage for org.jfree.data KeyedObjects KeyedObjects

List of usage examples for org.jfree.data KeyedObjects KeyedObjects

Introduction

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

Prototype

public KeyedObjects() 

Source Link

Document

Creates a new collection (initially empty).

Usage

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

/**
 * Some checks for the removeValue(int) method.
 *///from w  w  w.  j ava 2 s .c o  m
@Test
public void testRemoveValueInt() {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.setObject("Key 1", "Object 1");
    ko1.setObject("Key 2", null);
    ko1.setObject("Key 3", "Object 2");

    ko1.removeValue(1);
    assertEquals(2, ko1.getItemCount());
    assertEquals(1, ko1.getIndex("Key 3"));

    // try negative key index
    boolean pass = false;
    try {
        ko1.removeValue(-1);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);

    // try key index == itemCount
    pass = false;
    try {
        ko1.removeValue(2);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the removeValue() methods.
 *//*from w  ww  .  jav a2s  . c  om*/
public void testRemoveValue() {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.setObject("Key 1", "Object 1");
    ko1.setObject("Key 2", null);
    ko1.setObject("Key 3", "Object 2");

    ko1.removeValue(1);
    assertEquals(2, ko1.getItemCount());
    assertEquals(1, ko1.getIndex("Key 3"));

    ko1.removeValue("Key 1");
    assertEquals(1, ko1.getItemCount());
    assertEquals(0, ko1.getIndex("Key 3"));

    // try unknown key
    boolean pass = false;
    try {
        ko1.removeValue("UNKNOWN");
    } catch (UnknownKeyException e) {
        pass = true;
    }
    assertTrue(pass);

    // try null argument
    pass = false;
    try {
        ko1.removeValue(null);
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Some checks for the removeValue(int) method.
 *//* w w  w  .  j av  a 2 s. c  om*/
public void testRemoveValueInt() {
    KeyedObjects ko1 = new KeyedObjects();
    ko1.setObject("Key 1", "Object 1");
    ko1.setObject("Key 2", null);
    ko1.setObject("Key 3", "Object 2");

    ko1.removeValue(1);
    assertEquals(2, ko1.getItemCount());
    assertEquals(1, ko1.getIndex("Key 3"));

    // try negative key index
    boolean pass = false;
    try {
        ko1.removeValue(-1);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);

    // try key index == itemCount
    pass = false;
    try {
        ko1.removeValue(2);
    } catch (IndexOutOfBoundsException e) {
        pass = true;
    }
    assertTrue(pass);
}

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

/**
 * Tests sorting of data by key (ascending).
 *///from w  w w  .  j  a v a 2s . co m
public void testSortByKeyAscending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("A", new Double(2.0));

    data.sortByKeys(SortOrder.ASCENDING);

    // check key order
    assertEquals("A", data.getKey(0));
    assertEquals("B", data.getKey(1));
    assertEquals("C", data.getKey(2));
    assertEquals("D", data.getKey(3));

    // check retrieve value by key
    assertEquals(data.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(2.0));
    assertEquals(data.getObject(1), null);
    assertEquals(data.getObject(2), new Double(1.0));
    assertEquals(data.getObject(3), new Double(3.0));
}

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

/**
 * Tests sorting of data by key (descending).
 *//*  w w w  .  j  ava2 s.c  o m*/
public void testSortByKeyDescending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("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.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(3.0));
    assertEquals(data.getObject(1), new Double(1.0));
    assertEquals(data.getObject(2), null);
    assertEquals(data.getObject(3), new Double(2.0));
}

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

/**
 * Tests sorting of data by value (ascending).
 *///from   ww  w.java 2 s.c  o m
public void testSortByValueAscending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("A", new Double(2.0));

    data.sortByObjects(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.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(1.0));
    assertEquals(data.getObject(1), new Double(2.0));
    assertEquals(data.getObject(2), new Double(3.0));
    assertEquals(data.getObject(3), null);
}

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

/**
 * Tests sorting of data by key (descending).
 *//*from   www. ja v  a 2 s  . c  o  m*/
public void testSortByValueDescending() {
    KeyedObjects data = new KeyedObjects();
    data.addObject("C", new Double(1.0));
    data.addObject("B", null);
    data.addObject("D", new Double(3.0));
    data.addObject("A", new Double(2.0));

    data.sortByObjects(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.getObject("A"), new Double(2.0));
    assertEquals(data.getObject("B"), null);
    assertEquals(data.getObject("C"), new Double(1.0));
    assertEquals(data.getObject("D"), new Double(3.0));

    // check retrieve value by index
    assertEquals(data.getObject(0), new Double(3.0));
    assertEquals(data.getObject(1), new Double(2.0));
    assertEquals(data.getObject(2), new Double(1.0));
    assertEquals(data.getObject(3), null);
}