diff options
author | 2021-08-15 00:20:56 +0200 | |
---|---|---|
committer | 2021-08-15 00:20:56 +0200 | |
commit | 66e213ea64f5c39d1da5e7e01a5cbf297f55afa6 (patch) | |
tree | 26d7197ab4526e0d88ad39127340ca4768216e28 /model-data | |
parent | renamed SymbolRepresentation to RelationRepresentation + added names (diff) | |
download | refinery-66e213ea64f5c39d1da5e7e01a5cbf297f55afa6.tar.gz refinery-66e213ea64f5c39d1da5e7e01a5cbf297f55afa6.tar.zst refinery-66e213ea64f5c39d1da5e7e01a5cbf297f55afa6.zip |
Added class for useful iterator functions (motivated by GUAVA)
Diffstat (limited to 'model-data')
-rw-r--r-- | model-data/src/main/java/org/eclipse/viatra/solver/data/util/CollectionsUtil.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/model-data/src/main/java/org/eclipse/viatra/solver/data/util/CollectionsUtil.java b/model-data/src/main/java/org/eclipse/viatra/solver/data/util/CollectionsUtil.java new file mode 100644 index 00000000..d950228d --- /dev/null +++ b/model-data/src/main/java/org/eclipse/viatra/solver/data/util/CollectionsUtil.java | |||
@@ -0,0 +1,29 @@ | |||
1 | package org.eclipse.viatra.solver.data.util; | ||
2 | |||
3 | import java.util.Iterator; | ||
4 | import java.util.function.Function; | ||
5 | |||
6 | public final class CollectionsUtil { | ||
7 | private CollectionsUtil() { | ||
8 | throw new UnsupportedOperationException(); | ||
9 | } | ||
10 | |||
11 | static <S,T> Iterator<T> map(Iterator<S> source, Function<S, T> transformation) { | ||
12 | return new Iterator<T>() { | ||
13 | |||
14 | @Override | ||
15 | public boolean hasNext() { | ||
16 | return source.hasNext(); | ||
17 | } | ||
18 | |||
19 | @Override | ||
20 | public T next() { | ||
21 | return transformation.apply(source.next()); | ||
22 | } | ||
23 | }; | ||
24 | } | ||
25 | |||
26 | static <S,T> Iterable<T> map(Iterable<S> source, Function<S, T> transformation) { | ||
27 | return (()->map(source.iterator(),transformation)); | ||
28 | } | ||
29 | } | ||