当前位置: 首页>>代码示例>>Java>>正文


Java KeyedObjects.sortByKeys方法代码示例

本文整理汇总了Java中org.jfree.data.KeyedObjects.sortByKeys方法的典型用法代码示例。如果您正苦于以下问题:Java KeyedObjects.sortByKeys方法的具体用法?Java KeyedObjects.sortByKeys怎么用?Java KeyedObjects.sortByKeys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jfree.data.KeyedObjects的用法示例。


在下文中一共展示了KeyedObjects.sortByKeys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:KeyedObjectsTests.java

示例2: 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));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:KeyedObjectsTests.java


注:本文中的org.jfree.data.KeyedObjects.sortByKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。