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