jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject [01/34] jena git commit: Simpify Iter.toList, Iter.toSet.
Date Sat, 06 Feb 2016 15:50:50 GMT
Repository: jena
Updated Branches:
  refs/heads/master f41d74ab3 -> 666e79bf0


Simpify Iter.toList, Iter.toSet.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/23a2d012
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/23a2d012
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/23a2d012

Branch: refs/heads/master
Commit: 23a2d01279861c0a35d4db1f6341e4daeefc7ef5
Parents: f41d74a
Author: Andy Seaborne <andy@apache.org>
Authored: Wed Feb 3 09:14:32 2016 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed Feb 3 09:14:32 2016 +0000

----------------------------------------------------------------------
 .../org/apache/jena/atlas/iterator/Iter.java    | 57 +++++---------------
 1 file changed, 12 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/23a2d012/jena-base/src/main/java/org/apache/jena/atlas/iterator/Iter.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/iterator/Iter.java b/jena-base/src/main/java/org/apache/jena/atlas/iterator/Iter.java
index 99c71c3..d64896c 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/iterator/Iter.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/iterator/Iter.java
@@ -85,56 +85,23 @@ public class Iter<T> implements Iterator<T> {
     
     // ---- Collectors.
     
+    /** Collect an iterator into a set. */
     public static <T> Set<T> toSet(Iterator<? extends T> stream) {
-        Accumulate<T, Set<T>> action = new Accumulate<T, Set<T>>()
{
-            private Set<T> acc = null ;
-
-            @Override
-            public void accumulate(T item) {
-                acc.add(item) ;
-            }
-
-            @Override
-            public Set<T> get() {
-                return acc ;
-            }
-
-            @Override
-            public void start() {
-                acc = new HashSet<>() ;
-            }
-
-            @Override
-            public void finish() {}
-        } ;
-        return reduce(stream, action) ;
+        Set<T> acc = new HashSet<>() ;
+        collect(acc, stream) ;
+        return acc ;
     }
-
-    
     
+    /** Collect an iterator into a list. */
     public static <T> List<T> toList(Iterator<? extends T> stream) {
-        Accumulate<T, List<T>> action = new Accumulate<T, List<T>>()
{
-            private List<T> acc = null ;
-
-            @Override
-            public void accumulate(T item) {
-                acc.add(item) ;
-            }
-
-            @Override
-            public List<T> get() {
-                return acc ;
-            }
-
-            @Override
-            public void start() {
-                acc = new ArrayList<>() ;
-            }
+        List<T> acc = new ArrayList<>() ;
+        collect(acc, stream) ;
+        return acc ;
+    }
 
-            @Override
-            public void finish() {}
-        } ;
-        return reduce(stream, action) ;
+    /** Collect an iterator. */
+    private static <T> void collect(Collection<T> acc, Iterator<? extends
T> stream) {
+        stream.forEachRemaining((x)->acc.add(x)) ;
     }
 
     /**


Mime
View raw message