Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 98 |  | Methods: | 5
| NCLOC: | 58 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
RowNameFilter.java | 92.9% | 88.2% | 60% | 86.8% |

1 |  |
     /*
2 |  |
      * Created on Jun 16, 2004
3 |  |
      */
4 |  |
     package baseCode.dataFilter;
5 |  |
6 |  |
     import java.util.Set;
7 |  |
     import java.util.Vector;
8 |  |
9 |  |
     import baseCode.dataStructure.matrix.NamedMatrix;
10 |  |
11 |  |
     /**
12 |  |
      * Remove or retain rows that are on a list.
13 |  |
      *
14 |  |
      * @author Paul Pavlidis
15 |  |
      * @version $Id: RowNameFilter.java,v 1.10 2004/07/27 03:18:58 pavlidis Exp $
16 |  |
      */
17 |  |
     public class RowNameFilter extends AbstractFilter implements Filter {
18 |  |
19 |  |
        private boolean exclude = false;
20 |  |
        private Set filterNames;
21 |  |
22 |  |
        /**
23 |  |
         * @param namesToFilter
24 |  |
         * @param exclude Set to true if you want the list to indicate items to be skipped, rather than selected.
25 |  |
         */
26 | 2 |
        public RowNameFilter( Set namesToFilter, boolean exclude ) {
27 | 2 |
           this( namesToFilter );
28 | 2 |
           this.exclude = exclude;
29 |  |
        }
30 |  |
31 |  |
        /**
32 |  |
         * @param namesToFilter
33 |  |
         */
34 | 4 |
        public RowNameFilter( Set namesToFilter ) {
35 | 4 |
           filterNames = namesToFilter;
36 |  |
        }
37 |  |
38 | 0 |
        public RowNameFilter() {
39 | 0 |
           filterNames = null;
40 |  |
        }
41 |  |
42 | 0 |
        public void setFilterNames( Set namesToFilter, boolean exclude ) {
43 | 0 |
           this.filterNames = namesToFilter;
44 | 0 |
           this.exclude = exclude;
45 |  |
        }
46 |  |
47 |  |
        /**
48 |  |
         * Filter according to row names.
49 |  |
         *
50 |  |
         * @param data
51 |  |
         * @return
52 |  |
         */
53 | 4 |
        public NamedMatrix filter( NamedMatrix data ) {
54 | 4 |
           Vector MTemp = new Vector();
55 | 4 |
           Vector rowNames = new Vector();
56 | 4 |
           int numRows = data.rows();
57 | 4 |
           int numCols = data.columns();
58 | 4 |
           int numNeeded = filterNames.size();
59 | 4 |
           int kept = 0;
60 | 4 |
           for ( int i = 0; i < numRows; i++ ) {
61 | 120 |
              String name = data.getRowName( i );
62 |  |
63 |  |
              // apply the rules.
64 | 120 |
              if ( filterNames.contains( name ) ) {
65 | 16 |
                 if ( exclude ) {
66 | 8 |
                    continue;
67 |  |
                 }
68 | 8 |
                 MTemp.add( data.getRowObj( i ) );
69 | 8 |
                 rowNames.add( name );
70 | 8 |
                 kept++;
71 | 8 |
                 if ( kept >= numNeeded ) {
72 | 0 |
                    break; // no use in continuing.
73 |  |
                 }
74 |  |
              }
75 |  |
76 | 112 |
              if ( exclude ) {
77 | 52 |
                 MTemp.add( data.getRowObj( i ) );
78 | 52 |
                 rowNames.add( name );
79 | 52 |
                 kept++;
80 |  |
              }
81 |  |
           }
82 |  |
83 | 4 |
           NamedMatrix returnval = getOutputMatrix( data, MTemp.size(), numCols );
84 |  |
85 | 4 |
           for ( int i = 0; i < MTemp.size(); i++ ) {
86 | 60 |
              for ( int j = 0; j < numCols; j++ ) {
87 | 720 |
                 returnval.set( i, j, ( ( Object[] ) MTemp.get( i ) )[j] );
88 |  |
              }
89 |  |
           }
90 | 4 |
           returnval.setColumnNames( data.getColNames() );
91 | 4 |
           returnval.setRowNames( rowNames );
92 |  |
93 | 4 |
           log.info( "There are " + kept + " rows left after filtering." );
94 |  |
95 | 4 |
           return ( returnval );
96 |  |
        }
97 |  |
98 |  |
     }