1 /***
2 * Copyright 2003-2010 Terracotta, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.pool.sizeof.filter;
18
19 import java.lang.reflect.Field;
20 import java.util.Collection;
21
22 /***
23 * Filter combining multiple filters
24 *
25 * @author Chris Dennis
26 */
27 public class CombinationSizeOfFilter implements SizeOfFilter {
28
29 private final SizeOfFilter[] filters;
30
31 /***
32 * Constructs a filter combining multiple ones
33 * @param filters the filters to combine
34 */
35 public CombinationSizeOfFilter(SizeOfFilter... filters) {
36 this.filters = filters;
37 }
38
39 /***
40 * {@inheritDoc}
41 */
42 public Collection<Field> filterFields(Class<?> klazz, Collection<Field> fields) {
43 Collection<Field> current = fields;
44 for (SizeOfFilter filter : filters) {
45 current = filter.filterFields(klazz, current);
46 }
47 return current;
48 }
49
50 /***
51 * {@inheritDoc}
52 */
53 public boolean filterClass(Class<?> klazz) {
54 for (SizeOfFilter filter : filters) {
55 if (!filter.filterClass(klazz)) {
56 return false;
57 }
58 }
59 return true;
60 }
61 }