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