
javarepl.console.ConsoleConfig Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javarepl Show documentation
Show all versions of javarepl Show documentation
Java REPL is a simple Read-Eval-Print-Loop for Java language.
package javarepl.console;
import com.googlecode.totallylazy.Option;
import com.googlecode.totallylazy.Sequence;
import com.googlecode.totallylazy.Sequences;
import javarepl.Evaluator;
import javarepl.Result;
import javarepl.console.commands.*;
import java.io.File;
import static com.googlecode.totallylazy.Option.none;
import static com.googlecode.totallylazy.Option.option;
import static com.googlecode.totallylazy.Sequences.empty;
import static com.googlecode.totallylazy.Sequences.one;
import static com.googlecode.totallylazy.Sequences.sequence;
public final class ConsoleConfig {
public final Option historyFile;
public final Sequence expressions;
public final ConsoleLogger logger;
public final Sequence> commands;
public final Sequence results;
public final Boolean sandboxed;
private ConsoleConfig(Option historyFile, Sequence expressions, ConsoleLogger logger, Sequence> commands, Sequence results, Boolean sandboxed) {
this.historyFile = historyFile;
this.expressions = expressions;
this.logger = logger;
this.commands = commands;
this.results = results;
this.sandboxed = sandboxed;
}
public static ConsoleConfig consoleConfig() {
return new ConsoleConfig(none(File.class), empty(String.class), new ConsoleLogger(), defaultCommands(), empty(Result.class), false);
}
public ConsoleConfig logger(ConsoleLogger logger) {
return new ConsoleConfig(historyFile, expressions, option(logger).getOrElse(new ConsoleLogger()), commands, results, sandboxed);
}
public ConsoleConfig historyFile(Option file) {
return new ConsoleConfig(file, expressions, logger, commands, results, sandboxed);
}
public ConsoleConfig historyFile(File file) {
return new ConsoleConfig(option(file), expressions, logger, commands, results, sandboxed);
}
public ConsoleConfig expressions(String... expressions) {
return new ConsoleConfig(historyFile, sequence(expressions), logger, commands, results, sandboxed);
}
@SafeVarargs
@SuppressWarnings("varargs")
public final ConsoleConfig commands(Class extends Command>... cmds) {
return new ConsoleConfig(historyFile, expressions, logger, sequence(cmds).unsafeCast(), results, sandboxed);
}
public ConsoleConfig results(Result... results) {
return new ConsoleConfig(historyFile, expressions, logger, commands, sequence(results), sandboxed);
}
public ConsoleConfig sandboxed(boolean sandboxed) {
return new ConsoleConfig(historyFile, expressions, logger, commands, results, sandboxed);
}
public static Sequence> defaultCommands() {
return Sequences.>sequence()
.append(ClearScreen.class)
.append(QuitApplication.class)
.append(ShowHistory.class)
.append(SearchHistory.class)
.append(EvaluateFromHistory.class)
.append(ResetAllEvaluations.class)
.append(ReplayAllEvaluations.class)
.append(EvaluateFile.class)
.append(AddToClasspath.class)
.append(LoadSourceFile.class)
.append(ListValues.class)
.append(ShowLastSource.class)
.append(ShowTypeOfExpression.class)
.append(CheckExpression.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy