Graph/List.pm untested

filter: Statementstmt 0.0% 0 / 99 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 20 Podpod 0.0% 0 / 16 totaltotal 0.0% 0 / 151 CC 9 SCAR 17.9
CC
9
Cov
0%
init
20.0
getElementAt
6.0
removeElement
6.0
CRAP 6.0
1 package Bio::GMOD::Blast::Graph::List;
2 BEGIN {
3 $Bio::GMOD::Blast::Graph::List::AUTHORITY = 'cpan:RBUELS';
4 }
5 BEGIN {
6 $Bio::GMOD::Blast::Graph::List::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::ListEnumerator;
21  
22 @ISA = qw( Bio::GMOD::Blast::Graph::BaseObj );
23  
24 #
25 # basically, just a wrapper so we can
26 # use it in ListSet a little more clearly.
27 # tho you cannot have undefs as elements of the list.
28 #
29  
30 my $kElements = Bio::GMOD::Blast::Graph::MyUtils::makeVariableName( "elements" );
31  
32 #########################################################################
33 sub init {
34 #########################################################################
35 my( $self, @ref ) = @_;
36  
37 # this sure is gross, but it seems to work.
38 # if( defined( @ref ) )
39 if( @ref )
40 {
41 if( ref( $ref[0] ) eq "ARRAY" )
42 {
43 #dmsg( "got reference to array" );
44 $self->{ $kElements } = $ref[0];
45 }
46 elsif( !ref( $ref[0] ) )
47 {
48 #dmsg( "got array itself" );
49 $self->{ $kElements } = \@ref;
50 }
51 }
52 else
53 {
54 #dmsg( "no ref given at all" );
55 $self->{ $kElements } = [];
56 }
57 }
58  
59 #########################################################################
60 sub getElementsRef{
61 #########################################################################
62 my( $self ) = shift;
63 return( $self->{ $kElements } );
64 }
65  
66 #########################################################################
67 sub putElementsRef {
68 #########################################################################
69 my( $self, $lref ) = @_;
70 $self->{ $kElements } = $lref;
71 }
72  
73 #########################################################################
74 sub addElement {
75 #########################################################################
76 my( $self, $elem ) = @_;
77 push( @{$self->getElementsRef}, $elem );
78 }
79  
80 # dex is zero based.
81 #########################################################################
82 sub getElementAt {
83 #########################################################################
84 my( $self, $dex ) = @_;
85 my( $ref );
86 my( $maxDex );
87 my( $elem );
88  
89 $elem = undef;
90 $maxDex = $self->getCount()-1;
91  
92 if( $dex <= $maxDex )
93 {
94 $ref = $self->getElementsRef();
95 $elem = $ { $ref } [ $dex ];
96 }
97  
98 return( $elem );
99 }
100  
101 #########################################################################
102 sub removeElement {
103 #########################################################################
104 my( $self, $elem ) = @_;
105 my( $ref );
106 my( $dex );
107 my( $test );
108  
109 $ref = $self->getElementsRef();
110 for( $dex = 0; $dex < $self->getCount(); $dex++ )
111 {
112 $test = $self->getElementAt( $dex );
113 last if( $test == $elem );
114 }
115  
116 splice( @{$ref}, $dex, 1 );
117 }
118  
119 #########################################################################
120 sub my_shift {
121 #########################################################################
122 my( $self ) = shift;
123 my( $val );
124  
125 $val = shift( @{$self->getElementsRef()} );
126 #dmsg( "shift(): $val" );
127 return( $val );
128 }
129  
130 #########################################################################
131 sub shiftSafe {
132 #########################################################################
133 my( $self ) = shift;
134 my( $val );
135  
136 if( $self->emptyP() )
137 {
138 $val = undef;
139 }
140 else
141 {
142 $val = $self->shift();
143 }
144  
145 return( $val );
146 }
147  
148 # return 1 based count.
149 #########################################################################
150 sub getCount {
151 #########################################################################
152 my( $self ) = shift;
153 my( $ref ) = $self->getElementsRef();
154 #dmsgs( "getCount(): ref = ", @{$ref} );
155 my( $count ) = scalar( @{$self->getElementsRef()} );
156 #dmsg( "getCount(): count = ", $count );
157 return( $count );
158 }
159  
160 #########################################################################
161 sub emptyP {
162 #########################################################################
163 my( $self ) = shift;
164 my( $emptyP );
165  
166 if( $self->getCount() == 0 )
167 {
168 $emptyP = 1;
169 }
170 else
171 {
172 $emptyP = 0;
173 }
174  
175 return( $emptyP );
176 }
177  
178 # [[ $sub is the fully qualified name of a sorter subroutine.
179 # that routine must refer to $List::a and $List::b to work;
180 # perl suck. ]]
181 # subclasses might override this to provide a fixed
182 # sorting method, which ignores any given subroutine.
183 #########################################################################
184 sub sort {
185 #########################################################################
186 my( $self, $sub ) = @_;
187 my( $lref );
188 my( @ray );
189  
190 $lref = $self->getElementsRef();
191  
192 @ray = sort $sub @{$lref};
193  
194 $self->putElementsRef( \@ray );
195 }
196  
197 # n is zero based.
198 # element at location n is also removed.
199 #########################################################################
200 sub truncateAt {
201 #########################################################################
202 my( $self, $n ) = @_;
203 my( $lref );
204  
205 if( $n < 0 )
206 {
207 $self->putElementsRef( [] );
208 }
209 else
210 {
211 $lref = $self->getElementsRef();
212 splice( @{$lref}, $n );
213 }
214 }
215  
216 #########################################################################
217 sub getEnumerator {
218 #########################################################################
219 my( $self ) = shift;
220 return( new Bio::GMOD::Blast::Graph::ListEnumerator( $self ) );
221 }
222  
223 #########################################################################
224 sub toString {
225 #########################################################################
226 my( $self ) = shift;
227 my( $str );
228  
229 $str = Bio::GMOD::Blast::Graph::MyUtils::makeDumpString($self,
230 $self->getCount,
231 @{$self->getElementsRef()});
232  
233 return( $str );
234 }
235 #########################################################################
236 1;
237 #########################################################################
238  
239 __END__