001package com.hammurapi.extract; 002 003 004/** 005 * Extractor which maps arguments to the target extractor. 006 * @author Pavel Vlasov 007 * 008 * @param <T> 009 * @param <V> 010 * @param <C> 011 */ 012public class MappedPredicate<T, C> extends MappedExtractor<T, Boolean, C> implements Predicate<T, C> { 013 014 /** 015 * @param target Target extractor 016 * @param map Index map, e.g. if it is {5, 3} then the first argument 017 * of this extractor becomes the sixth argument of the target extractor 018 * and the second argument of this extractor becomes the 4th argument 019 * of the target extractor. 020 */ 021 protected MappedPredicate(Predicate<T, C> target, int[] map) { 022 super(target, map); 023 } 024 025 public static <T,C> Predicate<T,C> mapPredicate(Predicate<T,C> target, int[] map) { 026 if (ComparisonResult.isOneToOneMapping(map)) { 027 return target; 028 } 029 030 // Target is not index-dependent (e.g. constant). 031 if (target.parameterIndices().isEmpty()) { 032 return target; 033 } 034 if (target instanceof Mappable) { 035 @SuppressWarnings("unchecked") 036 Extractor<T, Boolean, C> ret = ((Mappable<T,Boolean,C>) target).map(map); 037 if (ret!=null) { 038 return ExtractorUtil.wrap(ret); 039 } 040 } 041 042 return new MappedPredicate<T, C>(target, map); 043 } 044 045 046}