2018-03-13 23:45:55 +09:00
|
|
|
/*
|
2021-01-08 17:55:38 +01:00
|
|
|
* Copyright (C) 2018-2021 Lightbend Inc. <https://www.lightbend.com>
|
2018-03-13 23:45:55 +09:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.stream;
|
2016-01-13 16:25:24 +01:00
|
|
|
|
|
|
|
|
import akka.actor.ActorRef;
|
|
|
|
|
|
|
|
|
|
import java.util.function.Predicate;
|
|
|
|
|
|
|
|
|
|
/**
|
2019-01-12 04:00:53 +08:00
|
|
|
* Acts as if `System.out.println()` yet swallows all messages. Useful for putting printlines in
|
|
|
|
|
* examples yet without polluting the build with them.
|
2016-01-13 16:25:24 +01:00
|
|
|
*/
|
|
|
|
|
public class SilenceSystemOut {
|
|
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
private SilenceSystemOut() {}
|
2016-01-13 16:25:24 +01:00
|
|
|
|
|
|
|
|
public static System get() {
|
2019-01-12 04:00:53 +08:00
|
|
|
return new System(
|
|
|
|
|
new System.Println() {
|
|
|
|
|
@Override
|
|
|
|
|
public void println(String s) {
|
|
|
|
|
// ignore
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-01-13 16:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static System get(ActorRef probe) {
|
2019-01-12 04:00:53 +08:00
|
|
|
return new System(
|
|
|
|
|
new System.Println() {
|
|
|
|
|
@Override
|
|
|
|
|
public void println(String s) {
|
|
|
|
|
probe.tell(s, ActorRef.noSender());
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-01-13 16:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static System get(Predicate<String> filter, ActorRef probe) {
|
2019-01-12 04:00:53 +08:00
|
|
|
return new System(
|
|
|
|
|
new System.Println() {
|
|
|
|
|
@Override
|
|
|
|
|
public void println(String s) {
|
|
|
|
|
if (filter.test(s)) probe.tell(s, ActorRef.noSender());
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-01-13 16:25:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class System {
|
|
|
|
|
public final Println out;
|
|
|
|
|
|
|
|
|
|
public System(Println out) {
|
|
|
|
|
this.out = out;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
public abstract static class Println {
|
2016-01-13 16:25:24 +01:00
|
|
|
public abstract void println(String s);
|
|
|
|
|
|
|
|
|
|
public void println(Object s) {
|
|
|
|
|
println(s.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void printf(String format, Object... args) {
|
|
|
|
|
println(String.format(format, args));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|