View Javadoc

1   package se.citerus.dddsample.domain.model.voyage;
2   
3   import org.apache.commons.lang.Validate;
4   import se.citerus.dddsample.domain.shared.ValueObject;
5   
6   /**
7    * Identifies a voyage.
8    * 
9    */
10  public class VoyageNumber implements ValueObject<VoyageNumber> {
11  
12    private String number;
13  
14    public VoyageNumber(String number) {
15      Validate.notNull(number);
16      
17      this.number = number;
18    }
19  
20    @Override
21    public boolean equals(Object o) {
22      if (this == o) return true;
23      if (o == null) return false;
24      if (!(o instanceof VoyageNumber)) return false;
25  
26      final VoyageNumber other = (VoyageNumber) o;
27      
28      return sameValueAs(other);
29    }
30  
31    @Override
32    public int hashCode() {
33      return number.hashCode();
34    }
35  
36    @Override
37    public boolean sameValueAs(VoyageNumber other) {
38      return other != null && this.number.equals(other.number);
39    }
40  
41    @Override
42    public String toString() {
43      return number;
44    }
45  
46    public String idString() {
47      return number;
48    }
49  
50    VoyageNumber() {
51      // Needed by Hibernate
52    }
53    
54  }