Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added two convenience methods for creating new matrices

  • Loading branch information...
commit ca4c6d3936378e670f300b82ae1c8894006d2c8d 1 parent 544ead2
Egon Willighagen authored
19 ...ins/net.bioclipse.statistics.business/src/net/bioclipse/statistics/business/business/IMatrixManager.java
@@ -10,9 +10,12 @@
10 10 ******************************************************************************/
11 11 package net.bioclipse.statistics.business.business;
12 12
  13 +import java.util.List;
  14 +
13 15 import net.bioclipse.core.PublishedClass;
14 16 import net.bioclipse.core.PublishedMethod;
15 17 import net.bioclipse.core.Recorded;
  18 +import net.bioclipse.core.business.BioclipseException;
16 19 import net.bioclipse.managers.business.IBioclipseManager;
17 20 import net.bioclipse.statistics.model.IMatrixResource;
18 21
@@ -39,6 +42,22 @@ public IMatrixResource create(
39 42
40 43 @Recorded
41 44 @PublishedMethod(methodSummary=
  45 + "Creates a new, empty matrix domain object."
  46 + )
  47 + public IMatrixResource empty();
  48 +
  49 + @Recorded
  50 + @PublishedMethod(
  51 + params="IMatrixResource matrix, List<String> values",
  52 + methodSummary="Adds a new row to the existing matrix. Throws an exception " +
  53 + "when the number of values is incompatible with the number of columns " +
  54 + "of the existing matrix."
  55 + )
  56 + public IMatrixResource addRow(IMatrixResource matrix, List<Double> values)
  57 + throws BioclipseException;
  58 +
  59 + @Recorded
  60 + @PublishedMethod(methodSummary=
42 61 "Sets the column labels of the matrix."
43 62 )
44 63 public void setColumnLabels(IMatrixResource matrix, String[] names);
23 plugins/net.bioclipse.statistics.business/src/net/bioclipse/statistics/business/business/MatrixManager.java
@@ -10,8 +10,10 @@
10 10 ******************************************************************************/
11 11 package net.bioclipse.statistics.business.business;
12 12
  13 +import java.util.List;
13 14 import java.util.StringTokenizer;
14 15
  16 +import net.bioclipse.core.business.BioclipseException;
15 17 import net.bioclipse.managers.business.IBioclipseManager;
16 18 import net.bioclipse.statistics.model.IMatrixResource;
17 19 import net.bioclipse.statistics.model.MatrixResource;
@@ -92,4 +94,25 @@ public void setRowLabels(IMatrixResource matrix, String[] names) {
92 94 }
93 95 }
94 96
  97 + public IMatrixResource empty() {
  98 + IMatrixResource matrix = new MatrixResource("", (IFileEditorInput)null);
  99 + matrix.setSize(0,0);
  100 + return matrix;
  101 + }
  102 +
  103 + public IMatrixResource addRow(IMatrixResource matrix, List<Double> values)
  104 + throws BioclipseException {
  105 + int row = matrix.getRowCount();
  106 + if (row != 0 && values.size() != matrix.getColumnCount())
  107 + throw new BioclipseException(
  108 + "The existing matrix has a different number of columns than " +
  109 + "the number of values in the List."
  110 + );
  111 +
  112 + row += 1;
  113 + for (int col=1; col<=values.size(); col++) {
  114 + matrix.set(row, col, values.get(col-1));
  115 + }
  116 + return matrix;
  117 + }
95 118 }

0 comments on commit ca4c6d3

Please sign in to comment.
Something went wrong with that request. Please try again.