Author: wizard of ozwizard of oz
Date: Aug 28, 2008 22:11
I'm trying to write a data class using generics. This class is a Sparse
Matrix meaning that it can have many dimensions but not many entries (e.g. a
100 by 100 matrix, but there might only be 10 entries in the matrix).
I intend to use LinkedLists or Trees to manage the row and column keys and
probably a hash Map to manage the cells - but that's not important right
now.
My first step is that in my add method, I need to ensure that my row and
column keys are in my list. I would like to use one common routine for this.
The problem is I can't figure out the right generics syntax.
Here is what I started with:
public class SparseMatrix {
private TreeSet rowHeaders = new TreeSet ();
private TreeSet colHeaders = new TreeSet ();
public void add (R rowKey, C colKey, E element) {
ensureExists (rowHeaders, rowKey);
ensureExists (colHeaders, colKey);
}
|