1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package net.sourceforge.domian.test.domain;
17  
18  
19  import java.util.Arrays;
20  import java.util.Collections;
21  import java.util.List;
22  
23  import org.apache.commons.lang.builder.EqualsBuilder;
24  import org.apache.commons.lang.builder.HashCodeBuilder;
25  import org.apache.commons.lang.builder.ReflectionToStringBuilder;
26  import static org.apache.commons.lang.math.RandomUtils.nextLong;
27  import org.apache.commons.lang.NotImplementedException;
28  
29  import net.sourceforge.domian.entity.Entity;
30  
31  
32  
33  public class OrderLine implements Entity {
34  
35      protected final String entityId = String.valueOf(nextLong()); 
36  
37      
38      protected Integer version;
39  
40      protected long orderLineId;
41      protected boolean paymentReceived = false;    
42      protected Boolean processed = false;          
43      protected Boolean cancelled = false;          
44  
45      
46      public OrderLine() {}
47  
48      public OrderLine(final Long id) {
49          this.orderLineId = id; 
50      }
51  
52      public long getOrderLineId() {
53          return orderLineId;
54      }
55  
56      public boolean isPaymentReceived() {
57          return paymentReceived;
58      }
59  
60      public OrderLine paymentReceived(final boolean paymentReceived) {
61          this.paymentReceived = paymentReceived;
62          return this;
63      }
64  
65      public Boolean isProcessed() {
66          return processed;
67      }
68  
69      public OrderLine processed(final boolean processed) {
70          this.processed = processed;
71          return this;
72      }
73  
74      public Boolean isCancelled() {
75          return cancelled;
76      }
77  
78      public OrderLine cancelled(final boolean cancelled) {
79          this.cancelled = cancelled;
80          return this;
81      }
82  
83      
84      public Boolean pending() {
85          return !isPaymentReceived();
86      }
87  
88      
89      public boolean isPending() {
90          return pending();
91      }
92  
93      
94      Boolean privateIsPending() {
95          return pending();
96      }
97  
98      @Override
99      public String getEntityId() {
100         return this.entityId;
101     }
102 
103     public Integer getVersion() {
104         throw new NotImplementedException();
105     }
106 
107     public void setVersion(Integer version) {
108         throw new NotImplementedException();
109     }
110 
111     public Boolean isEntity() {
112         return Boolean.TRUE;
113     }
114 
115     public List getKey() {
116         return Collections.unmodifiableList(Arrays.asList(orderLineId));
117     }
118 
119     public static List getKeyProperties() {
120         return Collections.unmodifiableList(Arrays.asList("orderLineId"));
121     }
122 
123     public Integer getInitialNonZeroOddNumber() {
124         return 2753;
125     }
126 
127     public Integer getMultiplierNonZeroOddNumber() {
128         return 7739;
129     }
130 
131     @Override
132     public int hashCode() {
133         final HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(getInitialNonZeroOddNumber(),
134                                                                     getMultiplierNonZeroOddNumber());
135         for (Object partialKey : getKey()) {
136             if (isEntity()) {
137                 if (partialKey != null) {
138                     hashCodeBuilder.append(partialKey);
139                 } else {
140                     return System.identityHashCode(this);
141                 }
142 
143             } else { 
144                 if (partialKey != null) {
145                     hashCodeBuilder.append(partialKey);
146                 }
147             }
148         }
149         return hashCodeBuilder.toHashCode();
150     }
151 
152     @Override
153     public boolean equals(final Object otherObject) {
154         if (otherObject == null) {
155             return false;
156         }
157         if (!(otherObject instanceof OrderLine)) {
158             return false;
159         }
160         OrderLine otherOrderLine = (OrderLine) otherObject;
161         return new EqualsBuilder().append(this.orderLineId, otherOrderLine.orderLineId).isEquals();
162     }
163 
164     @Override
165     public String toString() {
166         return new ReflectionToStringBuilder(this).toString();
167     }
168 }