View Javadoc

1   package se.citerus.dddsample.domain.model.cargo;
2   
3   import org.apache.commons.lang.Validate;
4   import se.citerus.dddsample.domain.shared.ValueObject;
5   
6   /**
7    * Uniquely identifies a particular cargo. Automatically generated by the application.
8    *  
9    */
10  public final class TrackingId implements ValueObject<TrackingId> {
11  
12    private String id;
13  
14    /**
15     * Constructor.
16     *
17     * @param id Id string.
18     */
19    public TrackingId(final String id) {
20      Validate.notNull(id);
21      this.id = id;
22    }
23  
24    /**
25     * @return String representation of this tracking id.
26     */
27    public String idString() {
28      return id;
29    }
30  
31    @Override
32    public boolean equals(Object o) {
33      if (this == o) return true;
34      if (o == null || getClass() != o.getClass()) return false;
35  
36      TrackingId other = (TrackingId) o;
37  
38      return sameValueAs(other);
39    }
40  
41    @Override
42    public int hashCode() {
43      return id.hashCode();
44    }
45  
46    @Override
47    public boolean sameValueAs(TrackingId other) {
48      return other != null && this.id.equals(other.id);
49    }
50  
51    @Override
52    public String toString() {
53      return id;
54    }
55  
56    TrackingId() {
57      // Needed by Hibernate
58    }
59  }