01: /* TableNameToTablePredicateAdapter.java
02: *
03: * DDSteps - Data Driven JUnit Test Steps
04: * Copyright (C) 2005 Jayway AB
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License version 2.1 as published by the Free Software Foundation.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, visit
17: * http://www.opensource.org/licenses/lgpl-license.php
18: */
19: package org.ddsteps.dataset.decorator;
20:
21: import org.apache.commons.collections.Predicate;
22: import org.apache.commons.lang.Validate;
23: import org.ddsteps.dataset.DataTable;
24:
25: /**
26: * Filter tables by name using a predicate which takes table names.
27: *
28: * @author Adam
29: * @version $Id: TableNameToTablePredicateAdapter.java,v 1.2 2006/01/31 11:50:57 marthursson Exp $
30: */
31: public class TableNameToTablePredicateAdapter implements Predicate {
32:
33: final Predicate dataTableNamePredicate;
34:
35: /**
36: * Constructor for injecting a name predicate.
37: *
38: * @param namePredicate Predicate for String, name of dataTable
39: */
40: public TableNameToTablePredicateAdapter(Predicate namePredicate) {
41: super ();
42: Validate.notNull(namePredicate);
43: this .dataTableNamePredicate = namePredicate;
44: }
45:
46: /**
47: * Check the name of the table against the inner predicate.
48: * @see Predicate#evaluate(java.lang.Object)
49: */
50: public boolean evaluate(Object arg0) {
51: Validate.notNull(arg0, "Argument must not be null");
52: Validate.isTrue(arg0 instanceof DataTable,
53: "Argument must be a DataTable");
54:
55: DataTable table = (DataTable) arg0;
56: return dataTableNamePredicate.evaluate(table.getName());
57: }
58: }
|