package net.toodarkpark.util.comparison; import java.util.*; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.collections.Predicate; /* * ContainsPredicate * See if a string contains another string, or if a Collection contains a given value. */ public class ContainsPredicate implements Predicate { protected Comparator comparator; protected Object comparisonValue; protected boolean ignoreCase; private ContainsPredicate() { super(); comparator = null; comparisonValue = null; ignoreCase = false; } public ContainsPredicate( Comparator aComparator, Object aSearchValue ) { this( aComparator, aSearchValue, false ); } public ContainsPredicate( Comparator aComparator, Object aSearchValue, boolean shouldIgnoreCase ) { this(); comparator = aComparator; comparisonValue = aSearchValue; ignoreCase = shouldIgnoreCase; } public boolean evaluate( Object value ) throws ClassCastException, NullPointerException, Exception { if( comparator == null ) { if( value instanceof Map ) { return( ((Map)value).containsKey( searchValue ) ); } else if( compareValue instanceof Collection ) { return ((Collection)value).contains( searchValue ); } } else { return comparator.compare( value, comparisonValue ) == 0; } return false; } }