本文整理汇总了Java中org.jfree.data.KeyedObjects类的典型用法代码示例。如果您正苦于以下问题:Java KeyedObjects类的具体用法?Java KeyedObjects怎么用?Java KeyedObjects使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
KeyedObjects类属于org.jfree.data包,在下文中一共展示了KeyedObjects类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetIndex
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Simple checks for the getIndex(Comparable) method.
*/
public void testGetIndex() {
KeyedObjects ko1 = new KeyedObjects();
ko1.addObject("Key 1", "Object 1");
ko1.addObject("Key 2", null);
ko1.addObject("Key 3", "Object 2");
assertEquals(0, ko1.getIndex("Key 1"));
assertEquals(1, ko1.getIndex("Key 2"));
assertEquals(2, ko1.getIndex("Key 3"));
// check null argument
boolean pass = false;
try {
ko1.getIndex(null);
}
catch (IllegalArgumentException e) {
pass = true;
}
assertTrue(pass);
}
示例2: testInsertAndRetrieve
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Problem that inserting and retrieving values works as expected.
*/
public void testInsertAndRetrieve() {
final KeyedObjects data = new KeyedObjects();
data.addObject("A", new Double(1.0));
data.addObject("B", new Double(2.0));
data.addObject("C", new Double(3.0));
data.addObject("D", null);
// 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.getObject("A"), new Double(1.0));
assertEquals(data.getObject("B"), new Double(2.0));
assertEquals(data.getObject("C"), new Double(3.0));
assertEquals(data.getObject("D"), null);
assertEquals(data.getObject("Not a key"), null);
// 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);
}
示例3: testInsertAndRetrieve
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Check that inserting and retrieving values works as expected.
*/
public void testInsertAndRetrieve() {
KeyedObjects data = new KeyedObjects();
data.addObject("A", new Double(1.0));
data.addObject("B", new Double(2.0));
data.addObject("C", new Double(3.0));
data.addObject("D", null);
// 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.getObject("A"), new Double(1.0));
assertEquals(data.getObject("B"), new Double(2.0));
assertEquals(data.getObject("C"), new Double(3.0));
assertEquals(data.getObject("D"), null);
assertEquals(data.getObject("Not a key"), null);
// 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);
}
示例4: testInsertAndRetrieve
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Check that inserting and retrieving values works as expected.
*/
public void testInsertAndRetrieve() {
KeyedObjects data = new KeyedObjects();
data.addObject("A", new Double(1.0));
data.addObject("B", new Double(2.0));
data.addObject("C", new Double(3.0));
data.addObject("D", null);
// 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.getObject("A"), new Double(1.0));
assertEquals(data.getObject("B"), new Double(2.0));
assertEquals(data.getObject("C"), new Double(3.0));
assertEquals(data.getObject("D"), null);
boolean pass = false;
try {
data.getObject("Not a key");
}
catch (UnknownKeyException e) {
pass = true;
}
assertTrue(pass);
// 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);
}
示例5: testSetObject
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Some checks for the setObject(Comparable, Object) method.
*/
public void testSetObject() {
KeyedObjects ko1 = new KeyedObjects();
ko1.setObject("Key 1", "Object 1");
ko1.setObject("Key 2", null);
ko1.setObject("Key 3", "Object 2");
assertEquals("Object 1", ko1.getObject("Key 1"));
assertEquals(null, ko1.getObject("Key 2"));
assertEquals("Object 2", ko1.getObject("Key 3"));
// replace an existing value
ko1.setObject("Key 2", "AAA");
ko1.setObject("Key 3", "BBB");
assertEquals("AAA", ko1.getObject("Key 2"));
assertEquals("BBB", ko1.getObject("Key 3"));
// try a null key - should throw an exception
boolean pass = false;
try {
ko1.setObject(null, "XX");
}
catch (IllegalArgumentException e) {
pass = true;
}
assertTrue(pass);
}
示例6: testSortByKeyAscending
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Tests sorting of data by key (ascending).
*/
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));
}
示例7: testSortByKeyDescending
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Tests sorting of data by key (descending).
*/
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));
}
示例8: testSortByValueAscending
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Tests sorting of data by value (ascending).
*/
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);
}
示例9: testSortByValueDescending
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Tests sorting of data by key (descending).
*/
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);
}
示例10: DefaultPieDataset
import org.jfree.data.KeyedObjects; //导入依赖的package包/类
/**
* Creates a new dataset by copying data from a {@link KeyedValues}
* instance.
*
* @param data the data (<code>null</code> not permitted).
*/
public DefaultPieDataset(KeyedValues data) {
if (data == null) {
throw new IllegalArgumentException("Null 'data' argument.");
}
this.data = new KeyedObjects();
for (int i = 0; i < data.getItemCount(); i++) {
SelectableValue dataItem = new SelectableValue(data.getValue(i));
this.data.addObject(data.getKey(i), dataItem);
}
}