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 11package org .apache .camel .component .dataprovider ;
22
3+ import com .google .common .collect .ImmutableList ;
34import com .google .common .collect .Range ;
45
5- import java .util .List ;
66import java .util .concurrent .locks .Lock ;
77import java .util .concurrent .locks .ReentrantReadWriteLock ;
88
@@ -21,19 +21,27 @@ public abstract class LazyDataProvider<T> implements IDataProvider<T> {
2121 private final Lock readDataLock = dataLock .readLock ();
2222 private final Lock writeDataLock = dataLock .writeLock ();
2323
24- private List <T > data ;
24+ private ImmutableList <T > data ;
2525
2626 /**
2727 * Tells how to load the data.
28+ * <p>
29+ * Internally will be converted into a {@link ImmutableList}.
30+ * </p>
2831 *
2932 * @return the loaded data. Never <code>null</code> but could be <i>empty</i>.
3033 */
31- public abstract List <T > loadData ();
34+ public abstract Iterable <T > loadData ();
3235
3336 private void ensureDataLoaded () {
3437 LockUtils .runWithLock (writeDataLock , () -> {
3538 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+ }
3745 }
3846 });
3947 }
Original file line number Diff line number Diff line change 33import com .google .common .collect .ImmutableList ;
44import com .google .common .collect .Range ;
55
6- import java .util .Arrays ;
7- import java .util .Collection ;
8- import java .util .List ;
9-
106/**
117 * {@link IDataProvider} implementation which already specifies all the data in the constructor.
128 *
139 * @author <a href="mailto:christian.ribeaud@novartis.com">Christian Ribeaud</a>
1410 */
1511public class StaticDataProvider <T > implements IDataProvider <T > {
1612
17- private final List <T > data ;
13+ // Immutable list is expected here
14+ private final ImmutableList <T > data ;
1815
1916 public StaticDataProvider (T ... data ) {
20- this (Arrays . asList (data ));
17+ this (ImmutableList . copyOf (data ));
2118 }
2219
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 ) {
2429 assert data != null : "Unspecified data" ;
25- if (data instanceof List == false ) {
30+ if (data instanceof ImmutableList == false ) {
2631 this .data = ImmutableList .copyOf (data );
2732 } else {
28- this .data = (( List <T >) data ) ;
33+ this .data = (ImmutableList <T >) data ;
2934 }
3035 }
3136
You can’t perform that action at this time.
0 commit comments