predicate

How to negate a method reference predicate

血红的双手。 提交于 2019-11-26 04:07:54
问题 In Java 8, you can use a method reference to filter a stream, for example: Stream<String> s = ...; long emptyStrings = s.filter(String::isEmpty).count(); Is there a way to create a method reference that is the negation of an existing one, i.e. something like: long nonEmptyStrings = s.filter(not(String::isEmpty)).count(); I could create the not method like below but I was wondering if the JDK offered something similar. static <T> Predicate<T> not(Predicate<T> p) { return o -> !p.test(o); } 回答1

How to convert a String to its equivalent LINQ Expression Tree?

ぐ巨炮叔叔 提交于 2019-11-26 03:27:27
问题 This is a simplified version of the original problem. I have a class called Person: public class Person { public string Name { get; set; } public int Age { get; set; } public int Weight { get; set; } public DateTime FavouriteDay { get; set; } } ...and lets say an instance: var bob = new Person { Name = \"Bob\", Age = 30, Weight = 213, FavouriteDay = \'1/1/2000\' } I would like to write the following as a string in my favourite text editor.... (Person.Age > 3 AND Person.Weight > 50) OR Person