1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package ubic.basecode.dataStructure.matrix;
20
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.LinkedHashMap;
24 import java.util.List;
25
26
27
28
29
30
31
32 public abstract class AbstractMatrix3D<R, C, S, V> implements Matrix3D<R, C, S, V> {
33 public LinkedHashMap<C, Integer> colMap;
34 public List<C> colNames;
35 public LinkedHashMap<R, Integer> rowMap;
36 public List<R> rowNames;
37 public LinkedHashMap<S, Integer> sliceMap;
38 public List<S> sliceNames;
39
40 public AbstractMatrix3D() {
41 colMap = new LinkedHashMap<C, Integer>();
42 rowMap = new LinkedHashMap<R, Integer>();
43 sliceMap = new LinkedHashMap<S, Integer>();
44 colNames = new ArrayList<C>();
45 rowNames = new ArrayList<R>();
46 sliceNames = new ArrayList<S>();
47 }
48
49 @Override
50 public final void addColumnName( C s, int index ) {
51 if ( colNames.contains( s ) ) return;
52 colMap.put( s, index );
53 colNames.add( s );
54 }
55
56 @Override
57 public final void addRowName( R s, int index ) {
58 if ( rowNames.contains( s ) ) return;
59 rowMap.put( s, index );
60 rowNames.add( s );
61
62 }
63
64 @Override
65 public final void addSliceName( S s, int index ) {
66 if ( sliceNames.contains( s ) ) return;
67 sliceMap.put( s, index );
68 sliceNames.add( s );
69 }
70
71 @Override
72 public abstract int columns();
73
74 @Override
75 public final boolean containsColumnName( Object columnName ) {
76 return colMap.containsKey( columnName );
77 }
78
79 @Override
80 public final boolean containsRowName( Object rowName ) {
81 return rowMap.containsKey( rowName );
82 }
83
84 @Override
85 public final boolean containsSliceName( Object sliceName ) {
86 return sliceMap.containsKey( sliceName );
87 }
88
89 @Override
90 public final int getColIndexByName( Object s ) {
91 Integer index = colMap.get( s );
92 if ( index == null ) throw new IllegalArgumentException( s + " not found" );
93 return index.intValue();
94 }
95
96 @Override
97 public C getColName( int i ) {
98 return colNames.get( i );
99 }
100
101 @Override
102 public Iterator<C> getColNameIterator() {
103 return colNames.iterator();
104 }
105
106 @Override
107 public List<C> getColNames() {
108 return colNames;
109 }
110
111 @Override
112 public int getRowIndexByName( R s ) {
113 Integer index = rowMap.get( s );
114 if ( index == null ) throw new IllegalArgumentException( s + " not found" );
115 return index.intValue();
116 }
117
118 @Override
119 public R getRowName( int i ) {
120 return rowNames.get( i );
121 }
122
123 @Override
124 public Iterator<R> getRowNameIterator() {
125 return rowMap.keySet().iterator();
126 }
127
128 @Override
129 public List<R> getRowNames() {
130 return rowNames;
131 }
132
133 @Override
134 public int getSliceIndexByName( S s ) {
135 Integer index = sliceMap.get( s );
136 if ( index == null ) throw new IllegalArgumentException( s + " not found" );
137 return index.intValue();
138 }
139
140 @Override
141 public S getSliceName( int i ) {
142 return sliceNames.get( i );
143 }
144
145 @Override
146 public Iterator<S> getSliceNameIterator() {
147 return sliceNames.iterator();
148 }
149
150 @Override
151 public List<S> getSliceNames() {
152 return sliceNames;
153 }
154
155 @Override
156 public boolean hasColNames() {
157 return columns() == colNames.size();
158 }
159
160 @Override
161 public boolean hasRow( Object r ) {
162 return rowMap.containsKey( r );
163 }
164
165 @Override
166 public boolean hasRowNames() {
167 return rows() == rowNames.size();
168 }
169
170 @Override
171 public boolean hasSliceNames() {
172 return slices() == sliceNames.size();
173 }
174
175 @Override
176 public abstract boolean isMissing( int slice, int row, int col );
177
178 @Override
179 public abstract int numMissing();
180
181 @Override
182 public abstract int rows();
183
184 @Override
185 public void setColumnNames( List<C> v ) {
186 colNames = v;
187 for ( int i = 0; i < v.size(); i++ )
188 colMap.put( v.get( i ), i );
189 }
190
191 @Override
192 public void setRowNames( List<R> v ) {
193 rowNames = v;
194 for ( int i = 0; i < v.size(); i++ )
195 rowMap.put( v.get( i ), i );
196 }
197
198 @Override
199 public void setSliceNames( List<S> v ) {
200 sliceNames = v;
201 for ( int i = 0; i < v.size(); i++ )
202 sliceMap.put( v.get( i ), i );
203 }
204
205 @Override
206 public abstract int slices();
207
208 }