JodaTime - , - , ChoiceFormat MessageFormat:
static String choiceFor(int index, String noun) {
return "{index,choice,0#|1#1 noun |1<{index,number,integer} nouns }"
.replace("index", String.valueOf(index))
.replace("noun", noun);
}
static String prettyPrint(int h, int m, int s) {
String fmt =
choiceFor(0, "hour") +
choiceFor(1, "minute") +
choiceFor(2, "second");
return java.text.MessageFormat.format(fmt, h, m, s).trim();
}
( ideone.com):
System.out.println(prettyPrint(1,2,3));
System.out.println(prettyPrint(0,0,7));
System.out.println(prettyPrint(1,0,1));
System.out.println(prettyPrint(0,2,0));
, , , // ..