當前位置: 首頁>>代碼示例>>Java>>正文


Java ObservableList.sort方法代碼示例

本文整理匯總了Java中javafx.collections.ObservableList.sort方法的典型用法代碼示例。如果您正苦於以下問題:Java ObservableList.sort方法的具體用法?Java ObservableList.sort怎麽用?Java ObservableList.sort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.collections.ObservableList的用法示例。


在下文中一共展示了ObservableList.sort方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: showUkeire

import javafx.collections.ObservableList; //導入方法依賴的package包/類
public void showUkeire(MahjongScene scene) {
    ObservableList<Ukeire> list = FXCollections.observableArrayList();
    int[] hais = new int[34];
    int naki = scene.naki.get(scene.heroPosition).size();
    Set<Integer> set = new TreeSet<>();
    for (int hai : scene.tehaiSets.get(scene.heroPosition)) {
        hais[hai / 4]++;
        set.add(hai / 4);
    }
    if (scene.tsumo[scene.heroPosition] != -1) {
        hais[scene.tsumo[scene.heroPosition] / 4]++;
        set.add(scene.tsumo[scene.heroPosition] / 4);
    }
    for (int candidate : set) {
        hais[candidate]--;
        int syanten = MahjongUtils.computeSyanten(hais, naki);
        hais[candidate]++;
        list.add(new Ukeire(candidate, new ArrayList<>(), 0, syanten));
    }
    list.sort((u1, u2) -> u1.getSyanten() != u2.getSyanten() ?
            u1.getSyanten() - u2.getSyanten() : u1.getSum() - u2.getSum());
    setItems(list);
}
 
開發者ID:CrazyBBB,項目名稱:tenhou-visualizer,代碼行數:24,代碼來源:UkeireTableView.java

示例2: permuteElementsTest

import javafx.collections.ObservableList; //導入方法依賴的package包/類
@Test
public void permuteElementsTest()
{
    final ObservableList<Integer> list1 = FXCollections.observableArrayList(1, 2, 0);
    final ObservableList<Integer> list2 = FXCollections.observableArrayList(3);
    final ObservableList<Integer> list3 = FXCollections.observableArrayList(4, 5);

    final ObservableListAggregation<Integer> listAggregation = new ObservableListAggregation<>(list1, list2, list3);
    final AtomicReference<Change<? extends Integer>> change = new AtomicReference<>(null);
    listAggregation.addListener((ListChangeListener<Integer>) c -> {
        change.set(c);
    });

    list1.sort(Integer::compareTo);

    assertNotNull("Change event", change.get());
    assertTrue("Has change", change.get().next());
    assertFalse("Was added", change.get().wasAdded());
    assertFalse("Was removed", change.get().wasRemoved());
    assertFalse("Was update", change.get().wasUpdated());
    assertTrue("Was permuted", change.get().wasPermutated());
    assertEquals("from", 0, change.get().getFrom());
    assertEquals("to", 3, change.get().getTo());
    assertEquals("permitation(0)", 1, change.get().getPermutation(0));
    assertEquals("permitation(1)", 2, change.get().getPermutation(1));
    assertEquals("permitation(2)", 0, change.get().getPermutation(2));
    assertFalse("Has more change", change.get().next());

    assertEquals("size", 6, listAggregation.size());
    assertEquals("get(0)", Integer.valueOf(0), listAggregation.get(0));
    assertEquals("get(1)", Integer.valueOf(1), listAggregation.get(1));
    assertEquals("get(2)", Integer.valueOf(2), listAggregation.get(2));
    assertEquals("get(3)", Integer.valueOf(3), listAggregation.get(3));
    assertEquals("get(4)", Integer.valueOf(4), listAggregation.get(4));
    assertEquals("get(5)", Integer.valueOf(5), listAggregation.get(5));
}
 
開發者ID:ben12,項目名稱:infxnity,代碼行數:37,代碼來源:ObservableListAggregationTest.java

示例3: permuteElementsTest

import javafx.collections.ObservableList; //導入方法依賴的package包/類
@Test
public void permuteElementsTest()
{
    final ObservableList<Model> collection1 = FXCollections.observableArrayList(new Model("value2"),
                                                                                new Model("value4"),
                                                                                new Model("value1"),
                                                                                new Model("value3"));
    final ObservableList<String> collection2 = FXCollections.observableArrayList();

    IFXContentBinding.bind(collection2, collection1, Model::getText);

    // Permutation can be generated only by calling sort, so IFXContentBinding generate a remove then an add

    final List<ListChangeListener.Change<? extends String>> change = new ArrayList<>(2);
    collection2.addListener((ListChangeListener<String>) c -> {
        if (change.isEmpty())
        {
            assertEquals(Collections.emptyList(), collection2);
        }
        change.add(c);
    });

    collection1.sort(Comparator.comparing(Model::getText));

    assertEquals("Change event", 2, change.size());

    assertTrue("Has change", change.get(0).next());
    assertFalse("Was added", change.get(0).wasAdded());
    assertTrue("Was removed", change.get(0).wasRemoved());
    assertFalse("Was update", change.get(0).wasUpdated());
    assertFalse("Was permuted", change.get(0).wasPermutated());
    assertEquals("from", 0, change.get(0).getFrom());
    assertEquals("to", 0, change.get(0).getTo());
    assertEquals("Removed", Arrays.asList("value2", "value4", "value1", "value3"), change.get(0).getRemoved());
    assertFalse("Has more change", change.get(0).next());

    assertTrue("Has change", change.get(1).next());
    assertTrue("Was added", change.get(1).wasAdded());
    assertFalse("Was removed", change.get(1).wasRemoved());
    assertFalse("Was update", change.get(1).wasUpdated());
    assertFalse("Was permuted", change.get(1).wasPermutated());
    assertEquals("from", 0, change.get(1).getFrom());
    assertEquals("to", 4, change.get(1).getTo());
    assertEquals("Added sub-list", Arrays.asList("value1", "value2", "value3", "value4"),
                 change.get(1).getAddedSubList());
    assertFalse("Has more change", change.get(1).next());

    assertEquals(Arrays.asList("value1", "value2", "value3", "value4"), collection2);
}
 
開發者ID:ben12,項目名稱:infxnity,代碼行數:50,代碼來源:IFXContentBindingTest.java


注:本文中的javafx.collections.ObservableList.sort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。