本文整理汇总了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);
}
示例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));
}
示例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);
}