File tree Expand file tree Collapse file tree 2 files changed +26
-13
lines changed
src/main/java/org/apache/camel/component/dataprovider Expand file tree Collapse file tree 2 files changed +26
-13
lines changed Original file line number Diff line number Diff line change 1
1
package org .apache .camel .component .dataprovider ;
2
2
3
+ import com .google .common .collect .ImmutableList ;
3
4
import com .google .common .collect .Range ;
4
5
5
- import java .util .List ;
6
6
import java .util .concurrent .locks .Lock ;
7
7
import java .util .concurrent .locks .ReentrantReadWriteLock ;
8
8
@@ -21,19 +21,27 @@ public abstract class LazyDataProvider<T> implements IDataProvider<T> {
21
21
private final Lock readDataLock = dataLock .readLock ();
22
22
private final Lock writeDataLock = dataLock .writeLock ();
23
23
24
- private List <T > data ;
24
+ private ImmutableList <T > data ;
25
25
26
26
/**
27
27
* Tells how to load the data.
28
+ * <p>
29
+ * Internally will be converted into a {@link ImmutableList}.
30
+ * </p>
28
31
*
29
32
* @return the loaded data. Never <code>null</code> but could be <i>empty</i>.
30
33
*/
31
- public abstract List <T > loadData ();
34
+ public abstract Iterable <T > loadData ();
32
35
33
36
private void ensureDataLoaded () {
34
37
LockUtils .runWithLock (writeDataLock , () -> {
35
38
if (data == null ) {
36
- data = loadData ();
39
+ Iterable <T > data = loadData ();
40
+ if (data instanceof ImmutableList ) {
41
+ this .data = (ImmutableList <T >) data ;
42
+ } else {
43
+ this .data = ImmutableList .copyOf (data );
44
+ }
37
45
}
38
46
});
39
47
}
Original file line number Diff line number Diff line change 3
3
import com .google .common .collect .ImmutableList ;
4
4
import com .google .common .collect .Range ;
5
5
6
- import java .util .Arrays ;
7
- import java .util .Collection ;
8
- import java .util .List ;
9
-
10
6
/**
11
7
* {@link IDataProvider} implementation which already specifies all the data in the constructor.
12
8
*
13
9
* @author <a href="mailto:christian.ribeaud@novartis.com">Christian Ribeaud</a>
14
10
*/
15
11
public class StaticDataProvider <T > implements IDataProvider <T > {
16
12
17
- private final List <T > data ;
13
+ // Immutable list is expected here
14
+ private final ImmutableList <T > data ;
18
15
19
16
public StaticDataProvider (T ... data ) {
20
- this (Arrays . asList (data ));
17
+ this (ImmutableList . copyOf (data ));
21
18
}
22
19
23
- public StaticDataProvider (Collection <T > data ) {
20
+ /**
21
+ * Constructor with provided {@link Iterable} <i>data</i>.
22
+ * <p>
23
+ * Internally will be converted into a {@link ImmutableList}.
24
+ * </p>
25
+ *
26
+ * @param data the {@link Iterable} data. Can NOT be <code>null</code>.
27
+ */
28
+ public StaticDataProvider (Iterable <T > data ) {
24
29
assert data != null : "Unspecified data" ;
25
- if (data instanceof List == false ) {
30
+ if (data instanceof ImmutableList == false ) {
26
31
this .data = ImmutableList .copyOf (data );
27
32
} else {
28
- this .data = (( List <T >) data ) ;
33
+ this .data = (ImmutableList <T >) data ;
29
34
}
30
35
}
31
36
You can’t perform that action at this time.
0 commit comments