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.routing.filters;
8   
9   import org.mule.api.MuleMessage;
10  import org.mule.api.routing.filter.Filter;
11  import org.mule.api.routing.filter.ObjectFilter;
12  
13  /**
14   * <code>EqualsFilter</code> is a filter for comparing two objects using the
15   * equals() method.
16   */
17  public class EqualsFilter implements Filter, ObjectFilter
18  {
19      private Object pattern;
20  
21      public EqualsFilter()
22      {
23          super();
24      }
25  
26      public EqualsFilter(Object compareTo)
27      {
28          this.pattern = compareTo;
29      }
30  
31      public boolean accept(MuleMessage message)
32      {
33          return accept(message.getPayload());
34      }
35  
36      public boolean accept(Object object)
37      {
38          if (object == null && pattern == null)
39          {
40              return true;
41          }
42  
43          if (object == null || pattern == null)
44          {
45              return false;
46          }
47  
48          return pattern.equals(object);
49      }
50  
51      public Object getPattern()
52      {
53          return pattern;
54      }
55  
56      public void setPattern(Object pattern)
57      {
58          this.pattern = pattern;
59      }
60  
61  }