![JAR search and dependency download from the Maven repository](/logo.png)
de.aliceice.paper.ConsolePaper Maven / Gradle / Ivy
package de.aliceice.paper;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public final class ConsolePaper implements Paper {
@Override
public void printTitle(String title) {
this.out.println(title);
}
@Override
public void printDescription(String description) {
this.out.println(description);
this.out.println();
}
@Override
public void printField(String name, String description) {
this.fieldDescriptions.put(name, description);
this.out.printf("%s: ", name);
this.fieldValues.put(name, this.in.nextLine());
}
@Override
public void markAsInvalid() {
this.out.println("There are errors on the form:");
}
@Override
public void markErrorOn(String fieldName) {
this.out.printf(" - %s: %s", fieldName, this.fieldDescriptions.get(fieldName));
}
@Override
public void copyTo(Form form) {
this.fieldValues.forEach(form::write);
}
public ConsolePaper() {
this(System.in, System.out);
}
public ConsolePaper(InputStream in, OutputStream out) {
this.in = new Scanner(in);
this.out = new PrintWriter(out, true);
this.fieldValues = new HashMap<>();
this.fieldDescriptions = new HashMap<>();
}
private final Scanner in;
private final PrintWriter out;
private final Map fieldValues;
private final Map fieldDescriptions;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy