package environment; import java.io.*; import java.util.function.Function; import error.ErrorManager; public class RuntimeEnvironment { private static RuntimeEnvironment uniqueInstance = new RuntimeEnvironment(); public static RuntimeEnvironment getInstance() { return uniqueInstance; } private String inputName; private InputStream input; private PrintStream output; private PrintStream errorOutput; private Function outputDecorator; private Function valueOutputDecorator; private Function warningOutputDecorator; private Function errorOutputDecorator; private Function criticalOutputDecorator; private Runnable terminationFunction; private Runnable errorTerminationFunction; private ErrorManager errorManager; private RuntimeEnvironment() {} public void setInputName(String inputName) { this.inputName = inputName; } public void setInput(InputStream input) { this.input = input; } public void setOutput(PrintStream output) { this.output = output; } public void setErrorOutput(PrintStream errorOutput) { this.errorOutput = errorOutput; } public void setTerminationFunction(Runnable terminationFunction) { this.terminationFunction = terminationFunction; } public void setErrorTerminationFunction(Runnable errorTerminationFunction) { this.errorTerminationFunction = errorTerminationFunction; } public void setErrorManager(ErrorManager errorManager) { this.errorManager = errorManager; } public void setOutputDecorator(Function outputDecorator) { this.outputDecorator = outputDecorator; } public void setValueOutputDecorator(Function valueOutputDecorator) { this.valueOutputDecorator = valueOutputDecorator; } public void setWarningOutputDecorator(Function warningOutputDecorator) { this.warningOutputDecorator = warningOutputDecorator; } public void setErrorOutputDecorator(Function errorOutputDecorator) { this.errorOutputDecorator = errorOutputDecorator; } public void setCriticalOutputDecorator(Function criticalOutputDecorator) { this.criticalOutputDecorator = criticalOutputDecorator; } public String getInputName() { return inputName; } public InputStream getInput() { return input; } public PrintStream getOutput() { return output; } public PrintStream getErrorOutput() { return errorOutput; } public void terminateSuccessfully() { terminationFunction.run(); } public void terminateExceptionally() { errorTerminationFunction.run(); } public ErrorManager getErrorManager() { return errorManager; } 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); } }