01: /* StringInArrayPredicate.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.util;
20:
21: import org.apache.commons.collections.Predicate;
22: import org.apache.commons.lang.ArrayUtils;
23: import org.apache.commons.lang.Validate;
24:
25: /**
26: * Predicate for checking if a string is in an array. Useful for filtering out
27: * certain DataTables from a DataSet.
28: *
29: * @author adam
30: * @version $Id: StringInArrayPredicate.java,v 1.1 2005/12/03 12:51:40
31: * adamskogman Exp $
32: */
33: public class StringInArrayPredicate implements Predicate {
34:
35: /**
36: * The array of strings.
37: */
38: protected final String[] stringArray;
39:
40: /**
41: * Dependency Injection constructor.
42: *
43: * @param array
44: * The String Array, not null, not empty.
45: */
46: public StringInArrayPredicate(String[] array) {
47: super ();
48: Validate.notEmpty(array, "String array must not be empty");
49: this .stringArray = array;
50: }
51:
52: /**
53: * True if the argument is a string and it is in the array
54: *
55: * @see org.apache.commons.collections.Predicate#evaluate(java.lang.Object)
56: */
57: public boolean evaluate(Object arg0) {
58: Validate.notNull(arg0, "Argument must not be null");
59: Validate.isTrue(arg0 instanceof String,
60: "Argument must be a String");
61:
62: String argument = (String) arg0;
63:
64: return ArrayUtils.contains(stringArray, argument);
65: }
66:
67: }
|