package com.hammurapi.extract;

import java.util.Collection;


/**
 * Predicate which is a composition of other predicates, e.g. AND or OR operations.
 * @author Pavel Vlasov.
 *
 * @param <T>
 * @param <PC> Parts collection type.
 * @param <C> Context type.
 */
public 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 {

	/**
	 * @return Sub-predicates.
	 */
	PC getParts();
	
	/**
	 * @param part
	 * @return Returns composite predicate of the same type without given part.
	 * If there is one remaining part then this part is returned.
	 */
	Predicate<T, C> remove(Predicate<T, C> part);
	
	/**
	 * Normalizes predicate by removing less restrictive parts in AND or more restrictive parts in OR,
	 * and analyzing if predicate is always TRUE or always FALSE. 
	 * @return Normalized predicate, True if predicate always evaluates to true, False if predicate always
	 * evaluates to false. 
	 */
	Predicate<T, C> normalize();
	
	S add(Predicate<T, C> part);
	
}
