predicates

C# method accepting a predicate - does this look ok?

I'd like a method that has the following API: //get all users with a role of admin var users = myRepository.GetUsers(u => u.Role == Role.Admin); Will something like this work? IList<User> GetUsers(Func<User, bool> predicate) { var users = GetAllUsers(); return users.Where(predicate).ToList(); ...

Java Object Question

Not quite sure how to word this question. I am wondering if there is a method to check certain parts of a custom java class to see if it matches a certain criteria. Such as this public Name(String forename, String middlename, String surname) And then when an array of instances of that class are created say, Name[] applicants = new N...

Can you use "parenthesis" on Predicate operations

I can't see any way to build a Predicate that uses parenthesis to control logical order. Is there one? Say I want to do something like Predicate <= mumble and (foo or baz) A simple Predicates.and or a Predicates.or has no equivalent that says "foo or baz" and with mumble. Is this possible? ...

how to delete elements from a transformed collection using a predicate?

If I have an ArrayList<Double> dblList and a Predicate<Double> IS_EVEN I am able to remov e all even elements from dblList using: Collections2.filter(dblList, IS_EVEN).clear() if dblList however is a result of a transformation like dblList = Lists.transform(intList, TO_DOUBLE) this does not work any more as the transformed list is...

Creating Dynamic Predicates- passing in property to a function as parameter

I am trying to create dynamic predicate so that it can be used against a list for filtering public class Feature { public string Color{get;set;} public string Weight{get;set;} } I want to be able to create a dynamic predicate so that a List can be filtered. I get few conditions as string values ">","<",">=" etc. Is there a wa...

HElp with converting to first order logic....

Using only these predicates..... child(X) X is a child unwell(X,Y) X is unwell on day Y location(X,Y,Z) Location of X on day Y is Z (school, park, home) sunny(X) X is a sunny day Generally, children do not go to school whenever they are unwell ∄x [Child(x) ∧ location(X,y,home) → Child(x) ∧ unwell(X,y)] Not s...

Turning remove_if into remove_not_if

How can I reverse a predicate's return value, and remove the elements that return false instead of true? Here is my code: headerList.remove_if(FindName(name)); (please ignore lack of erase) with FindName a simple functor: struct FindName { CString m_NameToFind; FindInspectionNames(const CString &nameToFind) { m...

XPath query with descendant and descendant text() predicates

I would like to construct an XPath query that will return a "div" or "table" element, so long as it has a descendant containing the text "abc". The one caveat is that it can not have any div or table descendants. <div> <table> <form> <div> <span> <p>abcdefg</p> </span> </div> <table> ...