6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.collections;
27
28 import com.sun.javafx.collections.NonIterableChange.SimplePermutationChange;
29 import com.sun.javafx.collections.ObservableListWrapper;
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Collections;
34 import java.util.Arrays;
35 import java.util.Comparator;
36 import java.util.Map;
37
38 import javafx.beans.Observable;
39 import javafx.beans.property.SimpleObjectProperty;
40 import javafx.collections.transformation.SortedList;
41 import javafx.collections.transformation.TransformationList;
42 import org.junit.Before;
43 import org.junit.Test;
44 import static org.junit.Assert.* ;
45 import static org.junit.Assert.assertEquals;
46
47 /**
48 *
49 */
50 public class SortedListTest {
51
52 private ObservableList<String> list;
53 private MockListObserver<String> mockListObserver;
54 private SortedList<String> sortedList;
55
56 @Before
57 public void setUp() {
58 list = FXCollections.observableArrayList();
59 list.addAll("a", "c", "d", "c");
281 @Test
282 public void testCompareNulls() {
283 ObservableList<String> list = FXCollections.observableArrayList( "g", "a", null, "z");
284
285 TransformationList<String, String> sorted = list.sorted();
286 assertEquals(Arrays.asList(null, "a", "g", "z"), sorted);
287 }
288
289
290 private static class Permutator<E> extends ObservableListWrapper<E> {
291 private List<E> backingList;
292 public Permutator(List<E> list) {
293 super(list);
294 this.backingList = list;
295 }
296
297 public void swap() {
298 E first = get(0);
299 backingList.set(0, get(size() - 1));
300 backingList.set(size() -1, first);
301 fireChange(new SimplePermutationChange(0, size(), new int[] {2, 1, 0}, this));
302 }
303
304 }
305 /**
306 * SortedList cant cope with permutations.
307 */
308 @Test
309 public void testPermutate() {
310 List<Integer> list = new ArrayList<Integer>();
311 for (int i = 0; i < 3; i++) {
312 list.add(i);
313 }
314 Permutator<Integer> permutator = new Permutator<Integer>(list);
315 SortedList<Integer> sorted = new SortedList<Integer>(permutator);
316 permutator.swap();
317 assertEquals(0, sorted.getSourceIndex(sorted.size() - 1));
318 }
319
320 @Test
321 public void testUnsorted() {
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package test.javafx.collections;
27
28 import test.javafx.collections.Person;
29 import test.javafx.collections.MockListObserver;
30 import com.sun.javafx.collections.NonIterableChange.SimplePermutationChange;
31 import com.sun.javafx.collections.ObservableListWrapper;
32 import java.util.ArrayList;
33 import java.util.HashMap;
34 import java.util.List;
35 import java.util.Collections;
36 import java.util.Arrays;
37 import java.util.Comparator;
38 import java.util.Map;
39
40 import javafx.beans.Observable;
41 import javafx.beans.property.SimpleObjectProperty;
42 import javafx.collections.FXCollections;
43 import javafx.collections.ListChangeListener;
44 import javafx.collections.ObservableList;
45 import javafx.collections.ObservableListWrapperShim;
46 import javafx.collections.transformation.SortedList;
47 import javafx.collections.transformation.TransformationList;
48 import org.junit.Before;
49 import org.junit.Test;
50 import static org.junit.Assert.* ;
51 import static org.junit.Assert.assertEquals;
52
53 /**
54 *
55 */
56 public class SortedListTest {
57
58 private ObservableList<String> list;
59 private MockListObserver<String> mockListObserver;
60 private SortedList<String> sortedList;
61
62 @Before
63 public void setUp() {
64 list = FXCollections.observableArrayList();
65 list.addAll("a", "c", "d", "c");
287 @Test
288 public void testCompareNulls() {
289 ObservableList<String> list = FXCollections.observableArrayList( "g", "a", null, "z");
290
291 TransformationList<String, String> sorted = list.sorted();
292 assertEquals(Arrays.asList(null, "a", "g", "z"), sorted);
293 }
294
295
296 private static class Permutator<E> extends ObservableListWrapper<E> {
297 private List<E> backingList;
298 public Permutator(List<E> list) {
299 super(list);
300 this.backingList = list;
301 }
302
303 public void swap() {
304 E first = get(0);
305 backingList.set(0, get(size() - 1));
306 backingList.set(size() -1, first);
307 ObservableListWrapperShim.fireChange(this,
308 new SimplePermutationChange(0, size(), new int[] {2, 1, 0}, this));
309 }
310
311 }
312 /**
313 * SortedList cant cope with permutations.
314 */
315 @Test
316 public void testPermutate() {
317 List<Integer> list = new ArrayList<Integer>();
318 for (int i = 0; i < 3; i++) {
319 list.add(i);
320 }
321 Permutator<Integer> permutator = new Permutator<Integer>(list);
322 SortedList<Integer> sorted = new SortedList<Integer>(permutator);
323 permutator.swap();
324 assertEquals(0, sorted.getSourceIndex(sorted.size() - 1));
325 }
326
327 @Test
328 public void testUnsorted() {
|