View Javadoc

1   package se.citerus.dddsample.domain.model.voyage;
2   
3   import org.apache.commons.lang.Validate;
4   import org.apache.commons.lang.builder.HashCodeBuilder;
5   import se.citerus.dddsample.domain.shared.ValueObject;
6   
7   import java.util.Collections;
8   import java.util.List;
9   
10  /**
11   * A voyage schedule.
12   * 
13   */
14  public class Schedule implements ValueObject<Schedule> {
15  
16    private List<CarrierMovement> carrierMovements = Collections.EMPTY_LIST;
17  
18    public static final Schedule EMPTY = new Schedule();
19  
20    Schedule(final List<CarrierMovement> carrierMovements) {
21      Validate.notNull(carrierMovements);
22      Validate.noNullElements(carrierMovements);
23      Validate.notEmpty(carrierMovements);
24  
25      this.carrierMovements = carrierMovements;
26    }
27  
28    /**
29     * @return Carrier movements.
30     */
31    public List<CarrierMovement> carrierMovements() {
32      return Collections.unmodifiableList(carrierMovements);
33    }
34  
35    @Override
36    public boolean sameValueAs(final Schedule other) {
37      return other != null && this.carrierMovements.equals(other.carrierMovements);
38    }
39  
40    @Override
41    public boolean equals(final Object o) {
42      if (this == o) return true;
43      if (o == null || getClass() != o.getClass()) return false;
44  
45      final Schedule that = (Schedule) o;
46  
47      return sameValueAs(that);
48    }
49  
50    @Override
51    public int hashCode() {
52      return new HashCodeBuilder().append(this.carrierMovements).toHashCode();
53    }
54  
55    Schedule() {
56      // Needed by Hibernate
57    }
58  
59  }