001package com.hammurapi.extract;
002
003import java.util.Collection;
004
005
006/**
007 * Predicate which is a composition of other predicates, e.g. AND or OR operations.
008 * @author Pavel Vlasov.
009 *
010 * @param <T>
011 * @param <PC> Parts collection type.
012 * @param <C> Context type.
013 */
014public interface CompositePredicate<T, PC extends Collection<Predicate<T, C>>, C, S extends CompositePredicate<T,PC,C,S>> extends Predicate<T, C>, FacadeExtractor<T,Boolean,C>, Mappable<T, Boolean, C>, Cloneable {
015
016        /**
017         * @return Sub-predicates.
018         */
019        PC getParts();
020        
021        /**
022         * @param part
023         * @return Returns composite predicate of the same type without given part.
024         * If there is one remaining part then this part is returned.
025         */
026        Predicate<T, C> remove(Predicate<T, C> part);
027        
028        /**
029         * Normalizes predicate by removing less restrictive parts in AND or more restrictive parts in OR,
030         * and analyzing if predicate is always TRUE or always FALSE. 
031         * @return Normalized predicate, True if predicate always evaluates to true, False if predicate always
032         * evaluates to false. 
033         */
034        Predicate<T, C> normalize();
035        
036        S add(Predicate<T, C> part);
037        
038}