commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ola Berg" <ola.b...@ports.se>
Subject Re: [collections] Number of elements matching a Predicate
Date Mon, 25 Nov 2002 07:31:24 GMT
> http://issues.apache.org/bugzilla/show_bug.cgi?id=9422
> 
> Proposal is to add a method (or four) to return true if all/none/one or more
> of the elements match the predicate.
> 
> Anyone got any views on this? I'm minded to reject it as not adding enough
> to the API, eg.

I'd say one method:

/**
Returns the number of objects in the Collection c that matches the Predicate p.
*/
public static int countMatches( Collection c, Predicate p){
...
 }

boolean allMatch = (countMatches(c,p) == c.size())
boolean noMatch = (countMatches(c,p) == 0);
boolean anyMatch = (!noMatch);
boolean someButNotAllMatch = anyMatch && (!allMatch);
etc

Or actually two methods since we could have an Object[] version too:

public static int countMatches( Object[] objects, Predicate p)...

/O


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message