2017-01-17 13:54:21 -05:00
|
|
|
package environment;
|
|
|
|
|
|
|
|
import java.io.*;
|
2017-02-11 13:33:34 -05:00
|
|
|
import java.util.function.Function;
|
2017-01-17 13:54:21 -05:00
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
import error.ErrorManager;
|
|
|
|
|
2017-02-06 13:39:05 -05:00
|
|
|
public class RuntimeEnvironment {
|
2017-01-17 13:54:21 -05:00
|
|
|
|
2017-02-06 13:39:05 -05:00
|
|
|
private static RuntimeEnvironment uniqueInstance = new RuntimeEnvironment();
|
2017-01-17 13:54:21 -05:00
|
|
|
|
2017-02-06 13:39:05 -05:00
|
|
|
public static RuntimeEnvironment getInstance() {
|
2017-01-17 15:54:09 -05:00
|
|
|
return uniqueInstance;
|
2017-01-17 13:54:21 -05:00
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
private String inputName;
|
2017-01-17 13:54:21 -05:00
|
|
|
private InputStream input;
|
|
|
|
private PrintStream output;
|
|
|
|
private PrintStream errorOutput;
|
2017-02-11 13:33:34 -05:00
|
|
|
|
|
|
|
private Function<String, String> outputDecorator;
|
|
|
|
private Function<String, String> valueOutputDecorator;
|
|
|
|
private Function<String, String> warningOutputDecorator;
|
|
|
|
private Function<String, String> errorOutputDecorator;
|
|
|
|
private Function<String, String> criticalOutputDecorator;
|
2017-01-18 16:25:09 -05:00
|
|
|
private Runnable terminationFunction;
|
|
|
|
private Runnable errorTerminationFunction;
|
2017-02-09 11:00:23 -05:00
|
|
|
private ErrorManager errorManager;
|
2017-01-17 13:54:21 -05:00
|
|
|
|
2017-02-06 13:39:05 -05:00
|
|
|
private RuntimeEnvironment() {}
|
2017-02-11 10:51:37 -05:00
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
public void setInputName(String inputName) {
|
|
|
|
this.inputName = inputName;
|
|
|
|
}
|
2017-01-17 13:54:21 -05:00
|
|
|
|
|
|
|
public void setInput(InputStream input) {
|
|
|
|
this.input = input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setOutput(PrintStream output) {
|
|
|
|
this.output = output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setErrorOutput(PrintStream errorOutput) {
|
|
|
|
this.errorOutput = errorOutput;
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:25:09 -05:00
|
|
|
public void setTerminationFunction(Runnable terminationFunction) {
|
|
|
|
this.terminationFunction = terminationFunction;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setErrorTerminationFunction(Runnable errorTerminationFunction) {
|
|
|
|
this.errorTerminationFunction = errorTerminationFunction;
|
2017-01-17 13:54:21 -05:00
|
|
|
}
|
2017-02-11 10:51:37 -05:00
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
public void setErrorManager(ErrorManager errorManager) {
|
|
|
|
this.errorManager = errorManager;
|
|
|
|
}
|
2017-02-11 10:51:37 -05:00
|
|
|
|
2017-02-11 13:33:34 -05:00
|
|
|
public void setOutputDecorator(Function<String, String> outputDecorator) {
|
|
|
|
this.outputDecorator = outputDecorator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValueOutputDecorator(Function<String, String> valueOutputDecorator) {
|
|
|
|
this.valueOutputDecorator = valueOutputDecorator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setWarningOutputDecorator(Function<String, String> warningOutputDecorator) {
|
|
|
|
this.warningOutputDecorator = warningOutputDecorator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setErrorOutputDecorator(Function<String, String> errorOutputDecorator) {
|
|
|
|
this.errorOutputDecorator = errorOutputDecorator;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setCriticalOutputDecorator(Function<String, String> criticalOutputDecorator) {
|
|
|
|
this.criticalOutputDecorator = criticalOutputDecorator;
|
|
|
|
}
|
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
public String getInputName() {
|
|
|
|
return inputName;
|
|
|
|
}
|
2017-01-17 13:54:21 -05:00
|
|
|
|
|
|
|
public InputStream getInput() {
|
|
|
|
return input;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PrintStream getOutput() {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PrintStream getErrorOutput() {
|
|
|
|
return errorOutput;
|
|
|
|
}
|
|
|
|
|
2017-01-18 16:25:09 -05:00
|
|
|
public void terminateSuccessfully() {
|
|
|
|
terminationFunction.run();
|
|
|
|
}
|
2017-02-06 13:43:27 -05:00
|
|
|
|
2017-01-18 16:25:09 -05:00
|
|
|
public void terminateExceptionally() {
|
|
|
|
errorTerminationFunction.run();
|
2017-01-17 13:54:21 -05:00
|
|
|
}
|
2017-02-11 10:51:37 -05:00
|
|
|
|
2017-02-09 11:00:23 -05:00
|
|
|
public ErrorManager getErrorManager() {
|
|
|
|
return errorManager;
|
|
|
|
}
|
2017-01-17 13:54:21 -05:00
|
|
|
|
2017-02-11 13:33:34 -05:00
|
|
|
public String decorateOutput(String output) {
|
|
|
|
return outputDecorator.apply(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String decorateValueOutput(String valueOutput) {
|
|
|
|
return valueOutputDecorator.apply(valueOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String decorateWarningOutput(String warningOutput) {
|
|
|
|
return warningOutputDecorator.apply(warningOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String decorateErrorOutput(String errorOutput) {
|
|
|
|
return errorOutputDecorator.apply(errorOutput);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String decorateCriticalOutput(String criticalOutput) {
|
|
|
|
return criticalOutputDecorator.apply(criticalOutput);
|
|
|
|
}
|
|
|
|
|
2017-01-17 13:54:21 -05:00
|
|
|
}
|