Skip to content

Commit

Permalink
[refactor] moved Enumerator#to_java.stream support into Java
Browse files Browse the repository at this point in the history
... since we're now compiling (JRuby 9.2) against Java 8
  • Loading branch information
kares committed May 18, 2018
1 parent d1a0bbf commit 0a2bede
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 22 deletions.
24 changes: 24 additions & 0 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Expand Up @@ -46,8 +46,10 @@
import org.jruby.util.cli.Options;

import java.util.Arrays;
import java.util.Spliterator;
import java.util.concurrent.Future;
import java.util.concurrent.SynchronousQueue;
import java.util.stream.Stream;

import static org.jruby.runtime.Visibility.PRIVATE;

Expand Down Expand Up @@ -609,6 +611,28 @@ public void remove() {
throw new UnsupportedOperationException();
}

// Java 8 stream support :

public Stream<Object> stream() {
return stream(false);
}

public Stream<Object> stream(final boolean parallel) {
return java.util.stream.StreamSupport.stream(spliterator(), parallel);
}

public Spliterator<Object> spliterator() {
final long size = size();
// we do not have ArrayNexter detection - assume immutable
int mod = java.util.Spliterator.IMMUTABLE;
if (size >= 0) mod |= java.util.Spliterator.SIZED;
return java.util.Spliterators.spliterator(this, size, mod);
}

public Spliterator<Object> spliterator(final int mod) {
return java.util.Spliterators.spliterator(this, size(), mod);
}

/**
* "Function" type for java-created enumerators with size. Should be implemented so that calls to
* SizeFn#size are kept in sync with the size of the created enum (i.e. if the object underlying an enumerator
Expand Down
1 change: 0 additions & 1 deletion core/src/main/ruby/jruby/java.rb
Expand Up @@ -38,4 +38,3 @@

load 'jruby/java/core_ext.rb'
load 'jruby/java/java_ext.rb'
load 'jruby/java/java_8.rb' if java.util.Spliterator rescue nil
1 change: 0 additions & 1 deletion core/src/main/ruby/jruby/java/core_ext.rb
Expand Up @@ -3,4 +3,3 @@
# These are loads so they don't pollute LOADED_FEATURES
load 'jruby/java/core_ext/module.rb'
load 'jruby/java/core_ext/object.rb'
#load 'jruby/java/core_ext/kernel.rb' - moved to org.jruby.javasupport.ext.Kernel
2 changes: 1 addition & 1 deletion core/src/main/ruby/jruby/java/core_ext/kernel.rb
Expand Up @@ -33,4 +33,4 @@ def com
def org
JavaUtilities.get_package_module_dot_format('org') # stub
end
end if false
end if false # only here for doc -> implementation at org.jruby.javasupport.ext.Kernel
19 changes: 0 additions & 19 deletions core/src/main/ruby/jruby/java/java_8.rb

This file was deleted.

1 change: 1 addition & 0 deletions test/jruby.index
Expand Up @@ -27,6 +27,7 @@ jruby/test_dir_with_jar_without_dir_entry
jruby/test_digest_extend
jruby/test_digest2
jruby/test_env
jruby/test_enumerator
jruby/test_etc
jruby/test_exception
jruby/test_file
Expand Down

0 comments on commit 0a2bede

Please sign in to comment.