Ray Milkey | fbfd2da | 2014-05-09 17:30:14 -0700 | [diff] [blame^] | 1 | package net.onrc.onos.api.rest; |
| 2 | |
| 3 | import org.slf4j.helpers.FormattingTuple; |
| 4 | import org.slf4j.helpers.MessageFormatter; |
| 5 | |
| 6 | /** |
| 7 | * Utility class used for formatting Rest Error descriptions. |
| 8 | */ |
| 9 | public final class RestErrorFormatter { |
| 10 | |
| 11 | /** |
| 12 | * Hide default constructor for utility classes. |
| 13 | */ |
| 14 | private RestErrorFormatter() { } |
| 15 | |
| 16 | /** |
| 17 | * Takes a RestError template and formats the description using a supplied |
| 18 | * list of replacement parameters. |
| 19 | * |
| 20 | * @param error the RestError to format |
| 21 | * @param parameters parameter list to use as positional parameters in the |
| 22 | * result string |
| 23 | * |
| 24 | * @return the String object for the formatted message. |
| 25 | */ |
| 26 | static String formatErrorMessage(final RestError error, |
| 27 | final Object... parameters) { |
| 28 | final FormattingTuple formattingResult = |
| 29 | MessageFormatter.arrayFormat(error.getDescription(), parameters); |
| 30 | return formattingResult.getMessage(); |
| 31 | } |
| 32 | } |