Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 215 |  | Methods: | 20
| NCLOC: | 120 |  | 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
AbstractNamedMatrix.java | 63.6% | 68% | 80% | 69.6% |

1 |  |
     package baseCode.dataStructure.matrix;
2 |  |
3 |  |
     import java.util.Iterator;
4 |  |
     import java.util.LinkedHashMap;
5 |  |
     import java.util.List;
6 |  |
     import java.util.Map;
7 |  |
     import java.util.Vector;
8 |  |
9 |  |
     /**
10 |  |
      * <p>
11 |  |
      * Copyright (c) 2004 Columbia University
12 |  |
      *
13 |  |
      * @author pavlidis
14 |  |
      * @version $Id: AbstractNamedMatrix.java,v 1.7 2005/03/18 02:53:38 pavlidis Exp $
15 |  |
      */
16 |  |
     public abstract class AbstractNamedMatrix implements NamedMatrix {
17 |  |
18 |  |
        private Vector rowNames;
19 |  |
        private Vector colNames;
20 |  |
        private Map rowMap; //contains a map of each row and elements in the row
21 |  |
        private Map colMap;
22 |  |
23 |  |
        private int lastColumnIndex = 0;
24 |  |
        private int lastRowIndex = 0;
25 |  |
26 |  |
        /**
27 |  |
         *
28 |  |
         *
29 |  |
         */
30 | 279 |
        public AbstractNamedMatrix() {
31 | 279 |
           rowMap = new LinkedHashMap(); //contains a map of each row name to index
32 |  |
           // of the row.
33 | 279 |
           colMap = new LinkedHashMap();
34 | 279 |
           rowNames = new Vector();
35 | 279 |
           colNames = new Vector();
36 |  |
        }
37 |  |
38 |  |
        /**
39 |  |
         * Add a column name when we don't care what the index will be. The index will be set by the method. This is useful
40 |  |
         * for when we need to set up a matrix before we know how many column or rows there are.
41 |  |
         *
42 |  |
         * @param s
43 |  |
         */
44 | 0 |
        public final void addColumnName( String s ) {
45 |  |
46 | 0 |
           if ( colMap.containsKey( s ) ) {
47 | 0 |
              throw new IllegalArgumentException( "Duplicate column name " + s );
48 |  |
           }
49 |  |
50 | 0 |
           this.colNames.add( s );
51 | 0 |
           this.colMap.put( s, new Integer( lastColumnIndex ) );
52 | 0 |
           lastColumnIndex++;
53 |  |
54 |  |
        }
55 |  |
56 | 5049 |
        public final void addColumnName( String s, int i ) {
57 |  |
58 | 5049 |
           if ( colMap.containsKey( s ) ) {
59 | 0 |
              throw new IllegalArgumentException( "Duplicate column name " + s );
60 |  |
           }
61 |  |
62 | 5049 |
           this.colNames.add( s );
63 | 5049 |
           this.colMap.put( s, new Integer( i ) );
64 |  |
        }
65 |  |
66 |  |
        /**
67 |  |
         * Add a row name when we don't care what the index will be. The index will be set by the method. This is useful for
68 |  |
         * when we need to set up a matrix before we know how many column or rows there are.
69 |  |
         *
70 |  |
         * @param s
71 |  |
         */
72 | 0 |
        public final void addRowName( String s ) {
73 |  |
74 | 0 |
           if ( rowMap.containsKey( s ) ) {
75 |  |
              //     throw new IllegalArgumentException("Duplicate row name " + s);
76 | 0 |
              return;
77 |  |
           }
78 |  |
79 | 0 |
           this.rowNames.add( s );
80 | 0 |
           this.rowMap.put( s, new Integer( lastRowIndex ) );
81 | 0 |
           lastRowIndex++;
82 |  |
        }
83 |  |
84 |  |
        /*
85 |  |
         * (non-Javadoc)
86 |  |
         *
87 |  |
         * @see baseCode.dataStructure.NamedMatrix#addRowName(java.lang.String, int)
88 |  |
         */
89 | 9292 |
        public final void addRowName( String s, int i ) {
90 |  |
91 | 9292 |
           if ( rowMap.containsKey( s ) ) {
92 |  |
              //      throw new IllegalArgumentException("Duplicate row name " + s);
93 | 0 |
              return;
94 |  |
           }
95 |  |
96 | 9292 |
           this.rowNames.add( s );
97 | 9292 |
           this.rowMap.put( s, new Integer( i ) );
98 |  |
        }
99 |  |
100 |  |
        /**
101 |  |
         * @param s String
102 |  |
         * @return int
103 |  |
         */
104 | 4263 |
        public final int getRowIndexByName( String s ) {
105 | 4263 |
           if ( !rowNames.contains( s ) ) {
106 | 0 |
              throw new IllegalArgumentException( s + " not found" );
107 |  |
           }
108 |  |
109 | 4263 |
           return ( ( Integer ) rowMap.get( s ) ).intValue();
110 |  |
        }
111 |  |
112 |  |
        /**
113 |  |
         * @param r String
114 |  |
         * @return int
115 |  |
         */
116 | 4260 |
        public final int getColIndexByName( String r ) {
117 | 4260 |
           if ( !colNames.contains( r ) ) {
118 | 0 |
              throw new IllegalArgumentException( r + " not found" );
119 |  |
           }
120 |  |
121 | 4260 |
           return ( ( Integer ) this.colMap.get( r ) ).intValue();
122 |  |
        }
123 |  |
124 |  |
        /**
125 |  |
         * @param i int
126 |  |
         * @return java.lang.String
127 |  |
         */
128 | 2493 |
        public final String getRowName( int i ) {
129 | 2493 |
           return ( String ) rowNames.get( i );
130 |  |
        }
131 |  |
132 |  |
        /**
133 |  |
         * @param i int
134 |  |
         * @return java.lang.String
135 |  |
         */
136 | 3930 |
        public final String getColName( int i ) {
137 | 3930 |
           return ( String ) colNames.get( i );
138 |  |
        }
139 |  |
140 | 1770 |
        public final boolean hasRowNames() {
141 | 1770 |
           return rowNames.size() == rows();
142 |  |
        }
143 |  |
144 | 10 |
        public final boolean hasColNames() {
145 | 10 |
           return colNames.size() == columns();
146 |  |
        }
147 |  |
148 | 270 |
        public final void setRowNames( List v ) {
149 | 270 |
           for ( int i = 0; i < v.size(); i++ ) {
150 | 7510 |
              addRowName( ( String ) v.get( i ), i );
151 |  |
           }
152 |  |
        }
153 |  |
154 | 270 |
        public final void setColumnNames( List v ) {
155 | 270 |
           for ( int i = 0; i < v.size(); i++ ) {
156 | 3267 |
              addColumnName( ( String ) v.get( i ), i );
157 |  |
           }
158 |  |
        }
159 |  |
160 | 40 |
        public final List getColNames() {
161 | 40 |
           return colNames;
162 |  |
        }
163 |  |
164 | 3 |
        public final List getRowNames() {
165 | 3 |
           return rowNames;
166 |  |
        }
167 |  |
168 | 0 |
        public final boolean hasRow( String r ) {
169 | 0 |
           return this.rowMap.containsKey( r );
170 |  |
        }
171 |  |
172 | 0 |
        public final Iterator getRowNameMapIterator() {
173 | 0 |
           return this.rowMap.keySet().iterator();
174 |  |
        }
175 |  |
176 |  |
        public abstract int rows();
177 |  |
178 |  |
        public abstract int columns();
179 |  |
180 |  |
        public abstract void set( int i, int j, Object val );
181 |  |
182 |  |
        public abstract Object[] getRowObj( int i );
183 |  |
184 |  |
        public abstract Object[] getColObj( int i );
185 |  |
186 |  |
        public abstract boolean isMissing( int i, int j );
187 |  |
188 | 184 |
        public final boolean containsRowName( String rowName ) {
189 | 184 |
           return rowNames.contains( rowName );
190 |  |
        }
191 |  |
192 | 2164 |
        public final boolean containsColumnName( String columnName ) {
193 | 2164 |
           return colNames.contains( columnName );
194 |  |
        }
195 |  |
196 |  |
        /*
197 |  |
         * (non-Javadoc)
198 |  |
         *
199 |  |
         * @see baseCode.dataStructure.NamedMatrix#numMissing()
200 |  |
         */
201 | 1 |
        public int numMissing() {
202 | 1 |
           int count = 0;
203 | 1 |
           int n = this.rows();
204 | 1 |
           int m = this.columns();
205 | 1 |
           for ( int i = 0; i < n; i++ ) {
206 | 30 |
              for ( int j = 0; j < m; j++ ) {
207 | 360 |
                 if ( isMissing( i, j ) ) {
208 | 77 |
                    count++;
209 |  |
                 }
210 |  |
              }
211 |  |
           }
212 | 1 |
           return count;
213 |  |
        }
214 |  |
215 |  |
     }