本文整理汇总了C#中Predicate.evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# Predicate.evaluate方法的具体用法?C# Predicate.evaluate怎么用?C# Predicate.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Predicate
的用法示例。
在下文中一共展示了Predicate.evaluate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: find
/**
* Finds the first element in the given collection which matches the given predicate.
* <p>
* If the input collection or predicate is null, or no element of the collection
* matches the predicate, null is returned.
*
* @param collection the collection to search, may be null
* @param predicate the predicate to use, may be null
* @return the first element of the collection which matches the predicate or null if none could be found
*/
public static Object find(java.util.Collection<Object> collection, Predicate predicate)
{
if (collection != null && predicate != null)
{
for (java.util.Iterator<Object> iter = collection.iterator(); iter.hasNext(); )
{
Object item = iter.next();
if (predicate.evaluate(item))
{
return item;
}
}
}
return null;
}
示例2: filter
/**
* Filter the collection by applying a Predicate to each element. If the
* predicate returns false, remove the element.
* <p>
* If the input collection or predicate is null, there is no change made.
*
* @param collection the collection to get the input from, may be null
* @param predicate the predicate to use as a filter, may be null
*/
public static void filter(java.util.Collection<Object> collection, Predicate predicate)
{
if (collection != null && predicate != null)
{
for (java.util.Iterator<Object> it = collection.iterator(); it.hasNext(); )
{
if (predicate.evaluate(it.next()) == false)
{
it.remove();
}
}
}
}
示例3: countMatches
/**
* Counts the number of elements in the input collection that match the predicate.
* <p>
* A <code>null</code> collection or predicate matches no elements.
*
* @param inputCollection the collection to get the input from, may be null
* @param predicate the predicate to use, may be null
* @return the number of matches for the predicate in the collection
*/
public static int countMatches(java.util.Collection<Object> inputCollection, Predicate predicate)
{
int count = 0;
if (inputCollection != null && predicate != null)
{
for (java.util.Iterator<Object> it = inputCollection.iterator(); it.hasNext(); )
{
if (predicate.evaluate(it.next()))
{
count++;
}
}
}
return count;
}
示例4: exists
/**
* Answers true if a predicate is true for at least one element of a collection.
* <p>
* A <code>null</code> collection or predicate returns false.
*
* @param collection the collection to get the input from, may be null
* @param predicate the predicate to use, may be null
* @return true if at least one element of the collection matches the predicate
*/
public static bool exists(java.util.Collection<Object> collection, Predicate predicate)
{
if (collection != null && predicate != null)
{
for (java.util.Iterator<Object> it = collection.iterator(); it.hasNext(); )
{
if (predicate.evaluate(it.next()))
{
return true;
}
}
}
return false;
}
示例5: selectRejected
/**
* Selects all elements from inputCollection which don't match the given predicate
* and adds them to outputCollection.
* <p>
* If the input predicate is <code>null</code>, no elements are added to <code>outputCollection</code>.
*
* @param inputCollection the collection to get the input from, may be null
* @param predicate the predicate to use, may be null
* @param outputCollection the collection to output into, may not be null
*/
public static void selectRejected(java.util.Collection<Object> inputCollection, Predicate predicate, java.util.Collection<Object> outputCollection)
{
if (inputCollection != null && predicate != null)
{
for (java.util.Iterator<Object> iter = inputCollection.iterator(); iter.hasNext(); )
{
Object item = iter.next();
if (predicate.evaluate(item) == false)
{
outputCollection.add(item);
}
}
}
}