-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Internally work with 'ImmutableList' instead of plain 'List'
- Loading branch information
ribeach1
committed
Jul 5, 2018
1 parent
6b729b7
commit b4ac574
Showing
2 changed files
with
26 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,29 +3,34 @@ | |
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.Range; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
/** | ||
* {@link IDataProvider} implementation which already specifies all the data in the constructor. | ||
* | ||
* @author <a href="mailto:[email protected]">Christian Ribeaud</a> | ||
*/ | ||
public class StaticDataProvider<T> implements IDataProvider<T> { | ||
|
||
private final List<T> data; | ||
// Immutable list is expected here | ||
private final ImmutableList<T> data; | ||
|
||
public StaticDataProvider(T... data) { | ||
this(Arrays.asList(data)); | ||
this(ImmutableList.copyOf(data)); | ||
} | ||
|
||
public StaticDataProvider(Collection<T> data) { | ||
/** | ||
* Constructor with provided {@link Iterable} <i>data</i>. | ||
* <p> | ||
* Internally will be converted into a {@link ImmutableList}. | ||
* </p> | ||
* | ||
* @param data the {@link Iterable} data. Can NOT be <code>null</code>. | ||
*/ | ||
public StaticDataProvider(Iterable<T> data) { | ||
assert data != null : "Unspecified data"; | ||
if (data instanceof List == false) { | ||
if (data instanceof ImmutableList == false) { | ||
this.data = ImmutableList.copyOf(data); | ||
} else { | ||
this.data = ((List<T>) data); | ||
this.data = (ImmutableList<T>) data; | ||
} | ||
} | ||
|
||
|