View Javadoc

1   /*
2    * $Id: Orange.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.tck.testmodels.fruit;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleException;
15  import org.mule.api.lifecycle.Callable;
16  
17  import java.util.HashMap;
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  public class Orange implements Callable, OrangeInterface
25  {
26      /**
27       * Serial version
28       */
29      private static final long serialVersionUID = 2556604671068150589L;
30  
31      /**
32       * logger used by this class
33       */
34      private static final Log logger = LogFactory.getLog(Orange.class);
35  
36      private boolean bitten = false;
37      private Integer segments = new Integer(10);
38      private Double radius = new Double(4.34);
39      private String brand = "Pirulo";
40  
41      private FruitCleaner cleaner;
42  
43      private Map mapProperties;
44  
45      private List listProperties;
46  
47      private List arrayProperties;
48  
49      public Orange()
50      {
51          super();
52      }
53  
54      public Orange(Integer segments, Double radius, String brand)
55      {
56          super();
57          this.segments = segments;
58          this.radius = radius;
59          this.brand = brand;
60      }
61  
62      public Orange(HashMap props) throws MuleException
63      {
64          setBrand((String) props.get("brand"));
65          setRadius((Double) props.get("radius"));
66          setSegments((Integer) props.get("segments"));
67      }
68  
69      public void bite()
70      {
71          bitten = true;
72      }
73  
74      public boolean isBitten()
75      {
76          return bitten;
77      }
78  
79      public Object onCall(MuleEventContext context) throws MuleException
80      {
81          logger.debug("Orange received an event in Callable.onEvent! MuleEvent says: "
82                       + context.getMessageAsString());
83          bite();
84          return null;
85      }
86  
87      public String getBrand()
88      {
89          return brand;
90      }
91  
92      public Integer getSegments()
93      {
94          return segments;
95      }
96  
97      public Double getRadius()
98      {
99          return radius;
100     }
101 
102     public void setBrand(String string)
103     {
104         brand = string;
105     }
106 
107     public void setSegments(Integer integer)
108     {
109         segments = integer;
110     }
111 
112     public void setRadius(Double double1)
113     {
114         radius = double1;
115     }
116 
117     /**
118      * @return Returns the listProperties.
119      */
120     public List getListProperties()
121     {
122         return listProperties;
123     }
124 
125     /**
126      * @param listProperties The listProperties to set.
127      */
128     public void setListProperties(List listProperties)
129     {
130         this.listProperties = listProperties;
131     }
132 
133     /**
134      * @return Returns the mapProperties.
135      */
136     public Map getMapProperties()
137     {
138         return mapProperties;
139     }
140 
141     /**
142      * @param mapProperties The mapProperties to set.
143      */
144     public void setMapProperties(Map mapProperties)
145     {
146         this.mapProperties = mapProperties;
147     }
148 
149     /**
150      * @return Returns the arrayProperties.
151      */
152     public List getArrayProperties()
153     {
154         return arrayProperties;
155     }
156 
157     /**
158      * @param arrayProperties The arrayProperties to set.
159      */
160     public void setArrayProperties(List arrayProperties)
161     {
162         this.arrayProperties = arrayProperties;
163     }
164 
165     public FruitCleaner getCleaner()
166     {
167         return cleaner;
168     }
169 
170     public void setCleaner(FruitCleaner cleaner)
171     {
172         this.cleaner = cleaner;
173     }
174 
175     public void wash()
176     {
177         cleaner.wash(this);
178     }
179 
180     public void polish()
181     {
182         cleaner.polish(this);
183     }
184 
185     @Override
186     public int hashCode()
187     {
188         final int prime = 31;
189         int result = 1;
190         result = prime * result + (bitten ? 1231 : 1237);
191         result = prime * result + ((brand == null) ? 0 : brand.hashCode());
192         result = prime * result + ((radius == null) ? 0 : radius.hashCode());
193         result = prime * result + ((segments == null) ? 0 : segments.hashCode());
194         return result;
195     }
196 
197     @Override
198     public boolean equals(Object obj)
199     {
200         if (this == obj)
201         {
202             return true;
203         }
204         if (obj == null)
205         {
206             return false;
207         }
208         if (getClass() != obj.getClass())
209         {
210             return false;
211         }
212         final Orange other = (Orange) obj;
213         if (bitten != other.bitten)
214         {
215             return false;
216         }
217         if (brand == null)
218         {
219             if (other.brand != null)
220             {
221                 return false;
222             }
223         }
224         else if (!brand.equals(other.brand))
225         {
226             return false;
227         }
228         if (radius == null)
229         {
230             if (other.radius != null)
231             {
232                 return false;
233             }
234         }
235         else if (!radius.equals(other.radius))
236         {
237             return false;
238         }
239         if (segments == null)
240         {
241             if (other.segments != null)
242             {
243                 return false;
244             }
245         }
246         else if (!segments.equals(other.segments))
247         {
248             return false;
249         }
250         return true;
251     }
252 
253 }