View Javadoc

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