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.logic;
8   
9   import static org.mule.util.ClassUtils.equal;
10  import static org.mule.util.ClassUtils.hash;
11  
12  import org.mule.api.MuleMessage;
13  import org.mule.api.routing.filter.Filter;
14  
15  /**
16   * <code>NotFilter</code> accepts if the filter does not accept.
17   */
18  
19  public class NotFilter implements Filter
20  {
21      private Filter filter;
22  
23      public NotFilter()
24      {
25          super();
26      }
27  
28      public NotFilter(Filter filter)
29      {
30          this.filter = filter;
31      }
32  
33      public Filter getFilter()
34      {
35          return filter;
36      }
37  
38      public void setFilter(Filter filter)
39      {
40          this.filter = filter;
41      }
42  
43      public boolean accept(MuleMessage message)
44      {
45          return (filter != null ? !filter.accept(message) : false);
46      }
47  
48      public boolean equals(Object obj)
49      {
50          if (this == obj) return true;
51          if (obj == null || getClass() != obj.getClass()) return false;
52  
53          final NotFilter other = (NotFilter) obj;
54          return equal(filter, other.filter);
55      }
56  
57      public int hashCode()
58      {
59          return hash(new Object[]{this.getClass(), filter});
60      }
61  }