View Javadoc

1   /*
2    * $Id: Banana.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 java.util.EventObject;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  
18  public class Banana implements Fruit
19  {
20      /**
21       * Serial version
22       */
23      private static final long serialVersionUID = -1371515374040436874L;
24  
25      /**
26       * logger used by this class
27       */
28      private static final Log logger = LogFactory.getLog(Banana.class);
29  
30      private boolean peeled = false;
31      private boolean bitten = false;
32  
33      public void peel()
34      {
35          peeled = true;
36      }
37  
38      public void peelEvent(EventObject e)
39      {
40          logger.debug("Banana got peel event in peelEvent(EventObject)! MuleEvent says: "
41                          + e.getSource().toString());
42          peel();
43      }
44  
45      public boolean isPeeled()
46      {
47          return peeled;
48      }
49  
50      public void bite()
51      {
52          bitten = true;
53      }
54  
55      public boolean isBitten()
56      {
57          return bitten;
58      }
59  
60      @Override
61      public boolean equals(Object o)
62      {
63          if (this == o)
64          {
65              return true;
66          }
67          if (!(o instanceof Banana))
68          {
69              return false;
70          }
71  
72          Banana banana = (Banana) o;
73  
74          if (bitten != banana.bitten)
75          {
76              return false;
77          }
78          if (peeled != banana.peeled)
79          {
80              return false;
81          }
82  
83          return true;
84      }
85  
86      @Override
87      public int hashCode()
88      {
89          int result = (peeled ? 1 : 0);
90          result = 31 * result + (bitten ? 1 : 0);
91          return result;
92      }
93  }