Graph/ListSetEnumerator.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 10 totaltotal 0.0% 0 / 86 CC 2 SCAR 9.3
CC
2
Cov
0%
getNextElement
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.5
1 package Bio::GMOD::Blast::Graph::ListSetEnumerator;
2 BEGIN {
3 $Bio::GMOD::Blast::Graph::ListSetEnumerator::AUTHORITY = 'cpan:RBUELS';
4 }
5 BEGIN {
6 $Bio::GMOD::Blast::Graph::ListSetEnumerator::VERSION = '0.06';
7 }
8 #####################################################################
9 #
10 # Cared for by Shuai Weng <shuai@genome.stanford.edu>
11 #
12 # Originally created by John Slenk <jces@genome.stanford.edu>
13 #
14 # You may distribute this module under the same terms as perl itself
15 #-----------------------------------------------------------------
16  
17 use Bio::GMOD::Blast::Graph::BaseObj;
18 use Bio::GMOD::Blast::Graph::MyUtils;
19 use Bio::GMOD::Blast::Graph::MyDebug qw( dmsg dmsgs );
20 use Bio::GMOD::Blast::Graph::List;
21  
22 @ISA = qw( Bio::GMOD::Blast::Graph::BaseObj );
23  
24 my $kListSet = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "list", "set" );
25 my $kIndex = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "index" );
26 my $kKeys = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "key" );
27 my $kMaxDex = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "max", "dex" );
28  
29 #####################################################################
30 sub init {
31 #####################################################################
32 my( $self, $listSet ) = @_;
33 my( @keys );
34  
35 $self->{ $kListSet } = $listSet;
36 $self->{ $kIndex } = -1;
37 @keys = sort $listSet->getKeys();
38 #dmsg( "init(): keys = (", join( ", ", @keys ), ")" );
39 $self->{ $kMaxDex } = scalar( @keys ) - 1;
40 $self->{ $kKeys } = \@keys;
41 #dmsgs( "init(): $listSet ", $self->{$kMaxDex}, @{$self->{$kKeys}} );
42 }
43  
44 #####################################################################
45 sub getCurrentKey {
46 #####################################################################
47 my( $self ) = shift;
48 my( $dex );
49 my( $key );
50  
51 $dex = $self->getIndex();
52 $key = $self->getKey( $dex );
53  
54 return( $key );
55 }
56  
57 #####################################################################
58 sub getNextElement {
59 #####################################################################
60 my( $self ) = shift;
61 my( $elem );
62 my( $dex );
63 my( $key );
64 my( $maxDex );
65  
66 $elem = undef;
67 $dex = $self->getIndex();
68 $maxDex = $self->getMaxIndex();
69  
70 # have to pre-index so getCurrentKey() will work.
71 $self->putIndex( ++$dex );
72  
73 if( $dex <= $maxDex )
74 {
75 $key = $self->getKey( $dex );
76 $elem = $self->getListSet()->getListAt( $key );
77 #dmsg( "getNextElement(): $dex $key $elem" );
78 }
79  
80 return( $elem );
81 }
82  
83 #####################################################################
84 sub getListSet {
85 #####################################################################
86 my( $self ) = shift;
87 return( $self->{ $kListSet } );
88 }
89  
90 #####################################################################
91 sub getKey {
92 #####################################################################
93 my( $self, $dex ) = @_;
94 my( $key );
95  
96 $key = $ { $self->{ $kKeys } } [ $dex ];
97  
98 return( $key );
99 }
100  
101 #####################################################################
102 sub getMaxIndex {
103 #####################################################################
104 my( $self ) = shift;
105 return( $self->{ $kMaxDex } );
106 }
107  
108 #####################################################################
109 sub getIndex {
110 #####################################################################
111 my( $self ) = shift;
112 return( $self->{ $kIndex } );
113 }
114  
115 #####################################################################
116 sub putIndex {
117 #####################################################################
118 my( $self, $dex ) = @_;
119 $self->{ $kIndex } = $dex;
120 }
121 #####################################################################
122 1;
123 #####################################################################
124  
125 __END__