1
2
3
4
5
6 package gov.nist.secauto.metaschema.cli.processor;
7
8 import java.util.Arrays;
9 import java.util.Collections;
10 import java.util.List;
11
12 import edu.umd.cs.findbugs.annotations.NonNull;
13
14 public class MessageExitStatus
15 extends AbstractExitStatus {
16 private final List<Object> messageArguments;
17
18
19
20
21
22
23
24
25
26
27 public MessageExitStatus(@NonNull ExitCode code, @NonNull Object... messageArguments) {
28 super(code);
29 if (messageArguments.length == 0) {
30 this.messageArguments = Collections.emptyList();
31 } else {
32 this.messageArguments = Arrays.asList(messageArguments);
33 }
34 }
35
36 @Override
37 public String getMessage() {
38 String format = lookupMessageForCode(getExitCode());
39 return String.format(format, messageArguments.toArray());
40 }
41
42 private String lookupMessageForCode(@SuppressWarnings("unused") ExitCode ignoredExitCode) {
43
44 StringBuilder builder = new StringBuilder();
45
46 for (int index = 1; index <= messageArguments.size(); index++) {
47 if (index > 1) {
48 builder.append(' ');
49 }
50 builder.append("%s");
51
52 }
53 return builder.toString();
54 }
55 }