當前位置: 首頁>>代碼示例>>Java>>正文


Java Predicate類代碼示例

本文整理匯總了Java中org.apache.commons.collections4.Predicate的典型用法代碼示例。如果您正苦於以下問題:Java Predicate類的具體用法?Java Predicate怎麽用?Java Predicate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Predicate類屬於org.apache.commons.collections4包,在下文中一共展示了Predicate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: validate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Validate the predicates to ensure that all is well.
 *
 * @param predicates  the predicates to validate
 * @return predicate array
 */
static <T> Predicate<? super T>[] validate(final Collection<? extends Predicate<? super T>> predicates) {
    if (predicates == null) {
        throw new NullPointerException("The predicate collection must not be null");
    }
    // convert to array like this to guarantee iterator() ordering
    @SuppressWarnings("unchecked") // OK
    final Predicate<? super T>[] preds = new Predicate[predicates.size()];
    int i = 0;
    for (final Predicate<? super T> predicate : predicates) {
        preds[i] = predicate;
        if (preds[i] == null) {
            throw new NullPointerException(
                    "The predicate collection must not contain a null predicate, index " + i + " was null");
        }
        i++;
    }
    return preds;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:25,代碼來源:FunctorUtils.java

示例2: find

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
private <T extends Abi.Entry> T find(Class<T> resultClass, final Abi.Entry.Type type, final Predicate<T> searchPredicate) {
    return (T) CollectionUtils.find(this, new Predicate<Abi.Entry>() {
        @Override
        public boolean evaluate(Abi.Entry entry) {
            return entry.type == type && searchPredicate.evaluate((T) entry);
        }
    });
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:9,代碼來源:Abi.java

示例3: filteredInputs

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
private List<Param> filteredInputs(final boolean indexed) {
    return select(inputs, new Predicate<Param>() {
        @Override
        public boolean evaluate(Param param) {
            return param.indexed == indexed;
        }
    });
}
 
開發者ID:talentchain,項目名稱:talchain,代碼行數:9,代碼來源:Abi.java

示例4: checkMoment

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
public boolean checkMoment(Date date) {
    if (calendar != null) {
        Period period = new Period(new DateTime(date), new Dur(0, 0, 0, 0));
        Predicate<CalendarComponent> periodRule = new PeriodRule<>(period);
        Filter<CalendarComponent> filter = new Filter<>(new Predicate[] {periodRule}, Filter.MATCH_ANY);
        Collection<CalendarComponent> events = filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
        if (events != null && !events.isEmpty()) {
            return true;
        }
    }
    return false;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:13,代碼來源:Calendar.java

示例5: ifClosure

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Factory method that performs validation.
 *
 * @param <E> the type that the closure acts on
 * @param predicate  predicate to switch on
 * @param trueClosure  closure used if true
 * @param falseClosure  closure used if false
 * @return the <code>if</code> closure
 * @throws NullPointerException if any argument is null
 */
public static <E> Closure<E> ifClosure(final Predicate<? super E> predicate,
                                       final Closure<? super E> trueClosure,
                                       final Closure<? super E> falseClosure) {
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    if (trueClosure == null || falseClosure == null) {
        throw new NullPointerException("Closures must not be null");
    }
    return new IfClosure<E>(predicate, trueClosure, falseClosure);
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:22,代碼來源:IfClosure.java

示例6: comparatorPredicate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Factory to create the comparator predicate
 *
 * @param <T> the type that the predicate queries
 * @param object  the object to compare to
 * @param comparator  the comparator to use for comparison
 * @param criterion  the criterion to use to evaluate comparison
 * @return the predicate
 * @throws NullPointerException if comparator or criterion is null
 */
public static <T> Predicate<T> comparatorPredicate(final T object, final Comparator<T> comparator,
                                                   final Criterion criterion) {
    if (comparator == null) {
        throw new NullPointerException("Comparator must not be null.");
    }
    if (criterion == null) {
        throw new NullPointerException("Criterion must not be null.");
    }
    return new ComparatorPredicate<T>(object, comparator, criterion);
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:21,代碼來源:ComparatorPredicate.java

示例7: evaluate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Evaluates the predicate returning true if only one decorated predicate
 * returns true.
 *
 * @param object  the input object
 * @return true if only one decorated predicate returns true
 */
public boolean evaluate(final T object) {
    boolean match = false;
    for (final Predicate<? super T> iPredicate : iPredicates) {
        if (iPredicate.evaluate(object)) {
            if (match) {
                return false;
            }
            match = true;
        }
    }
    return match;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:20,代碼來源:OnePredicate.java

示例8: ifTransformer

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Factory method that performs validation.
 *
 * @param <I>  input type for the transformer
 * @param <O>  output type for the transformer
 * @param predicate  predicate to switch on
 * @param trueTransformer  transformer used if true
 * @param falseTransformer  transformer used if false
 * @return the <code>if</code> transformer
 * @throws NullPointerException if either argument is null
 */
public static <I, O> Transformer<I, O> ifTransformer(final Predicate<? super I> predicate,
                                                     final Transformer<? super I, ? extends O> trueTransformer,
                                                     final Transformer<? super I, ? extends O> falseTransformer) {
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    if (trueTransformer == null || falseTransformer == null) {
        throw new NullPointerException("Transformers must not be null");
    }

    return new IfTransformer<I, O>(predicate, trueTransformer, falseTransformer);
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:24,代碼來源:IfTransformer.java

示例9: IfTransformer

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Constructor that performs no validation.
 * Use the static factory method <code>ifTransformer</code> if you want that.
 *
 * @param predicate  predicate to switch on, not null
 * @param trueTransformer  transformer used if true, not null
 * @param falseTransformer  transformer used if false, not null
 */
public IfTransformer(final Predicate<? super I> predicate,
    final Transformer<? super I, ? extends O> trueTransformer,
    final Transformer<? super I, ? extends O> falseTransformer) {

    super();
    iPredicate = predicate;
    iTrueTransformer = trueTransformer;
    iFalseTransformer = falseTransformer;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:18,代碼來源:IfTransformer.java

示例10: evaluate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Evaluates the predicate returning true if all predicates return true.
 *
 * @param object  the input object
 * @return true if all decorated predicates return true
 */
public boolean evaluate(final T object) {
    for (final Predicate<? super T> iPredicate : iPredicates) {
        if (!iPredicate.evaluate(object)) {
            return false;
        }
    }
    return true;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:15,代碼來源:AllPredicate.java

示例11: evaluate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Evaluates the predicate returning false if any stored predicate returns false.
 *
 * @param object  the input object
 * @return true if none of decorated predicates return true
 */
public boolean evaluate(final T object) {
    for (final Predicate<? super T> iPredicate : iPredicates) {
        if (iPredicate.evaluate(object)) {
            return false;
        }
    }
    return true;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:15,代碼來源:NonePredicate.java

示例12: evaluate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Evaluates the predicate returning true if any predicate returns true.
 *
 * @param object  the input object
 * @return true if any decorated predicate return true
 */
public boolean evaluate(final T object) {
    for (final Predicate<? super T> iPredicate : iPredicates) {
        if (iPredicate.evaluate(object)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:15,代碼來源:AnyPredicate.java

示例13: Builder

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Constructs a PredicatedCollectionBuilder with the specified Predicate.
 *
 * @param predicate  the predicate to use
 * @throws NullPointerException if predicate is null
 */
public Builder(final Predicate<? super E> predicate) {
    if (predicate == null) {
        throw new NullPointerException("Predicate must not be null");
    }
    this.predicate = predicate;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:13,代碼來源:PredicatedCollection.java

示例14: findField

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
public Value findField(final String fieldName){

        Value value;

        value = IterableUtils.find(this, new Predicate<Value>() {
            @Override
            public boolean evaluate(Value object) {
                return object.getMetadata().getName().equals(fieldName);
            }
        });

        return value;
    }
 
開發者ID:claudiodegio,項目名稱:dbsync,代碼行數:14,代碼來源:Record.java

示例15: transformedPredicate

import org.apache.commons.collections4.Predicate; //導入依賴的package包/類
/**
 * Factory to create the predicate.
 *
 * @param <T> the type that the predicate queries
 * @param transformer  the transformer to call
 * @param predicate  the predicate to call with the result of the transform
 * @return the predicate
 * @throws NullPointerException if the transformer or the predicate is null
 */
public static <T> Predicate<T> transformedPredicate(final Transformer<? super T, ? extends T> transformer,
                                                    final Predicate<? super T> predicate) {
    if (transformer == null) {
        throw new NullPointerException("The transformer to call must not be null");
    }
    if (predicate == null) {
        throw new NullPointerException("The predicate to call must not be null");
    }
    return new TransformedPredicate<T>(transformer, predicate);
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:20,代碼來源:TransformedPredicate.java


注:本文中的org.apache.commons.collections4.Predicate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。