1 package baseCode.dataStructure.matrix;
2
3 import cern.colt.matrix.ObjectMatrix1D;
4 import cern.colt.matrix.impl.DenseObjectMatrix2D;
5
6 /***
7 * A NamedMatrix containing String objects.
8 * <p>
9 * Copyright (c) 2004
10 * </p>
11 * <p>
12 * Institution: Columbia University
13 * </p>
14 *
15 * @author Paul Pavlidis
16 * @version $Id: StringMatrix2DNamed.java,v 1.2 2004/07/27 03:18:58 pavlidis Exp $
17 */
18 public class StringMatrix2DNamed extends AbstractNamedMatrix {
19
20 private DenseObjectMatrix2D matrix;
21
22 public StringMatrix2DNamed( int x, int y ) {
23 super();
24 matrix = new DenseObjectMatrix2D( x, y );
25 }
26
27 /***
28 * @return java.lang.String
29 */
30 public String toString() {
31 String result = "label";
32 for ( int i = 0; i < columns(); i++ ) {
33 result = result + "\t" + getColName( i );
34 }
35 result += "\n";
36
37 for ( int i = 0; i < rows(); i++ ) {
38 result += getRowName( i );
39 for ( int j = 0; j < columns(); j++ ) {
40 result = result + "\t" + get( i, j );
41 }
42 result += "\n";
43 }
44 return result;
45 }
46
47 public Object[] getRow( int row ) {
48 return viewRow( row ).toArray();
49 }
50
51 public Object[] getCol( int col ) {
52 String[] result = new String[rows()];
53 for ( int i = 0; i < rows(); i++ ) {
54 result[i] = ( String ) get( i, col );
55 }
56 return result;
57 }
58
59 public Object[] getRowObj( int row ) {
60 String[] result = new String[columns()];
61 for ( int i = 0; i < columns(); i++ ) {
62 result[i] = ( String ) get( row, i );
63 }
64 return result;
65 }
66
67 public Object[] getColObj( int col ) {
68 String[] result = new String[rows()];
69 for ( int i = 0; i < rows(); i++ ) {
70 result[i] = ( String ) get( i, col );
71 }
72 return result;
73 }
74
75 public boolean isMissing( int i, int j ) {
76 return get( i, j ) == "";
77 }
78
79 /***
80 * @return
81 */
82 public int columns() {
83 return matrix.columns();
84 }
85
86 /***
87 * @param row
88 * @param column
89 * @return
90 */
91 public Object get( int row, int column ) {
92 return matrix.get( row, column );
93 }
94
95 /***
96 * @param row
97 * @param column
98 * @return
99 */
100 public Object getQuick( int row, int column ) {
101 return matrix.getQuick( row, column );
102 }
103
104 /***
105 * @return
106 */
107 public int rows() {
108 return matrix.rows();
109 }
110
111 /***
112 * @return
113 */
114 public int size() {
115 return matrix.size();
116 }
117
118 /***
119 * @param column
120 * @return
121 */
122 public ObjectMatrix1D viewColumn( int column ) {
123 return matrix.viewColumn( column );
124 }
125
126 /***
127 * @param row
128 * @return
129 */
130 public ObjectMatrix1D viewRow( int row ) {
131 return matrix.viewRow( row );
132 }
133
134 /***
135 * @param row
136 * @param column
137 * @param value
138 */
139 public void set( int row, int column, Object value ) {
140 matrix.set( row, column, value );
141 }
142
143 /***
144 * @param row
145 * @param column
146 * @param value
147 */
148 public void setQuick( int row, int column, Object value ) {
149 matrix.setQuick( row, column, value );
150 }
151 }