View Javadoc

1   /*
2    * $Id: Banana.java 22409 2011-07-14 05:14:27Z dirk.olmes $
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      @Override
51      public void bite()
52      {
53          bitten = true;
54      }
55  
56      @Override
57      public boolean isBitten()
58      {
59          return bitten;
60      }
61  
62      @Override
63      public boolean equals(Object o)
64      {
65          if (this == o)
66          {
67              return true;
68          }
69          if (!(o instanceof Banana))
70          {
71              return false;
72          }
73  
74          Banana banana = (Banana) o;
75  
76          if (bitten != banana.bitten)
77          {
78              return false;
79          }
80          if (peeled != banana.peeled)
81          {
82              return false;
83          }
84  
85          return true;
86      }
87  
88      @Override
89      public int hashCode()
90      {
91          int result = (peeled ? 1 : 0);
92          result = 31 * result + (bitten ? 1 : 0);
93          return result;
94      }
95  }