commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Vernum <Tim.Ver...@macquarie.com>
Subject RE: [collections] Would like to contribute my RangeIterator
Date Tue, 30 Apr 2002 07:03:53 GMT

> final Predicate leftBoder = new Predicate() {
>       public boolean evaluate(Object input)
>       {
>            Member o = (Member)input;
>            return member.getAge() < 18;
>       }};
> 
> final Predicate rightBorder = new Predicate() {
>       public boolean evaluate(Object input)
>       {
>            Member o = (Member)input;
>            return member.getAge() > 65;
>       }
> 
> Iterator i = new RangeIterator(leftBoder, sourceiterator,
> rightBorder);

Isn't this just a PredicateIterator with a composite predicate ?

class AndPredicate extends Predicate
{
	private Predicate p1 , p2 ;

	AndPredicate( Predicate a, Predicate b )
	{
		p1 = a ;
		p2 = b ;
	}

	public boolean evaluate( Object input )
      {
          return p1.evaluate( input ) && p2.evaluate( input ) ;
      }
}

Iterator i = new PredicateIterator( sourceiterator , new AndIterator( leftBorder , rightBorder
) ) ;

(although the logic in your border predicates would need to be reversed in this case, or add
in
a NotPredicate)

Not sure how much of that is in Collections already, but really the RangeIterator is
just a specific PredicateIterator, just like the TypedList was really a PredicateList.


NOTICE
This e-mail and any attachments are confidential and may contain copyright material of Macquarie
Bank or third parties. If you are not the intended recipient of this email you should not
read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and
should destroy all copies of them. Macquarie Bank does not guarantee the integrity of any
emails or any attached files. The views or opinions expressed are the author's own and may
not reflect the views or opinions of Macquarie Bank. 


--
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