interface Matrix extends WidthAndHeight { public A get(int x, int y); public void set(int x, int y, A a); default Pt size() { ret pt(getWidth(), getHeight()); } default int nCells() { ret getWidth()*getHeight(); } default A get(Pt p) { ret get(p.x, p.y); } default void set aka put(Pt p, A a) { set(p.x, p.y, a); } // one row of the matrix as a virtual list (mutable) default L getLine(int y) { ret new RandomAccessAbstractList() { public int size() { ret getWidth(); } public A get(int x) { ret Matrix.this.get(x, y); } public A set(int x, A val) { A old = Matrix.this.get(x, y); Matrix.this.set(x, y, val); ret old; } }; } }