Skip to content

Fix compile under jdk11. Enable jdk11 travis build. #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ sudo: false
language: java

jdk:
- oraclejdk8
- openjdk11

matrix:

include:
- jdk: openjdk8
script:
- ./gradlew build coverage -s -i
after_success:
- bash <(curl -s https://codecov.io/bash)
- '[ "$TRAVIS_BRANCH" = "series/4.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ]
&& ./gradlew uploadArchives'

script:
- jdk_switcher use openjdk7 && export JAVA7_HOME=$JAVA_HOME
- jdk_switcher use oraclejdk8 && export JAVA8_HOME=$JAVA_HOME
- ./gradlew build coverage -s -i
- ./gradlew clean test

after_success:
- bash <(curl -s https://codecov.io/bash)
- '[ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ]
&& ./gradlew uploadArchives'

env:
global:
Expand Down
13 changes: 6 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ buildscript {
}
}

apply plugin: "jacoco"

if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
Expand All @@ -35,11 +33,10 @@ if (JavaVersion.current().isJava8Compatible()) {

allprojects {


apply plugin: "jacoco"

jacoco {
toolVersion = "0.8.1"

toolVersion = "0.8.2"
}

defaultTasks "build"
Expand Down Expand Up @@ -100,8 +97,6 @@ subprojects {
}
}

apply plugin: "jacoco"

apply from: "$rootDir/lib.gradle"
apply plugin: "java"
apply plugin: "eclipse"
Expand All @@ -123,9 +118,13 @@ subprojects {
}

jacocoTestReport {
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
classDirectories = files(sourceSets.main.output)
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}

Expand Down
6 changes: 0 additions & 6 deletions core/src/main/java/fj/data/$.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ public final class $<A, B> extends P1<B> {

/**
* Returns a function that given an argument, returns a function that ignores its argument.
* @deprecated JDK 8 warns '_' may not be supported after SE 8. As of release 4.4, use {@link #constant} (note the synonym {@link #__}).
* @return A function that given an argument, returns a function that ignores its argument.
*/
@Deprecated
public static <A, B> $<A, B> _(final B b) {
return constant(b);
}

public static <A, B> $<A, B> __(final B b) {
return constant(b);
}
Expand Down
234 changes: 121 additions & 113 deletions core/src/main/java/fj/data/IOFunctions.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package fj.data;

import static fj.Bottom.errorF;
import static fj.Function.constant;
import static fj.Function.partialApply2;
import fj.F;
import fj.F0;
import fj.F1Functions;
import fj.F2;
import fj.Function;
import fj.P;
import fj.P1;
import fj.P2;
import fj.Try;
import fj.Unit;
import fj.data.Iteratee.Input;
import fj.data.Iteratee.IterV;
import fj.function.Try0;
import fj.function.Try1;

import java.io.BufferedReader;
import java.io.Closeable;
Expand All @@ -14,11 +25,9 @@
import java.nio.charset.Charset;
import java.util.Arrays;

import fj.*;
import fj.data.Iteratee.Input;
import fj.data.Iteratee.IterV;
import fj.function.Try0;
import fj.function.Try1;
import static fj.Bottom.errorF;
import static fj.Function.constant;
import static fj.Function.partialApply2;

/**
* IO monad for processing files, with main methods {@link #enumFileLines },
Expand Down Expand Up @@ -170,130 +179,129 @@ public static <A> SafeIO<A> lazySafe(final F0<A> f) {
* A function that feeds an iteratee with lines read from a {@link BufferedReader}.
*/
public static <A> F<BufferedReader, F<IterV<String, A>, IO<IterV<String, A>>>> lineReader() {
final F<IterV<String, A>, Boolean> isDone =
new F<Iteratee.IterV<String, A>, Boolean>() {
final F<P2<A, Input<String>>, P1<Boolean>> done = constant(P.p(true));
final F<F<Input<String>, IterV<String, A>>, P1<Boolean>> cont = constant(P.p(false));

@Override
public Boolean f(final IterV<String, A> i) {
return i.fold(done, cont)._1();
}
};

return r -> new F<IterV<String, A>, IO<IterV<String, A>>>() {
final F<P2<A, Input<String>>, P1<IterV<String, A>>> done = errorF("iteratee is done"); //$NON-NLS-1$

@Override
public IO<IterV<String, A>> f(final IterV<String, A> it) {
// use loop instead of recursion because of missing TCO
return () -> {
IterV<String, A> i = it;
while (!isDone.f(i)) {
final String s = r.readLine();
if (s == null) {
return i;
}
final Input<String> input = Input.el(s);
final F<F<Input<String>, IterV<String, A>>, P1<IterV<String, A>>> cont = F1Functions.lazy(Function.apply(input));
i = i.fold(done, cont)._1();
return LineReader::new;
}

private static class LineReader<A> implements F<IterV<String, A>, IO<IterV<String, A>>> {

private final BufferedReader r;

private final F<IterV<String, A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
private final F<P2<A, Input<String>>, P1<IterV<String, A>>> done = errorF("iteratee is done"); //$NON-NLS-1$

private LineReader(BufferedReader r) {
this.r = r;
}

@Override
public IO<IterV<String, A>> f(IterV<String, A> it) {
// use loop instead of recursion because of missing TCO
return () -> {
IterV<String, A> i = it;
while (!isDone.f(i)) {
final String s = r.readLine();
if (s == null) {
return i;
}
return i;
};
}
};
final Input<String> input = Input.el(s);
final F<F<Input<String>, IterV<String, A>>, P1<IterV<String, A>>> cont = F1Functions.lazy(Function.apply(input));
i = i.fold(done, cont)._1();
}
return i;
};
}
}

/**
* A function that feeds an iteratee with character chunks read from a {@link Reader}
* (char[] of size {@link #DEFAULT_BUFFER_SIZE}).
*/
public static <A> F<Reader, F<IterV<char[], A>, IO<IterV<char[], A>>>> charChunkReader() {
final F<IterV<char[], A>, Boolean> isDone =
new F<Iteratee.IterV<char[], A>, Boolean>() {
final F<P2<A, Input<char[]>>, P1<Boolean>> done = constant(P.p(true));
final F<F<Input<char[]>, IterV<char[], A>>, P1<Boolean>> cont = constant(P.p(false));

@Override
public Boolean f(final IterV<char[], A> i) {
return i.fold(done, cont)._1();
return CharChunkReader::new;
}

private static class CharChunkReader<A> implements F<IterV<char[], A>, IO<IterV<char[], A>>> {

private final Reader r;

private final F<IterV<char[], A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
private final F<P2<A, Input<char[]>>, P1<IterV<char[], A>>> done = errorF("iteratee is done"); //$NON-NLS-1$

CharChunkReader(Reader r) {
this.r = r;
}

@Override
public IO<IterV<char[], A>> f(IterV<char[], A> it) {
// use loop instead of recursion because of missing TCO
return () -> {

IterV<char[], A> i = it;
while (!isDone.f(i)) {
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
final int numRead = r.read(buffer);
if (numRead == -1) {
return i;
}
};

return r -> new F<IterV<char[], A>, IO<IterV<char[], A>>>() {
final F<P2<A, Input<char[]>>, P1<IterV<char[], A>>> done = errorF("iteratee is done"); //$NON-NLS-1$

@Override
public IO<IterV<char[], A>> f(final IterV<char[], A> it) {
// use loop instead of recursion because of missing TCO
return () -> {

IterV<char[], A> i = it;
while (!isDone.f(i)) {
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
final int numRead = r.read(buffer);
if (numRead == -1) {
return i;
}
if (numRead < buffer.length) {
buffer = Arrays.copyOfRange(buffer, 0, numRead);
}
final Input<char[]> input = Input.el(buffer);
final F<F<Input<char[]>, IterV<char[], A>>, P1<IterV<char[], A>>> cont =
F1Functions.lazy(Function.apply(input));
i = i.fold(done, cont)._1();
if (numRead < buffer.length) {
buffer = Arrays.copyOfRange(buffer, 0, numRead);
}
return i;
};
}
};
final Input<char[]> input = Input.el(buffer);
final F<F<Input<char[]>, IterV<char[], A>>, P1<IterV<char[], A>>> cont =
F1Functions.lazy(Function.apply(input));
i = i.fold(done, cont)._1();
}
return i;
};
}
}



/**
* A function that feeds an iteratee with characters read from a {@link Reader}
* (chars are read in chunks of size {@link #DEFAULT_BUFFER_SIZE}).
*/
public static <A> F<Reader, F<IterV<Character, A>, IO<IterV<Character, A>>>> charChunkReader2() {
final F<IterV<Character, A>, Boolean> isDone =
new F<Iteratee.IterV<Character, A>, Boolean>() {
final F<P2<A, Input<Character>>, P1<Boolean>> done = constant(P.p(true));
final F<F<Input<Character>, IterV<Character, A>>, P1<Boolean>> cont = constant(P.p(false));

@Override
public Boolean f(final IterV<Character, A> i) {
return i.fold(done, cont)._1();
return CharChunkReader2::new;
}

private static class CharChunkReader2<A> implements F<IterV<Character, A>, IO<IterV<Character, A>>> {

private final Reader r;

private final F<IterV<Character, A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
private final F<P2<A, Input<Character>>, IterV<Character, A>> done = errorF("iteratee is done"); //$NON-NLS-1$

CharChunkReader2(Reader r) {
this.r = r;
}

@Override
public IO<IterV<Character, A>> f(IterV<Character, A> it) {
// use loop instead of recursion because of missing TCO
return () -> {

IterV<Character, A> i = it;
while (!isDone.f(i)) {
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
final int numRead = r.read(buffer);
if (numRead == -1) {
return i;
}
};

return r -> new F<IterV<Character, A>, IO<IterV<Character, A>>>() {
final F<P2<A, Input<Character>>, IterV<Character, A>> done = errorF("iteratee is done"); //$NON-NLS-1$

@Override
public IO<IterV<Character, A>> f(final IterV<Character, A> it) {
// use loop instead of recursion because of missing TCO
return () -> {

IterV<Character, A> i = it;
while (!isDone.f(i)) {
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
final int numRead = r.read(buffer);
if (numRead == -1) {
return i;
}
if (numRead < buffer.length) {
buffer = Arrays.copyOfRange(buffer, 0, numRead);
}
for (char c : buffer) {
final Input<Character> input = Input.el(c);
final F<F<Input<Character>, IterV<Character, A>>, IterV<Character, A>> cont =
Function.apply(input);
i = i.fold(done, cont);
}
if (numRead < buffer.length) {
buffer = Arrays.copyOfRange(buffer, 0, numRead);
}
return i;
};
}
};
for (char c : buffer) {
final Input<Character> input = Input.el(c);
final F<F<Input<Character>, IterV<Character, A>>, IterV<Character, A>> cont =
Function.apply(input);
i = i.fold(done, cont);
}
}
return i;
};
}
}

public static <A, B> IO<B> map(final IO<A> io, final F<A, B> f) {
Expand Down
22 changes: 1 addition & 21 deletions core/src/main/java/fj/data/Java.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,27 +404,7 @@ public static <A> F<Array<A>, SynchronousQueue<A>> Array_SynchronousQueue(final
* @return A function that converts streams to iterable.
*/
public static <A> F<Stream<A>, Iterable<A>> Stream_Iterable() {
return as -> () -> new Iterator<A>() {
private Stream<A> x = as;

public boolean hasNext() {
return x.isNotEmpty();
}

public A next() {
if (x.isEmpty())
throw new NoSuchElementException("Empty iterator");
else {
final A a = x.head();
x = x.tail()._1();
return a;
}
}

public void remove() {
throw new UnsupportedOperationException();
}
};
return as -> as;
}

/**
Expand Down
Loading