michael-nmg/java-project-71

View on GitHub
app/src/main/java/hexlet/code/Formatter.java

Summary

Maintainability
A
0 mins
Test Coverage
package hexlet.code;

import hexlet.code.formatters.Format;
import hexlet.code.formatters.FormatJson;
import hexlet.code.formatters.FormatPlain;
import hexlet.code.formatters.FormatStylish;

public class Formatter {

    public static Format select(String format) throws RuntimeException {
        return switch (format) {
            case "plain" -> new FormatPlain();
            case "json" -> new FormatJson();
            case "stylish" -> new FormatStylish();
            default -> throw new RuntimeException("Unused format.");
        };
    }
}