GriffonFXCollectionsExtension.groovy
01 /*
02  * SPDX-License-Identifier: Apache-2.0
03  *
04  * Copyright 2008-2017 the original author or authors.
05  *
06  * Licensed under the Apache License, Version 2.0 (the "License");
07  * you may not use this file except in compliance with the License.
08  * You may obtain a copy of the License at
09  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 package griffon.javafx
19 
20 import griffon.javafx.collections.GriffonFXCollections
21 import griffon.javafx.collections.MappingObservableList
22 import groovy.transform.CompileStatic
23 import javafx.beans.value.ObservableValue
24 import javafx.collections.ObservableList
25 import javafx.collections.ObservableMap
26 import javafx.collections.ObservableSet
27 
28 import javax.annotation.Nonnull
29 import java.util.function.Function
30 
31 /**
32  @author Andres Almiray
33  @since 2.13.0
34  */
35 @CompileStatic
36 final class GriffonFXCollectionsExtension {
37     @Nonnull
38     static <T> ObservableList<T> uiThreadAware(@Nonnull ObservableList<T> self) {
39         return GriffonFXCollections.uiThreadAwareObservableList(self)
40     }
41 
42     @Nonnull
43     static <T> ObservableSet<T> uiThreadAware(@Nonnull ObservableSet<T> self) {
44         return GriffonFXCollections.uiThreadAwareObservableSet(self)
45     }
46 
47     @Nonnull
48     static <K, V> ObservableMap<K, V> uiThreadAware(@Nonnull ObservableMap<K, V> self) {
49         return GriffonFXCollections.uiThreadAwareObservableMap(self)
50     }
51 
52     @Nonnull
53     static <T, S> ObservableList<T> mappedWith(@Nonnull ObservableList<S> self, @Nonnull Function<S, T> mapper) {
54         new MappingObservableList<T, S>(self, mapper)
55     }
56 
57     @Nonnull
58     static <T, S> ObservableList<T> mappedWith(
59         @Nonnull ObservableList<S> self, @Nonnull ObservableValue<Function<S, T>> mapper) {
60         new MappingObservableList<T, S>(self, mapper)
61     }
62 }