View Javadoc

1   /*
2    * $Id: WaterMelon.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.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.lifecycle.Disposable;
16  import org.mule.api.lifecycle.Startable;
17  import org.mule.api.lifecycle.Stoppable;
18  
19  import java.util.HashMap;
20  
21  import org.apache.commons.logging.Log;
22  import org.apache.commons.logging.LogFactory;
23  
24  public class WaterMelon implements Fruit, Startable, Stoppable, Disposable
25  {
26      /**
27       * Serial version
28       */
29      private static final long serialVersionUID = -8860598811203869100L;
30  
31      /**
32       * logger used by this class
33       */
34      private static final Log logger = LogFactory.getLog(WaterMelon.class);
35  
36      private boolean bitten = false;
37      private Integer seeds = new Integer(100);
38      private Double radius = new Double(4.34);
39      private String brand;
40      private String state = "void";
41  
42      public WaterMelon()
43      {
44          super();
45      }
46  
47      public WaterMelon(HashMap props) throws MuleException
48      {
49          logger.info("Initialisaing Water melon with hashmap constructor");
50          setBrand((String) props.get("namespace.brand"));
51          setRadius((Double) props.get("another.namespace.radius"));
52          setSeeds((Integer) props.get("seeds"));
53          state = "initialised";
54      }
55  
56      public void bite()
57      {
58          bitten = true;
59      }
60  
61      public boolean isBitten()
62      {
63          return bitten;
64      }
65  
66      public void myEventHandler(MuleEvent event) throws MuleException
67      {
68          logger.debug("Water Melon received an event in MyEventHandler! MuleEvent says: "
69                       + event.getMessageAsString());
70          bite();
71      }
72  
73      public String getBrand()
74      {
75          return brand;
76      }
77  
78      public Integer getSeeds()
79      {
80          return seeds;
81      }
82  
83      public Double getRadius()
84      {
85          return radius;
86      }
87  
88      public void setBrand(String string)
89      {
90          brand = string;
91      }
92  
93      public void setSeeds(Integer integer)
94      {
95          seeds = integer;
96      }
97  
98      public void setRadius(Double double1)
99      {
100         radius = double1;
101     }
102 
103     public String getState()
104     {
105         return state;
106     }
107 
108     public void start()
109     {
110         state = "started";
111     }
112 
113     public void stop()
114     {
115         state = "stopped";
116     }
117 
118     public void dispose()
119     {
120         state = "disposed";
121     }
122 
123     @Override
124     public boolean equals(Object obj)
125     {
126         if (obj instanceof WaterMelon)
127         {
128             WaterMelon melon = (WaterMelon) obj;
129             return (getBrand().equals(melon.getBrand()) && getRadius().equals(melon.getRadius())
130                     && getSeeds().equals(melon.getSeeds()) && getState().equals(getState()));
131         }
132 
133         return super.equals(obj);
134     }
135 
136     @Override
137     public int hashCode()
138     {
139         int result;
140         result = (bitten ? 1 : 0);
141         result = 31 * result + seeds.hashCode();
142         result = 31 * result + radius.hashCode();
143         result = 31 * result + (brand != null ? brand.hashCode() : 0);
144         result = 31 * result + state.hashCode();
145         return result;
146     }
147 }