mengdiwang / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

enhancement request: Predicates.viewOr( Iterable<...> ), .viewAnd( Iterable<...> ) #484

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The Predicates.or/and(Iterable<? extends Predicate<? super T>> predicates) 
methods make a defensive copy of the Iterable to ensure immutable (at least 
relative to the Iterable) behavior.

However, there are uses for having mutable behavior if the underlying Iterable 
is mutable.  I use my own straightforward wrapper to implement a predicate 
which does this, but it doesn't do any of other nice things that the assorted 
private classes in Predicates do.

Hence, I'm requesting viewOr(Iterable<? extends Predicate<? super T>> 
predicates) and viewAnd( ...etc...) methods be added to the Predicates utility 
class.  Other sensible names include orView, mutableOr, orMutable and similar 
for and.

Original issue reported on code.google.com by blank...@gmail.com on 19 Nov 2010 at 9:36

GoogleCodeExporter commented 9 years ago
Could you give an example of how you use a mutable Predicate?

Original comment by boppenh...@google.com on 21 Nov 2010 at 7:06

GoogleCodeExporter commented 9 years ago
Sure; I currently have a constraint problem where the constraints are 
represented by Predicates.  However, both individual constraints and the number 
of constraints dynamically change.  So, I'm using roughly the following:

MyOrPredicate<T> extends ForwardingSet<Predicate<T>> implements Predicate<T> {

 //...forwarding set stuff, etc

 public boolean apply(T input) {
  for (Predicate<T> p : this) if (p.apply(input)) return true;
  return false;
 }

}

and then

MyPredicate<T> constraints = new MyPredicate<T>();

// ... adjust which constraints are in the predicate

if (constraints.apply(thing)) // ... do some stuff

// ... more adjustment of constraints

etc.

Original comment by blank...@gmail.com on 21 Nov 2010 at 8:05

GoogleCodeExporter commented 9 years ago
I'm afraid I see these as far too "niche" for Guava.

Original comment by kevinb@google.com on 12 Jan 2011 at 10:47

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09