1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.core.metapath;
7   
8   import gov.nist.secauto.metaschema.core.metapath.impl.ErrorCodeImpl;
9   import gov.nist.secauto.metaschema.core.util.ObjectUtils;
10  
11  import edu.umd.cs.findbugs.annotations.NonNull;
12  
13  /**
14   * Provides an error code that identifies the type of message.
15   * <p>
16   * Implementations of this interface are expected to be immutable.
17   */
18  public interface IErrorCode {
19    /**
20     * Create a new error code with the provided prefix and code value.
21     *
22     * @param prefix
23     *          the error code prefix
24     * @param code
25     *          the error code value
26     * @return a new error code instance
27     */
28    @NonNull
29    static IErrorCode of(@NonNull String prefix, int code) {
30      return new ErrorCodeImpl(prefix, code);
31    }
32  
33    /**
34     * Get the error code prefix, which indicates what type of error it is.
35     *
36     * @return the error code prefix
37     */
38    @NonNull
39    String getPrefix();
40  
41    /**
42     * Get the error code value.
43     *
44     * @return the error code value
45     */
46    int getCode();
47  
48    /**
49     * Get a combination of the error code family and value.
50     *
51     * @return the full error code.
52     */
53    @NonNull
54    default String getCodeAsString() {
55      return ObjectUtils.notNull(String.format("%s%04d", getPrefix(), getCode()));
56    }
57  }