I'd change your enum State, like this:
enum State
{
OK(null),
COULDNT_LOAD("Error: Could not load file: %s."),
COULDNT_PARSE("Error: Could not parse contents of file %s."),
UNEXPECTED_NUM_FILES("Error: Unexpected number of files - expected %s%d, actual %s%d.");
String message;
State(String message)
{
this.message = message;
}
void setReplacements(Object... replacements)
{
if(this.message != null)
{
this.message = new Formatter().format(this.message, replacements).toString();
}
}
}
Then you can have your validation method return a state, and you can do your checking block after, like this:
File fileITriedToLoad = new File("/usr/file.java");
State result = State.COULDNT_LOAD;
result.setReplacements(fileITriedToLoad.getAbsolutePath());
if(result != State.OK)
{
System.out.println(result.message);
}
And you can delete the rest of your Result class.
Edit: Using the new setReplacements() method would then allow you to add pieces of text at the specified points in your message, so your validation method that returns a State would use it as follows:
State state = State.UNEXPECTED_NUM_FILES;
state.setReplacements(1, 3);
And then printing the state.message will produce:
Error: Unexpected number of files - expected 1, actual 3.