-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.spreadsheet.common.matrix;\r
-\r
-import java.io.Externalizable;\r
-import java.io.IOException;\r
-import java.io.ObjectInput;\r
-import java.io.ObjectOutput;\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.simantics.spreadsheet.Matrix;\r
-\r
-public class MatrixImpl implements Matrix, Externalizable {\r
-\r
- private int rows;\r
- private int columns;\r
- private Object[] data;\r
- \r
- public MatrixImpl() {\r
- \r
- }\r
- \r
- public MatrixImpl(int rows, int columns) {\r
- this.rows = rows;\r
- this.columns = columns;\r
- this.data = new Object[rows*columns];\r
- }\r
-\r
- @Override\r
- public int getColumnCount() {\r
- return columns;\r
- }\r
-\r
- @Override\r
- public int getRowCount() {\r
- return rows;\r
- }\r
-\r
- @Override\r
- public void readExternal(ObjectInput in) throws IOException,\r
- ClassNotFoundException {\r
- rows = in.readInt();\r
- columns = in.readInt();\r
- data = new Object[rows*columns];\r
- for(int i=0;i<data.length;i++) data[i] = in.readObject();\r
- }\r
-\r
- @Override\r
- public void writeExternal(ObjectOutput out) throws IOException {\r
- out.writeInt(rows);\r
- out.writeInt(columns);\r
- for(Object o : data) out.writeObject(o);\r
- }\r
-\r
- @Override\r
- public Object get(int row, int column) {\r
- return data[column*rows + row];\r
- }\r
- \r
- public void setColumn(int column, Collection<Object> objects) {\r
- int index = rows*column;\r
- for(Object o : objects) {\r
- data[index++] = o;\r
- }\r
- }\r
-\r
- public void set(int row, int column, Object object) {\r
- data[rows*column + row] = object;\r
- }\r
-\r
- public Collection<Object> getColumn(int column) {\r
- ArrayList<Object> result = new ArrayList<Object>();\r
- for(int i=0;i<rows;i++) {\r
- result.add(data[rows*column+i]);\r
- }\r
- return result;\r
- }\r
-\r
- public Collection<Object> getRow(int row) {\r
- ArrayList<Object> result = new ArrayList<Object>();\r
- for(int i=0;i<columns;i++) {\r
- result.add(data[row + columns*i]);\r
- }\r
- return result;\r
- }\r
- \r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.spreadsheet.common.matrix;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.simantics.spreadsheet.Matrix;
+
+public class MatrixImpl implements Matrix, Externalizable {
+
+ private int rows;
+ private int columns;
+ private Object[] data;
+
+ public MatrixImpl() {
+
+ }
+
+ public MatrixImpl(int rows, int columns) {
+ this.rows = rows;
+ this.columns = columns;
+ this.data = new Object[rows*columns];
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columns;
+ }
+
+ @Override
+ public int getRowCount() {
+ return rows;
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException,
+ ClassNotFoundException {
+ rows = in.readInt();
+ columns = in.readInt();
+ data = new Object[rows*columns];
+ for(int i=0;i<data.length;i++) data[i] = in.readObject();
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeInt(rows);
+ out.writeInt(columns);
+ for(Object o : data) out.writeObject(o);
+ }
+
+ @Override
+ public Object get(int row, int column) {
+ return data[column*rows + row];
+ }
+
+ public void setColumn(int column, Collection<Object> objects) {
+ int index = rows*column;
+ for(Object o : objects) {
+ data[index++] = o;
+ }
+ }
+
+ public void set(int row, int column, Object object) {
+ data[rows*column + row] = object;
+ }
+
+ public Collection<Object> getColumn(int column) {
+ ArrayList<Object> result = new ArrayList<Object>();
+ for(int i=0;i<rows;i++) {
+ result.add(data[rows*column+i]);
+ }
+ return result;
+ }
+
+ public Collection<Object> getRow(int row) {
+ ArrayList<Object> result = new ArrayList<Object>();
+ for(int i=0;i<columns;i++) {
+ result.add(data[row + columns*i]);
+ }
+ return result;
+ }
+
+}