1
# See bottom of file for license and copyright information
4
---+ package Foswiki::AggregateIterator
5
*implements* Foswiki::Iterator
7
Combine multiple iterators into a single iteration.
11
package Foswiki::AggregateIterator;
12
use base 'Foswiki::Iterator';
18
---++ new(\@list, $unique)
20
Create a new iterator over the given list of iterators. The list is
21
not damaged in any way.
23
If =$unique= is set, we try to not repeat values.
24
Warning: =$unique= assumes that the values are strings.
29
my ( $class, $list, $unique ) = @_;
48
---++ hasNext() -> $boolean
50
Returns false when the iterator is exhausted.
56
return 1 if $this->{next};
59
unless ( $this->{list} ) {
60
if ( $this->{Itr_index} < scalar( @{ $this->{Itr_list} } ) ) {
61
$this->{list} = $this->{Itr_list}->[ $this->{Itr_index}++ ];
64
return 0; #no more iterators in list
67
if ( $this->{list}->hasNext() ) {
68
$n = $this->{list}->next();
71
$this->{list} = undef; #goto next iterator
73
} while ( !$this->{list}
74
|| ( $this->{filter} && !&{ $this->{filter} }($n) )
75
|| ( $this->{unique} && !$this->unique($n) ) );
81
my ( $this, $value ) = @_;
83
unless ( defined( $this->{unique_hash}{$value} ) ) {
84
$this->{unique_hash}{$value} = 1;
95
Return the next entry in the list.
97
The iterator object can be customised to pre- and post-process entries from
98
the list before returning them. This is done by setting two fields in the
101
* ={filter}= can be defined to be a sub that filters each entry. The entry
102
will be ignored (next() will not return it) if the filter returns false.
103
* ={process}= can be defined to be a sub to process each entry before it
104
is returned by next. The value returned from next is the value returned
105
by the process function.
112
my $n = $this->{next};
113
$this->{next} = undef;
114
$n = &{ $this->{process} }($n) if $this->{process};
116
#print STDERR "next - $n \n";
122
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
124
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
125
# Foswiki Contributors are listed in the AUTHORS file in the root
126
# of this distribution. NOTE: Please extend that file, not this notice.
128
# Additional copyrights apply to some or all of the code in this
131
# Copyright (C) 2000-2007 TWiki Contributors. All Rights Reserved.
132
# TWiki Contributors are listed in the AUTHORS file in the root
133
# of this distribution. NOTE: Please extend that file, not this notice.
135
# This program is free software; you can redistribute it and/or
136
# modify it under the terms of the GNU General Public License
137
# as published by the Free Software Foundation; either version 2
138
# of the License, or (at your option) any later version. For
139
# more details read LICENSE in the root of this distribution.
141
# This program is distributed in the hope that it will be useful,
142
# but WITHOUT ANY WARRANTY; without even the implied warranty of
143
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
145
# As per the GPL, removal of this notice is prohibited.