View Javadoc

1   package com.atlassian.messagequeue;
2   
3   import com.atlassian.annotations.PublicApi;
4   
5   import javax.annotation.Nullable;
6   import java.io.Serializable;
7   
8   import static java.util.Objects.requireNonNull;
9   
10  /**
11   * Message validator key
12   * @since 1.0.6
13   */
14  @PublicApi
15  public final class MessageValidatorKey implements Serializable, Comparable<MessageValidatorKey> {
16      private static final long serialVersionUID = 1L;
17  
18      private final String key;
19  
20      private MessageValidatorKey(final String key) {
21          this.key = requireNonNull(key, "key");
22      }
23  
24      /**
25       * Wraps the provided string as a {@code MessageValidatorKey}.
26       * <p>
27       * Although it is not necessary for correctness, it will usually make sense to create a single instance of
28       * the {@code MessageValidatorKey} and reuse it as a constant, as in:
29       * </p>
30       * <pre>
31       * {@code
32       *     private static final MessageValidatorKey <strong>MY_MESSAGE_VALIDATOR</strong> = MessageValidatorKey.of("com.example.plugin.MyMessageValidator");
33       *
34       *     // ...
35       *
36       *     private void registerMessageValidator()
37       *     {
38       *         messageValidatorRegistryService.registerMessageValidator(MY_MESSAGE_VALIDATOR, new MyMessageValidatorImpl();
39       *     }
40       * }
41       * </pre>
42       *
43       * @param key the message validator key, as a string
44       * @return the wrapped message validator key
45       */
46      public static MessageValidatorKey of(String key) {
47          return new MessageValidatorKey(key);
48      }
49  
50      @Override
51      @SuppressWarnings("SimplifiableIfStatement")
52      public boolean equals(@Nullable final Object o) {
53          if (this == o) {
54              return true;
55          }
56          return o != null
57                  && o.getClass() == getClass()
58                  && ((MessageValidatorKey) o).key.equals(key);
59      }
60  
61      @Override
62      public int compareTo(final MessageValidatorKey o) {
63          return key.compareTo(o.key);
64      }
65  
66      @Override
67      public int hashCode() {
68          return key.hashCode();
69      }
70  
71      @Override
72      public String toString() {
73          return key;
74      }
75  }