View Javadoc

1   /*
2    * $Id: AbstractFilterCollection.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  package org.mule.routing.filters.logic;
11  
12  import org.mule.api.routing.filter.Filter;
13  import org.mule.util.ClassUtils;
14  
15  import java.util.ArrayList;
16  import java.util.List;
17  
18  /**
19   * Manages a filter collection. Used as the base clas for the Or and AND filters
20   */
21  
22  public abstract class AbstractFilterCollection implements Filter
23  {
24      private List<Filter> filters;
25  
26      public AbstractFilterCollection()
27      {
28          filters = new ArrayList<Filter>();
29      }
30  
31      public AbstractFilterCollection(List<Filter> filters)
32      {
33          this();
34          this.filters = filters;
35      }
36  
37      public AbstractFilterCollection(Filter... filters)
38      {
39          this();
40          for (int i = 0; i < filters.length; i++)
41          {
42              this.filters.add(filters[i]);
43          }
44      }
45  
46      public List<Filter> getFilters()
47      {
48          return filters;
49      }
50  
51      public void setFilters(List<Filter> filters)
52      {
53          this.filters = filters;
54      }
55      
56      public boolean equals(Object obj)
57      {
58          if (this == obj) return true;
59          if (obj == null || getClass() != obj.getClass()) return false;
60  
61          final AbstractFilterCollection other = (AbstractFilterCollection) obj;
62          return ClassUtils.equal(filters, other.filters);
63      }
64  
65      public int hashCode()
66      {
67          return ClassUtils.hash(new Object[]{this.getClass(), filters});
68      }
69  
70  }