Skip to content

Commit fb4b5bc

Browse files
authored
Merge pull request functionaljava#361 from jbgi/jdk11-compat
Fix compile under jdk11. Enable jdk11 travis build.
2 parents 453f83c + ebdceaa commit fb4b5bc

File tree

24 files changed

+247
-383
lines changed

24 files changed

+247
-383
lines changed

.travis.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@ sudo: false
44
language: java
55

66
jdk:
7-
- oraclejdk8
7+
- openjdk11
8+
9+
matrix:
10+
11+
include:
12+
- jdk: openjdk8
13+
script:
14+
- ./gradlew build coverage -s -i
15+
after_success:
16+
- bash <(curl -s https://codecov.io/bash)
17+
- '[ "$TRAVIS_BRANCH" = "series/4.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ]
18+
&& ./gradlew uploadArchives'
819

920
script:
10-
- jdk_switcher use openjdk7 && export JAVA7_HOME=$JAVA_HOME
11-
- jdk_switcher use oraclejdk8 && export JAVA8_HOME=$JAVA_HOME
12-
- ./gradlew build coverage -s -i
21+
- ./gradlew clean test
1322

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

1924
env:
2025
global:

build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ buildscript {
2323
}
2424
}
2525

26-
apply plugin: "jacoco"
27-
2826
if (JavaVersion.current().isJava8Compatible()) {
2927
allprojects {
3028
tasks.withType(Javadoc) {
@@ -35,11 +33,10 @@ if (JavaVersion.current().isJava8Compatible()) {
3533

3634
allprojects {
3735

38-
36+
apply plugin: "jacoco"
3937

4038
jacoco {
41-
toolVersion = "0.8.1"
42-
39+
toolVersion = "0.8.2"
4340
}
4441

4542
defaultTasks "build"
@@ -100,8 +97,6 @@ subprojects {
10097
}
10198
}
10299

103-
apply plugin: "jacoco"
104-
105100
apply from: "$rootDir/lib.gradle"
106101
apply plugin: "java"
107102
apply plugin: "eclipse"
@@ -123,9 +118,13 @@ subprojects {
123118
}
124119

125120
jacocoTestReport {
121+
additionalSourceDirs = files(sourceSets.main.allSource.srcDirs)
122+
sourceDirectories = files(sourceSets.main.allSource.srcDirs)
123+
classDirectories = files(sourceSets.main.output)
126124
reports {
127125
html.enabled = true
128126
xml.enabled = true
127+
csv.enabled = false
129128
}
130129
}
131130

core/src/main/java/fj/data/$.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@ public final class $<A, B> extends P1<B> {
1717

1818
/**
1919
* Returns a function that given an argument, returns a function that ignores its argument.
20-
* @deprecated JDK 8 warns '_' may not be supported after SE 8. As of release 4.4, use {@link #constant} (note the synonym {@link #__}).
2120
* @return A function that given an argument, returns a function that ignores its argument.
2221
*/
23-
@Deprecated
24-
public static <A, B> $<A, B> _(final B b) {
25-
return constant(b);
26-
}
27-
2822
public static <A, B> $<A, B> __(final B b) {
2923
return constant(b);
3024
}

core/src/main/java/fj/data/IOFunctions.java

Lines changed: 121 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
package fj.data;
22

3-
import static fj.Bottom.errorF;
4-
import static fj.Function.constant;
5-
import static fj.Function.partialApply2;
3+
import fj.F;
4+
import fj.F0;
5+
import fj.F1Functions;
6+
import fj.F2;
7+
import fj.Function;
8+
import fj.P;
9+
import fj.P1;
10+
import fj.P2;
11+
import fj.Try;
12+
import fj.Unit;
13+
import fj.data.Iteratee.Input;
14+
import fj.data.Iteratee.IterV;
15+
import fj.function.Try0;
16+
import fj.function.Try1;
617

718
import java.io.BufferedReader;
819
import java.io.Closeable;
@@ -14,11 +25,9 @@
1425
import java.nio.charset.Charset;
1526
import java.util.Arrays;
1627

17-
import fj.*;
18-
import fj.data.Iteratee.Input;
19-
import fj.data.Iteratee.IterV;
20-
import fj.function.Try0;
21-
import fj.function.Try1;
28+
import static fj.Bottom.errorF;
29+
import static fj.Function.constant;
30+
import static fj.Function.partialApply2;
2231

2332
/**
2433
* IO monad for processing files, with main methods {@link #enumFileLines },
@@ -170,130 +179,129 @@ public static <A> SafeIO<A> lazySafe(final F0<A> f) {
170179
* A function that feeds an iteratee with lines read from a {@link BufferedReader}.
171180
*/
172181
public static <A> F<BufferedReader, F<IterV<String, A>, IO<IterV<String, A>>>> lineReader() {
173-
final F<IterV<String, A>, Boolean> isDone =
174-
new F<Iteratee.IterV<String, A>, Boolean>() {
175-
final F<P2<A, Input<String>>, P1<Boolean>> done = constant(P.p(true));
176-
final F<F<Input<String>, IterV<String, A>>, P1<Boolean>> cont = constant(P.p(false));
177-
178-
@Override
179-
public Boolean f(final IterV<String, A> i) {
180-
return i.fold(done, cont)._1();
181-
}
182-
};
183-
184-
return r -> new F<IterV<String, A>, IO<IterV<String, A>>>() {
185-
final F<P2<A, Input<String>>, P1<IterV<String, A>>> done = errorF("iteratee is done"); //$NON-NLS-1$
186-
187-
@Override
188-
public IO<IterV<String, A>> f(final IterV<String, A> it) {
189-
// use loop instead of recursion because of missing TCO
190-
return () -> {
191-
IterV<String, A> i = it;
192-
while (!isDone.f(i)) {
193-
final String s = r.readLine();
194-
if (s == null) {
195-
return i;
196-
}
197-
final Input<String> input = Input.el(s);
198-
final F<F<Input<String>, IterV<String, A>>, P1<IterV<String, A>>> cont = F1Functions.lazy(Function.apply(input));
199-
i = i.fold(done, cont)._1();
182+
return LineReader::new;
183+
}
184+
185+
private static class LineReader<A> implements F<IterV<String, A>, IO<IterV<String, A>>> {
186+
187+
private final BufferedReader r;
188+
189+
private final F<IterV<String, A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
190+
private final F<P2<A, Input<String>>, P1<IterV<String, A>>> done = errorF("iteratee is done"); //$NON-NLS-1$
191+
192+
private LineReader(BufferedReader r) {
193+
this.r = r;
194+
}
195+
196+
@Override
197+
public IO<IterV<String, A>> f(IterV<String, A> it) {
198+
// use loop instead of recursion because of missing TCO
199+
return () -> {
200+
IterV<String, A> i = it;
201+
while (!isDone.f(i)) {
202+
final String s = r.readLine();
203+
if (s == null) {
204+
return i;
200205
}
201-
return i;
202-
};
203-
}
204-
};
206+
final Input<String> input = Input.el(s);
207+
final F<F<Input<String>, IterV<String, A>>, P1<IterV<String, A>>> cont = F1Functions.lazy(Function.apply(input));
208+
i = i.fold(done, cont)._1();
209+
}
210+
return i;
211+
};
212+
}
205213
}
206214

207215
/**
208216
* A function that feeds an iteratee with character chunks read from a {@link Reader}
209217
* (char[] of size {@link #DEFAULT_BUFFER_SIZE}).
210218
*/
211219
public static <A> F<Reader, F<IterV<char[], A>, IO<IterV<char[], A>>>> charChunkReader() {
212-
final F<IterV<char[], A>, Boolean> isDone =
213-
new F<Iteratee.IterV<char[], A>, Boolean>() {
214-
final F<P2<A, Input<char[]>>, P1<Boolean>> done = constant(P.p(true));
215-
final F<F<Input<char[]>, IterV<char[], A>>, P1<Boolean>> cont = constant(P.p(false));
216-
217-
@Override
218-
public Boolean f(final IterV<char[], A> i) {
219-
return i.fold(done, cont)._1();
220+
return CharChunkReader::new;
221+
}
222+
223+
private static class CharChunkReader<A> implements F<IterV<char[], A>, IO<IterV<char[], A>>> {
224+
225+
private final Reader r;
226+
227+
private final F<IterV<char[], A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
228+
private final F<P2<A, Input<char[]>>, P1<IterV<char[], A>>> done = errorF("iteratee is done"); //$NON-NLS-1$
229+
230+
CharChunkReader(Reader r) {
231+
this.r = r;
232+
}
233+
234+
@Override
235+
public IO<IterV<char[], A>> f(IterV<char[], A> it) {
236+
// use loop instead of recursion because of missing TCO
237+
return () -> {
238+
239+
IterV<char[], A> i = it;
240+
while (!isDone.f(i)) {
241+
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
242+
final int numRead = r.read(buffer);
243+
if (numRead == -1) {
244+
return i;
220245
}
221-
};
222-
223-
return r -> new F<IterV<char[], A>, IO<IterV<char[], A>>>() {
224-
final F<P2<A, Input<char[]>>, P1<IterV<char[], A>>> done = errorF("iteratee is done"); //$NON-NLS-1$
225-
226-
@Override
227-
public IO<IterV<char[], A>> f(final IterV<char[], A> it) {
228-
// use loop instead of recursion because of missing TCO
229-
return () -> {
230-
231-
IterV<char[], A> i = it;
232-
while (!isDone.f(i)) {
233-
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
234-
final int numRead = r.read(buffer);
235-
if (numRead == -1) {
236-
return i;
237-
}
238-
if (numRead < buffer.length) {
239-
buffer = Arrays.copyOfRange(buffer, 0, numRead);
240-
}
241-
final Input<char[]> input = Input.el(buffer);
242-
final F<F<Input<char[]>, IterV<char[], A>>, P1<IterV<char[], A>>> cont =
243-
F1Functions.lazy(Function.apply(input));
244-
i = i.fold(done, cont)._1();
246+
if (numRead < buffer.length) {
247+
buffer = Arrays.copyOfRange(buffer, 0, numRead);
245248
}
246-
return i;
247-
};
248-
}
249-
};
249+
final Input<char[]> input = Input.el(buffer);
250+
final F<F<Input<char[]>, IterV<char[], A>>, P1<IterV<char[], A>>> cont =
251+
F1Functions.lazy(Function.apply(input));
252+
i = i.fold(done, cont)._1();
253+
}
254+
return i;
255+
};
256+
}
250257
}
251258

259+
260+
252261
/**
253262
* A function that feeds an iteratee with characters read from a {@link Reader}
254263
* (chars are read in chunks of size {@link #DEFAULT_BUFFER_SIZE}).
255264
*/
256265
public static <A> F<Reader, F<IterV<Character, A>, IO<IterV<Character, A>>>> charChunkReader2() {
257-
final F<IterV<Character, A>, Boolean> isDone =
258-
new F<Iteratee.IterV<Character, A>, Boolean>() {
259-
final F<P2<A, Input<Character>>, P1<Boolean>> done = constant(P.p(true));
260-
final F<F<Input<Character>, IterV<Character, A>>, P1<Boolean>> cont = constant(P.p(false));
261-
262-
@Override
263-
public Boolean f(final IterV<Character, A> i) {
264-
return i.fold(done, cont)._1();
266+
return CharChunkReader2::new;
267+
}
268+
269+
private static class CharChunkReader2<A> implements F<IterV<Character, A>, IO<IterV<Character, A>>> {
270+
271+
private final Reader r;
272+
273+
private final F<IterV<Character, A>, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1();
274+
private final F<P2<A, Input<Character>>, IterV<Character, A>> done = errorF("iteratee is done"); //$NON-NLS-1$
275+
276+
CharChunkReader2(Reader r) {
277+
this.r = r;
278+
}
279+
280+
@Override
281+
public IO<IterV<Character, A>> f(IterV<Character, A> it) {
282+
// use loop instead of recursion because of missing TCO
283+
return () -> {
284+
285+
IterV<Character, A> i = it;
286+
while (!isDone.f(i)) {
287+
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
288+
final int numRead = r.read(buffer);
289+
if (numRead == -1) {
290+
return i;
265291
}
266-
};
267-
268-
return r -> new F<IterV<Character, A>, IO<IterV<Character, A>>>() {
269-
final F<P2<A, Input<Character>>, IterV<Character, A>> done = errorF("iteratee is done"); //$NON-NLS-1$
270-
271-
@Override
272-
public IO<IterV<Character, A>> f(final IterV<Character, A> it) {
273-
// use loop instead of recursion because of missing TCO
274-
return () -> {
275-
276-
IterV<Character, A> i = it;
277-
while (!isDone.f(i)) {
278-
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
279-
final int numRead = r.read(buffer);
280-
if (numRead == -1) {
281-
return i;
282-
}
283-
if (numRead < buffer.length) {
284-
buffer = Arrays.copyOfRange(buffer, 0, numRead);
285-
}
286-
for (char c : buffer) {
287-
final Input<Character> input = Input.el(c);
288-
final F<F<Input<Character>, IterV<Character, A>>, IterV<Character, A>> cont =
289-
Function.apply(input);
290-
i = i.fold(done, cont);
291-
}
292+
if (numRead < buffer.length) {
293+
buffer = Arrays.copyOfRange(buffer, 0, numRead);
292294
}
293-
return i;
294-
};
295-
}
296-
};
295+
for (char c : buffer) {
296+
final Input<Character> input = Input.el(c);
297+
final F<F<Input<Character>, IterV<Character, A>>, IterV<Character, A>> cont =
298+
Function.apply(input);
299+
i = i.fold(done, cont);
300+
}
301+
}
302+
return i;
303+
};
304+
}
297305
}
298306

299307
public static <A, B> IO<B> map(final IO<A> io, final F<A, B> f) {

core/src/main/java/fj/data/Java.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -404,27 +404,7 @@ public static <A> F<Array<A>, SynchronousQueue<A>> Array_SynchronousQueue(final
404404
* @return A function that converts streams to iterable.
405405
*/
406406
public static <A> F<Stream<A>, Iterable<A>> Stream_Iterable() {
407-
return as -> () -> new Iterator<A>() {
408-
private Stream<A> x = as;
409-
410-
public boolean hasNext() {
411-
return x.isNotEmpty();
412-
}
413-
414-
public A next() {
415-
if (x.isEmpty())
416-
throw new NoSuchElementException("Empty iterator");
417-
else {
418-
final A a = x.head();
419-
x = x.tail()._1();
420-
return a;
421-
}
422-
}
423-
424-
public void remove() {
425-
throw new UnsupportedOperationException();
426-
}
427-
};
407+
return as -> as;
428408
}
429409

430410
/**

0 commit comments

Comments
 (0)