View Javadoc

1   package com.atlassian.scheduler.config;
2   
3   import com.atlassian.annotations.PublicApi;
4   
5   import javax.annotation.Nullable;
6   import javax.annotation.concurrent.Immutable;
7   import java.io.Serializable;
8   
9   import static com.atlassian.util.concurrent.Assertions.notNull;
10  
11  /**
12   * A wrapper to distinguish job IDs from simple strings and to make it easier
13   * to avoid confusing them with job runner keys.
14   *
15   * @since v1.0
16   */
17  @Immutable
18  @PublicApi
19  public final class JobId implements Serializable, Comparable<JobId> {
20      private static final long serialVersionUID = 1L;
21  
22      /**
23       * Wraps the provided string as a {@code JobId}.
24       *
25       * @param id the job ID, as a string
26       * @return the wrapped job runner key
27       */
28      public static JobId of(String id) {
29          return new JobId(id);
30      }
31  
32  
33      private final String id;
34  
35      private JobId(final String id) {
36          this.id = notNull("id", id);
37      }
38  
39  
40      @Override
41      @SuppressWarnings("SimplifiableIfStatement")
42      public boolean equals(@Nullable final Object o) {
43          if (this == o) {
44              return true;
45          }
46          return o != null
47                  && o.getClass() == getClass()
48                  && ((JobId) o).id.equals(id);
49      }
50  
51      @Override
52      public int compareTo(final JobId o) {
53          return id.compareTo(o.id);
54      }
55  
56      @Override
57      public int hashCode() {
58          return id.hashCode();
59      }
60  
61      public String toString() {
62          return id;
63      }
64  }