From 08d5df9099ef177b3af41538de50a6246494df1d Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Tue, 17 Jul 2018 12:29:31 +0200 Subject: [PATCH 01/42] Temporarily add imagej-common dependency for migration --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index b747d01..c7f5fcb 100644 --- a/pom.xml +++ b/pom.xml @@ -103,6 +103,11 @@ Konstanz, and KNIME GmbH. scijava-common + + net.imagej + imagej-common + + junit From 9dd4a24b355a7dd822024853b8b98168759a8d28 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 18 Apr 2014 10:38:56 -0500 Subject: [PATCH 02/42] Add initial code, migrated from ij-core & ij-data See: https://github.com/imagej/imagej/tree/imagej-2.0.0-beta-7.9/core --- .../java/net/imagej/table/AbstractTable.java | 504 ++++++++++++++++++ src/main/java/net/imagej/table/Column.java | 60 +++ .../java/net/imagej/table/DefaultColumn.java | 65 +++ .../net/imagej/table/DefaultGenericTable.java | 60 +++ .../net/imagej/table/DefaultResultsTable.java | 89 ++++ .../net/imagej/table/DefaultTableDisplay.java | 53 ++ .../java/net/imagej/table/DoubleColumn.java | 64 +++ .../java/net/imagej/table/GenericColumn.java | 49 ++ .../java/net/imagej/table/GenericTable.java | 41 ++ .../java/net/imagej/table/ResultsImg.java | 243 +++++++++ .../java/net/imagej/table/ResultsTable.java | 53 ++ src/main/java/net/imagej/table/Table.java | 425 +++++++++++++++ .../java/net/imagej/table/TableDisplay.java | 43 ++ .../java/net/imagej/table/TableLoader.java | 208 ++++++++ .../imagej/table/DefaultResultsTableTest.java | 120 +++++ 15 files changed, 2077 insertions(+) create mode 100644 src/main/java/net/imagej/table/AbstractTable.java create mode 100644 src/main/java/net/imagej/table/Column.java create mode 100644 src/main/java/net/imagej/table/DefaultColumn.java create mode 100644 src/main/java/net/imagej/table/DefaultGenericTable.java create mode 100644 src/main/java/net/imagej/table/DefaultResultsTable.java create mode 100644 src/main/java/net/imagej/table/DefaultTableDisplay.java create mode 100644 src/main/java/net/imagej/table/DoubleColumn.java create mode 100644 src/main/java/net/imagej/table/GenericColumn.java create mode 100644 src/main/java/net/imagej/table/GenericTable.java create mode 100644 src/main/java/net/imagej/table/ResultsImg.java create mode 100644 src/main/java/net/imagej/table/ResultsTable.java create mode 100644 src/main/java/net/imagej/table/Table.java create mode 100644 src/main/java/net/imagej/table/TableDisplay.java create mode 100644 src/main/java/net/imagej/table/TableLoader.java create mode 100644 src/test/java/net/imagej/table/DefaultResultsTableTest.java diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java new file mode 100644 index 0000000..ff0ec38 --- /dev/null +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -0,0 +1,504 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import java.util.ArrayList; + +import org.scijava.util.SizableArrayList; + +/** + * Abstract superclass for {@link Table} implementations. + * + * @author Curtis Rueden + * @param The type of data stored in the table. + */ +public abstract class AbstractTable, T> extends + SizableArrayList implements Table +{ + + /** Header for each row in the table. Lazily populated. */ + private final SizableArrayList rowHeaders; + + /** Number of rows in the table. */ + private int rowCount; + + /** Creates an empty table. */ + public AbstractTable() { + this(0, 0); + } + + /** Creates a table with the given column and row dimensions. */ + public AbstractTable(final int colCount, final int rowCount) { + super(); + checkRowCount(rowCount); + rowHeaders = new SizableArrayList(); + this.rowCount = rowCount; + setColumnCount(colCount); + } + + // -- Table methods -- + + @Override + public int getColumnCount() { + return size(); + } + + @Override + public void setColumnCount(final int colCount) { + checkColCount(colCount); + setSize(colCount); + scaleColumns(); + } + + @Override + public C get(final String colHeader) { + return get(colIndex(colHeader)); + } + + @Override + public C appendColumn() { + return appendColumn(null); + } + + @Override + public C appendColumn(final String header) { + return insertColumn(getColumnCount(), header); + } + + @Override + public ArrayList appendColumns(final int count) { + final ArrayList result = new ArrayList(count); + for (int c = 0; c < count; c++) { + result.add(appendColumn()); + } + return result; + } + + @Override + public ArrayList appendColumns(final String... headers) { + final ArrayList result = new ArrayList(headers.length); + for (final String header : headers) { + result.add(appendColumn(header)); + } + return result; + } + + @Override + public C insertColumn(final int col) { + return insertColumn(col, null); + } + + @Override + public C insertColumn(final int col, final String header) { + final ArrayList result = insertColumns(col, 1); + setColumnHeader(col, header); + return result.get(0); + } + + @Override + public ArrayList insertColumns(final int col, final int count) { + checkCol(col, 0); + final int oldColCount = getColumnCount(); + final int newColCount = oldColCount + count; + + // expand columns list + setColumnCount(newColCount); + + // copy columns after the inserted range into the new position + for (int oldC = col; oldC < oldColCount; oldC++) { + final int newC = oldC + count; + set(newC, get(oldC)); + } + + // insert new blank columns + final ArrayList result = new ArrayList(count); + for (int c = 0; c < count; c++) { + final C column = createColumn(null); + result.add(column); + set(col + c, column); + } + + return result; + } + + @Override + public ArrayList insertColumns(final int col, final String... headers) { + // insert empty columns as a block + final ArrayList result = insertColumns(col, headers.length); + + // set headers for newly inserted columns + for (int c = 0; c < headers.length; c++) { + setColumnHeader(col + c, headers[c]); + } + return result; + } + + @Override + public C removeColumn(final int col) { + return remove(col); + } + + @Override + public C removeColumn(final String header) { + return removeColumn(colIndex(header)); + } + + @Override + public ArrayList removeColumns(final int col, final int count) { + checkCol(col, count); + + // save to-be-removed columns + final ArrayList result = new ArrayList(count); + for (int c = 0; c < count; c++) { + result.add(get(col + c)); + } + + final int oldColCount = getColumnCount(); + final int newColCount = oldColCount - count; + + // copy data after the deleted range into the new position + for (int oldC = col; oldC < oldColCount; oldC++) { + final int newC = oldC - count; + set(newC, get(oldC)); + } + setColumnCount(newColCount); + + return result; + } + + @Override + public ArrayList removeColumns(final String... headers) { + final ArrayList result = new ArrayList(headers.length); + for (final String header : headers) { + result.add(removeColumn(header)); + } + return result; + } + + @Override + public int getRowCount() { + return rowCount; + } + + @Override + public void setRowCount(final int rowCount) { + checkRowCount(rowCount); + this.rowCount = rowCount; + scaleColumns(); + } + + @Override + public void appendRow() { + appendRow(null); + } + + @Override + public void appendRow(final String header) { + insertRow(getRowCount(), header); + } + + @Override + public void appendRows(final int count) { + for (int c = 0; c < count; c++) { + appendRow(); + } + } + + @Override + public void appendRows(final String... headers) { + for (final String header : headers) { + appendRow(header); + } + } + + @Override + public void insertRow(final int row) { + insertRow(row, null); + } + + @Override + public void insertRow(final int row, final String header) { + insertRows(row, 1); + setRowHeader(row, header); + } + + @Override + public void insertRows(final int row, final int count) { + checkRow(row, 0); + final int oldRowCount = getRowCount(); + final int newRowCount = oldRowCount + count; + + // expand rows list + setRowCount(newRowCount); + + // copy data after the inserted range into the new position + for (int oldR = row; oldR < oldRowCount; oldR++) { + final int newR = oldR + count; + for (int c = 0; c < getColumnCount(); c++) { + set(c, newR, get(c, oldR)); + } + } + + // copy row headers after the inserted range into the new position + // NB: This loop goes backwards for performance. + // It ensures that rowHeaders is resized at most once. + for (int oldR = oldRowCount - 1; oldR >= row; oldR--) { + final int newR = oldR + count; + setRowHeader(newR, getRowHeader(oldR)); + } + + // insert new blank row data + for (int r = 0; r < count; r++) { + for (int c = 0; c < getColumnCount(); c++) { + set(c, row + r, null); + } + } + + // insert new blank row headers + for (int r = 0; r < count; r++) { + setRowHeader(row + r, null); + } + } + + @Override + public void insertRows(final int row, final String... headers) { + // insert empty rows as a block + insertRows(row, headers.length); + + // set headers for newly inserted rows + for (int r = 0; r < headers.length; r++) { + setRowHeader(row + r, headers[r]); + } + } + + @Override + public void removeRow(final int row) { + removeRows(row, 1); + } + + @Override + public void removeRow(final String header) { + final int row = getColumnIndex(header); + if (row < 0) { + throw new IndexOutOfBoundsException("No such row: " + header); + } + removeRow(row); + } + + @Override + public void removeRows(final int row, final int count) { + checkRow(row, count); + final int oldRowCount = getRowCount(); + final int newRowCount = oldRowCount - count; + // copy data after the deleted range into the new position + for (int oldR = row; oldR < oldRowCount; oldR++) { + final int newR = oldR - count; + setRowHeader(newR, getRowHeader(oldR)); + for (int c = 0; c < getColumnCount(); c++) { + set(c, newR, get(c, oldR)); + } + } + setRowCount(newRowCount); + // trim row headers list, if needed + if (rowHeaders.size() > newRowCount) rowHeaders.setSize(newRowCount); + } + + @Override + public void removeRows(final String... headers) { + for (final String header : headers) { + removeRow(header); + } + } + + @Override + public void setDimensions(final int colCount, final int rowCount) { + setColumnCount(colCount); + setRowCount(rowCount); + } + + @Override + public String getColumnHeader(final int col) { + return get(col).getHeader(); + } + + @Override + public void setColumnHeader(final int col, final String header) { + get(col).setHeader(header); + } + + @Override + public int getColumnIndex(final String header) { + for (int c = 0; c < getColumnCount(); c++) { + final String h = getColumnHeader(c); + if (equal(h, header)) return c; + } + return -1; + } + + @Override + public String getRowHeader(final int row) { + checkRow(row, 1); + if (rowHeaders.size() <= row) return null; // label not initialized + return rowHeaders.get(row); + } + + @Override + public void setRowHeader(final int row, final String header) { + checkRow(row, 1); + if (row >= rowHeaders.size()) { + // ensure row headers list is long enough to accommodate the header + rowHeaders.setSize(row + 1); + } + // update the row header value, where applicable + rowHeaders.set(row, header); + } + + @Override + public int getRowIndex(final String header) { + for (int r = 0; r < getRowCount(); r++) { + final String h = getRowHeader(r); + if (equal(h, header)) return r; + } + return -1; + } + + @Override + public void set(final int col, final int row, final T value) { + check(col, row); + get(col).set(row, value); + } + + @Override + public void set(final String colHeader, final int row, final T value) { + final int col = colIndex(colHeader); + checkRow(row, 1); + get(col).set(row, value); + } + + @Override + public T get(final int col, final int row) { + check(col, row); + return get(col).get(row); + } + + @Override + public T get(final String colHeader, final int row) { + final int col = colIndex(colHeader); + checkRow(row, 1); + return get(col).get(row); + } + + // -- Internal methods -- + + protected abstract C createColumn(final String header); + + // -- Helper methods -- + + /** Initializes and scales all columns to match the row count. */ + private void scaleColumns() { + for (int c = 0; c < getColumnCount(); c++) { + if (get(c) == null) { + // initialize a new column + set(c, createColumn(null)); + } + get(c).setSize(getRowCount()); + } + } + + /** Throws an exception if the given row or column is out of bounds. */ + private void check(final int col, final int row) { + checkCol(col, 1); + checkRow(row, 1); + } + + /** Throws an exception if the given column(s) are out of bounds. */ + private void checkCol(final int col, final int count) { + check("column", col, count, getColumnCount()); + } + + /** Throws an exception if the given row(s) are out of bounds. */ + private void checkRow(final int row, final int count) { + check("row", row, count, getRowCount()); + } + + /** Throws an exception if the given values are out of bounds. */ + private void check(final String name, final int index, final int count, + final int bound) + { + final int last = index + count - 1; + if (index >= 0 && last < bound) return; + if (count <= 1) { + throw new IndexOutOfBoundsException("Invalid " + name + ": " + index); + } + throw new IndexOutOfBoundsException("Invalid " + name + "s: " + index + + " - " + last); + } + + /** Throws an exception if the given column count is invalid. */ + private void checkColCount(final int count) { + checkCount("column", count); + } + + /** Throws an exception if the given row count is invalid. */ + private void checkRowCount(final int count) { + checkCount("row", count); + } + + /** Throws an exception if the given count is invalid. */ + private void checkCount(final String name, final int count) { + if (count >= 0) return; + throw new IllegalArgumentException("Invalid " + name + " count: " + count); + } + + /** + * Gets the column index corresponding to the given header, throwing an + * exception if no such column exists. + */ + private int colIndex(final String header) { + final int col = getColumnIndex(header); + if (col < 0) { + throw new IllegalArgumentException("No such column: " + header); + } + return col; + } + + /** + * Returns true iff both objects are null, or the objects are equal via + * {@link Object#equals}. + */ + private boolean equal(final Object o1, final Object o2) { + if (o1 == null && o2 == null) return true; + if (o1 != null && o1.equals(o2)) return true; + return false; + } + +} diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java new file mode 100644 index 0000000..51cb37d --- /dev/null +++ b/src/main/java/net/imagej/table/Column.java @@ -0,0 +1,60 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import java.util.List; + +import org.scijava.util.Sizable; + +/** + * A column of data of a {@link Table}. + * + * @author Curtis Rueden + * @param The type of data stored in the table. + */ +public interface Column extends List, Sizable { + + /** Gets the header of this column. */ + String getHeader(); + + /** Sets the header of this column. */ + void setHeader(String header); + + /** Gets the column's size (i.e., number of rows). */ + @Override + int size(); + + /** Sets the column's size (i.e., number of rows). */ + @Override + void setSize(int size); + +} diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java new file mode 100644 index 0000000..6920e45 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -0,0 +1,65 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.SizableArrayList; + +/** + * Default implementation of {@link Column}. + * + * @author Curtis Rueden + * @param The type of data stored in the table. + */ +public class DefaultColumn extends SizableArrayList implements Column { + + /** The column header. */ + private String header; + + public DefaultColumn() {} + + public DefaultColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/net/imagej/table/DefaultGenericTable.java new file mode 100644 index 0000000..de77214 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultGenericTable.java @@ -0,0 +1,60 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link GenericTable}. + * + * @author Curtis Rueden + */ +public class DefaultGenericTable extends AbstractTable + implements GenericTable +{ + + /** Creates an empty table. */ + public DefaultGenericTable() { + super(); + } + + /** Creates a table with the given row and column dimensions. */ + public DefaultGenericTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- Internal methods -- + + @Override + protected GenericColumn createColumn(final String header) { + return new GenericColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java new file mode 100644 index 0000000..c07463b --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -0,0 +1,89 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import net.imglib2.img.Img; +import net.imglib2.meta.Axes; +import net.imglib2.meta.AxisType; +import net.imglib2.meta.ImgPlus; +import net.imglib2.type.numeric.real.DoubleType; + +/** + * Default implementation of {@link ResultsTable}. + * + * @author Curtis Rueden + */ +public class DefaultResultsTable extends AbstractTable + implements ResultsTable +{ + + /** Creates an empty results table. */ + public DefaultResultsTable() { + super(); + } + + /** Creates a results table with the given row and column dimensions. */ + public DefaultResultsTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- ResultsTable methods -- + + @Override + public double getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final double value) { + get(col).setValue(row, value); + } + + @Override + public ImgPlus img() { + final Img img = new ResultsImg(this); + final AxisType[] axes = { Axes.X, Axes.Y }; + final String name = "Results"; + final ImgPlus imgPlus = + new ImgPlus(img, name, axes); + // TODO: Once ImgPlus has a place for row & column labels, add those too. + return imgPlus; + } + + // -- Internal methods -- + + @Override + protected DoubleColumn createColumn(final String header) { + return new DoubleColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java new file mode 100644 index 0000000..0b8bffa --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultTableDisplay.java @@ -0,0 +1,53 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.display.AbstractDisplay; +import org.scijava.display.Display; +import org.scijava.plugin.Plugin; + +/** + * Default display for {@link Table}s, including {@link ResultsTable}s. + * + * @author Curtis Rueden + */ +@Plugin(type = Display.class) +public class DefaultTableDisplay extends AbstractDisplay> implements + TableDisplay +{ + + @SuppressWarnings({ "rawtypes", "unchecked" }) + public DefaultTableDisplay() { + super((Class) Table.class); + } + +} diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java new file mode 100644 index 0000000..5b2b14b --- /dev/null +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.DoubleArray; + +/** + * Efficient implementation of {@link Column} for {@code double} primitives. + * + * @author Curtis Rueden + */ +public class DoubleColumn extends DoubleArray implements Column { + + /** The column header. */ + private String header; + + public DoubleColumn() {} + + public DoubleColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java new file mode 100644 index 0000000..9b34e5e --- /dev/null +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -0,0 +1,49 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A column that can consist of any {@link Object}s. + * + * @author Curtis Rueden + */ +public class GenericColumn extends DefaultColumn { + + public GenericColumn() { + super(); + } + + public GenericColumn(final String header) { + super(header); + } + +} diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/net/imagej/table/GenericTable.java new file mode 100644 index 0000000..6c62d70 --- /dev/null +++ b/src/main/java/net/imagej/table/GenericTable.java @@ -0,0 +1,41 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A flexible table capable of storing any values as {@link Object}s. + * + * @author Curtis Rueden + */ +public interface GenericTable extends Table { + // NB: No implementation needed. +} diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java new file mode 100644 index 0000000..9befbc8 --- /dev/null +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -0,0 +1,243 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import java.util.Iterator; + +import net.imglib2.Cursor; +import net.imglib2.Interval; +import net.imglib2.IterableRealInterval; +import net.imglib2.Positionable; +import net.imglib2.RandomAccess; +import net.imglib2.RealPositionable; +import net.imglib2.img.Img; +import net.imglib2.img.ImgFactory; +import net.imglib2.type.numeric.real.DoubleType; + +/** + * Expresses a {@link ResultsTable} as an {@link Img}. + * + * @author Curtis Rueden + */ +public class ResultsImg implements Img { + + private final ResultsTable table; + + public ResultsImg(final ResultsTable table) { + this.table = table; + } + + // -- RandomAccessible methods -- + + @Override + public RandomAccess randomAccess() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + @Override + public RandomAccess randomAccess(final Interval interval) { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + // -- EuclideanSpace methods -- + + @Override + public int numDimensions() { + return 2; + } + + // -- Interval methods -- + + @Override + public long min(final int d) { + if (d >= 0 && d <= 1) return 0; + throw new IllegalArgumentException("Invalid dimension: " + d); + } + + @Override + public void min(final long[] min) { + min[0] = min[1] = 0; + } + + @Override + public void min(final Positionable min) { + min.setPosition(0, 0); + min.setPosition(0, 1); + } + + @Override + public long max(final int d) { + if (d == 0) return max0(); + if (d == 1) return max1(); + throw new IllegalArgumentException("Invalid dimension: " + d); + } + + @Override + public void max(final long[] max) { + max[0] = max0(); + max[1] = max1(); + } + + @Override + public void max(final Positionable max) { + max.setPosition(0, max0()); + max.setPosition(0, max1()); + } + + // -- RealInterval methods -- + + @Override + public double realMin(final int d) { + return min(d); + } + + @Override + public void realMin(final double[] min) { + min[0] = min[1] = 0; + } + + @Override + public void realMin(final RealPositionable min) { + min(min); + } + + @Override + public double realMax(final int d) { + return max(d); + } + + @Override + public void realMax(final double[] max) { + max[0] = table.getColumnCount(); + max[1] = table.getRowCount(); + } + + @Override + public void realMax(final RealPositionable max) { + max(max); + } + + // -- Dimensions methods -- + + @Override + public void dimensions(final long[] dimensions) { + dimensions[0] = dim0(); + dimensions[1] = dim1(); + } + + @Override + public long dimension(final int d) { + if (d == 0) return dim0(); + if (d == 1) return dim1(); + throw new IllegalArgumentException("Invalid dimension: " + d); + } + + // -- IterableRealInterval methods -- + + @Override + public Cursor cursor() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + @Override + public Cursor localizingCursor() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + @Override + public long size() { + return (long) dim0() * dim1(); + } + + @Override + public DoubleType firstElement() { + return new DoubleType(table.get(0, 0)); + } + + @Override + public Object iterationOrder() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + @Override + @Deprecated + public boolean equalIterationOrder(final IterableRealInterval f) { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + // -- Iterable methods -- + + @Override + public Iterator iterator() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + // -- Img methods -- + + @Override + public ImgFactory factory() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + @Override + public Img copy() { + // TODO + throw new UnsupportedOperationException("Unimplemented"); + } + + // -- Helper methods -- + + private int dim0() { + return table.getColumnCount(); + } + + private int dim1() { + return table.getRowCount(); + } + + private int max0() { + return dim0() - 1; + } + + private int max1() { + return dim1() - 1; + } + +} diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java new file mode 100644 index 0000000..9f7ee5c --- /dev/null +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -0,0 +1,53 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import net.imglib2.meta.ImgPlus; +import net.imglib2.type.numeric.real.DoubleType; + +/** + * A table of double-precision floating point values. + * + * @author Curtis Rueden + */ +public interface ResultsTable extends Table { + + /** Gets the value of the given table cell. */ + double getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, double value); + + /** Wraps the results table in an ImgLib {@link net.imglib2.img.Img}. */ + ImgPlus img(); + +} diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java new file mode 100644 index 0000000..36b4151 --- /dev/null +++ b/src/main/java/net/imagej/table/Table.java @@ -0,0 +1,425 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * A table of values. + * + * @author Curtis Rueden + * @param The type of column used by the table. + * @param The type of data stored in the table. + */ +public interface Table, T> extends List { + + /** Gets the number of columns in the table. */ + int getColumnCount(); + + /** Sets the number of columns in the table. */ + void setColumnCount(int colCount); + + /** Returns the first column with the given header in the table. */ + C get(String colHeader); + + /** + * Appends a column (with no header) to the table. + * + * @return the column that was appended + */ + C appendColumn(); + + /** + * Appends a column with the given header to the table. + * + * @return the column that was appended + */ + C appendColumn(String header); + + /** + * Appends a number of columns (with no headers) to the table. + * + * @return the columns that were appended + */ + List appendColumns(int count); + + /** + * Appends a block of columns with the given headers to the table. + * + * @return the columns that were appended + */ + List appendColumns(String... headers); + + /** + * Inserts a column (with no header) at the given position in the table. + * + * @return the column that was inserted + */ + C insertColumn(int col); + + /** + * Inserts a column with the specified header at the given position in the + * table. + * + * @return the column that was inserted + */ + C insertColumn(int col, String header); + + /** + * Inserts a block of columns (with no headers) at the given position in the + * table. + * + * @return the columns that were inserted + */ + List insertColumns(int col, int count); + + /** + * Inserts a block of columns with the specified headers at the given position + * in the table. + * + * @return the columns that were inserted + */ + List insertColumns(int col, String... headers); + + /** + * Removes the column at the given position from the table. + * + * @return the column that was removed + */ + C removeColumn(int col); + + /** + * Removes the first column with the given header from the table. + * + * @return the column that was removed + */ + C removeColumn(String header); + + /** + * Removes a block of columns starting at the given position from the table. + * + * @return the columns that were removed + */ + List removeColumns(int col, int count); + + /** + * Removes the first columns with the given headers from the table. + * + * @return the columns that were removed + */ + List removeColumns(String... headers); + + /** Gets the number of rows in the table. */ + int getRowCount(); + + /** Sets the number of rows in the table. */ + void setRowCount(int rowCount); + + /** Appends a row (with no header) to the table. */ + void appendRow(); + + /** Appends a row with the given header to the table. */ + void appendRow(String header); + + /** Appends a block of rows (with no headers) to the table. */ + void appendRows(int count); + + /** Appends a block of rows with the given headers to the table. */ + void appendRows(String... headers); + + /** Inserts a row (with no header) at the given position in the table. */ + void insertRow(int row); + + /** + * Inserts a row with the specified header at the given position in the table. + */ + void insertRow(int row, String header); + + /** + * Inserts a block of rows (with no headers) at the given position in the + * table. + */ + void insertRows(int row, int count); + + /** + * Inserts a block of rows with the specified headers at the given position in + * the table. + */ + void insertRows(int row, String... headers); + + /** Removes the row at the given position from the table. */ + void removeRow(int row); + + /** Removes the first row with the given header from the table. */ + void removeRow(String header); + + /** + * Removes a block of rows starting at the given position from the table. + */ + void removeRows(int row, int count); + + /** Removes the first rows with the given headers from the table. */ + void removeRows(String... headers); + + /** Sets the number of columns and rows in the table. */ + void setDimensions(int colCount, int rowCount); + + /** Gets the column header at the given column. */ + String getColumnHeader(int col); + + /** Sets the column header at the given column. */ + void setColumnHeader(int col, String header); + + /** Gets the column index of the column with the given header. */ + int getColumnIndex(String header); + + /** Gets the row header at the given row. */ + String getRowHeader(int row); + + /** Sets the row header at the given row. */ + void setRowHeader(int row, String header); + + /** Gets the row index of the row with the given header. */ + int getRowIndex(String header); + + /** Sets the table value at the given column and row. */ + void set(int col, int row, T value); + + /** Sets the table value at the given column and row. */ + void set(String colHeader, int row, T value); + + /** Gets the table value at the given column and row. */ + T get(int col, int row); + + /** Gets the table value at the given column and row. */ + T get(String colHeader, int row); + + // -- List methods -- + + /** Gets the number of columns in the table. */ + @Override + int size(); + + /** Gets whether the table is empty. */ + @Override + boolean isEmpty(); + + /** + * Gets whether the table contains the given column. + * + * @param column The {@link Column} whose presence in the table is to be + * tested. + */ + @Override + boolean contains(Object column); + + /** Returns an iterator over the columns in the table in proper sequence. */ + @Override + Iterator iterator(); + + /** + * Returns an array containing all of the columns in the table in proper + * sequence (from first to last column). + */ + @Override + Object[] toArray(); + + /** + * Returns an array containing all of the column in the table in proper + * sequence (from first to last column); the runtime type of the returned + * array is that of the specified array. If the list of columns fits in the + * specified array, it is returned therein. Otherwise, a new array is + * allocated with the runtime type of the specified array and the size of this + * list of columns. + */ + @Override + A[] toArray(A[] a); + + /** + * Appends the specified column to the end of the table. + *

+ * No checking is done to ensure the new column has the same number of rows as + * the other existing columns. + *

+ */ + @Override + boolean add(C column); + + /** + * Removes the first occurrence of the specified column from the table, if it + * is present. + * + * @return true if the table contained the specified column + */ + @Override + boolean remove(Object column); + + /** + * Returns true if the table contains all of the columns of the + * specified collection. + */ + @Override + boolean containsAll(Collection c); + + /** + * Appends all of the columns in the specified collection to the end of the + * table, in the order that they are returned by the specified collection's + * iterator. + *

+ * No checking is done to ensure the new columns have the same number of rows + * as the other existing columns. + *

+ * + * @return true if the table changed as a result of the call + */ + @Override + boolean addAll(Collection c); + + /** + * Inserts all of the columns in the specified collection into this list at + * the specified position. + *

+ * No checking is done to ensure the new columns have the same number of rows + * as the other existing columns. + *

+ * + * @return true if the table changed as a result of the call + */ + @Override + boolean addAll(int col, Collection c); + + /** + * Removes from the table all of its columns that are contained in the + * specified collection. + * + * @return true if the table changed as a result of the call + */ + @Override + boolean removeAll(Collection c); + + /** + * Retains only the columns in the table that are contained in the specified + * collection. In other words, removes from the table all the columns that are + * not contained in the specified collection. + * + * @return true if the table changed as a result of the call + */ + @Override + boolean retainAll(Collection c); + + /** + * Removes all data (including row and column headers) from the table. The + * table will be empty after this call returns. + *

+ * If you want to retain the column headers, call {@link #setRowCount(int)} + * with a value of 0. If you want to retain the row headers, call + * {@link #setColumnCount(int)} with a value of 0. + *

+ */ + @Override + void clear(); + + /** Returns the column at the specified position in the table. */ + @Override + C get(int col); + + /** + * Replaces the column at the specified position in the table with the + * specified column. + *

+ * No checking is done to ensure the new column has the same number of rows as + * the other existing columns. + *

+ * + * @return the column previously at the specified position + */ + @Override + C set(int col, C column); + + /** + * Inserts the specified column at the specified position in the table. + *

+ * No checking is done to ensure the new column has the same number of rows as + * the other existing columns. + *

+ */ + @Override + void add(int col, C column); + + /** + * Removes the column at the specified position in the table. + * + * @return the column previously at the specified position + */ + @Override + C remove(int col); + + /** + * Returns the index of the first occurrence of the specified column in the + * table, or -1 if the table does not contain the column. + */ + @Override + int indexOf(Object column); + + /** + * Returns the index of the last occurrence of the specified column in the + * table, or -1 if the table does not contain the column. + */ + @Override + int lastIndexOf(Object column); + + /** + * Returns a list iterator over the columns in the table (in proper sequence). + */ + @Override + ListIterator listIterator(); + + /** + * Returns a list iterator of the columns in the table (in proper sequence), + * starting at the specified position in the table. + */ + @Override + ListIterator listIterator(int col); + + /** + * Returns a view of the portion of the table between the specified + * fromIndex, inclusive, and toIndex, exclusive. The + * returned list is backed by the table, so non-structural changes in the + * returned list are reflected in the table, and vice-versa. + */ + @Override + List subList(int fromCol, int toCol); + +} diff --git a/src/main/java/net/imagej/table/TableDisplay.java b/src/main/java/net/imagej/table/TableDisplay.java new file mode 100644 index 0000000..1505a0f --- /dev/null +++ b/src/main/java/net/imagej/table/TableDisplay.java @@ -0,0 +1,43 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.display.Display; + +/** + * Interface for {@link Table} {@link Display}s. + * + * @author Curtis Rueden + */ +public interface TableDisplay extends Display> { + // This interface intentionally left blank. +} diff --git a/src/main/java/net/imagej/table/TableLoader.java b/src/main/java/net/imagej/table/TableLoader.java new file mode 100644 index 0000000..515e271 --- /dev/null +++ b/src/main/java/net/imagej/table/TableLoader.java @@ -0,0 +1,208 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StreamTokenizer; +import java.net.URL; + +// note: adapted from Wayne Rasband's IJ1 TextReader class + +/** + * Loads a text file containing comma separated values into a + * {@link ResultsTable}. + * + * @author Barry DeZonia + * @author Wayne Rasband + */ +public class TableLoader { + + // -- instance variables -- + + private int rows, cols; + + // -- private legacy text file support methods -- + + /** + * Loads the values of a table stored in a text file as a ResultsTable. Given + * BufferedInputStream must be marked to hold entire contents in buffer. This + * method rewinds the buggered stream so it can read it twice. + * + * @param str The BufferedInputStream containing the data of the text table + * @return A ResultsTable containing the values (and headers) + * @throws IOException + */ + public ResultsTable valuesFromTextFile(BufferedInputStream str) + throws IOException + { + countRowsAndCols(str); + if (rows == 0) return null; + ResultsTable values = new DefaultResultsTable(cols, rows); + str.reset(); + read(str, values); + int firstRowNaNCount = 0; + for (int i = 0; i < cols; i++) { + if (Double.isNaN(values.getValue(i, 0))) firstRowNaNCount++; + } + if (firstRowNaNCount == cols) { // assume first row is header + // throw away first row of non-values + rows--; + ResultsTable oldValues = values; + values = new DefaultResultsTable(cols, rows); + for (int c = 0; c < cols; c++) { + String colHeader = oldValues.getColumnHeader(c); + values.setColumnHeader(c, colHeader); + } + for (int row = 0; row < rows; row++) { + for (int col = 0; col < cols; col++) { + double val = oldValues.getValue(col, row + 1); + values.setValue(col, row, val); + } + } + } + return values; + } + + /** + * Loads the values of a table stored in a text file as a ResultsTable. + * + * @param urlString The url (as a string) of the file containing the text + * table + * @return A ResultsTable containing the values (and headers) + * @throws IOException + */ + public ResultsTable valuesFromTextFile(String urlString) throws IOException { + return valuesFromTextFile(new URL(urlString)); + } + + /** + * Loads the values of a table stored in a text file as a ResultsTable. + * + * @param file The File containing the text table + * @return A ResultsTable containing the values (and headers) + * @throws IOException + */ + public ResultsTable valuesFromTextFile(File file) throws IOException { + FileInputStream fstr = new FileInputStream(file); + BufferedInputStream stream = new BufferedInputStream(fstr); + stream.mark((int) file.length()); + return valuesFromTextFile(stream); + } + + /** + * Loads the values of a table stored at a URL as a ResultsTable. + * + * @param url The URL location of the file containing the text table + * @return A ResultsTable containing the values (and headers) + * @throws IOException + */ + public ResultsTable valuesFromTextFile(URL url) throws IOException { + InputStream istr = url.openStream(); + BufferedInputStream stream = new BufferedInputStream(istr); + stream.mark(8000000); // about 8 megabytes: FIXME HACK + return valuesFromTextFile(stream); + } + + // -- private helpers - + + private void countRowsAndCols(InputStream str) throws IOException { + Reader r = new BufferedReader(new InputStreamReader(str)); + StreamTokenizer tok = new StreamTokenizer(r); + tok.resetSyntax(); + tok.wordChars(43, 43); + tok.wordChars(45, 126); + tok.whitespaceChars(0, 42); + tok.whitespaceChars(44, 44); + tok.whitespaceChars(127, 255); + tok.eolIsSignificant(true); + + int words = 0, wordsPrevLine = 0; + while (tok.nextToken() != StreamTokenizer.TT_EOF) { + switch (tok.ttype) { + case StreamTokenizer.TT_EOL: + rows++; + if (words == 0) rows--; // ignore empty lines + if (rows == 1 && words > 0) cols = words; + if (rows > 1 && words != 0 && words != wordsPrevLine) { + throw new IOException("Line " + rows + + " is not the same length as the first line."); + } + if (words != 0) wordsPrevLine = words; + words = 0; + break; + case StreamTokenizer.TT_WORD: + // System.out.println("read word " + tok.sval); + words++; + break; + } + } + if (words == cols) rows++; // last line does not end with EOL + } + + private void read(InputStream str, ResultsTable values) throws IOException { + Reader r = new BufferedReader(new InputStreamReader(str)); + StreamTokenizer tok = new StreamTokenizer(r); + tok.resetSyntax(); + tok.wordChars(43, 43); + tok.wordChars(45, 126); + tok.whitespaceChars(0, 42); + tok.whitespaceChars(44, 44); + tok.whitespaceChars(127, 255); + + int row = 0, col = 0; + while (tok.nextToken() != StreamTokenizer.TT_EOF) { + if (tok.ttype == StreamTokenizer.TT_WORD) { + double value; + try { + value = Double.parseDouble(tok.sval); + } + catch (NumberFormatException e) { + value = Double.NaN; + if (row == 0) values.setColumnHeader(col, tok.sval); + } + values.setValue(col, row, value); + col++; + if (col == cols) { + row++; + col = 0; + } + } + } + } +} diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java new file mode 100644 index 0000000..5af4a9c --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -0,0 +1,120 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import net.imagej.table.DefaultResultsTable; +import net.imagej.table.DoubleColumn; +import net.imagej.table.ResultsTable; + +import org.junit.Test; + +/** + * Tests {@link DefaultResultsTable}. + * + * @author Curtis Rueden + */ +public class DefaultResultsTableTest { + + private static final String[] HEADERS = {"Year", "Age", "BA"}; + + // Paul Molitor + private static final double[][] DATA = { + {1978, 21, .273}, + {1979, 22, .322}, + {1980, 23, .304}, + {1981, 24, .267}, + {1982, 25, .302}, + {1983, 26, .270}, + {1984, 27, .217}, + {1985, 28, .297}, + {1986, 29, .281}, + {1987, 30, .353}, + {1988, 31, .312}, + {1989, 32, .315}, + {1990, 33, .285}, + {1991, 34, .325}, + {1992, 35, .320}, + {1993, 36, .332}, + {1994, 37, .341}, + {1995, 38, .270}, + {1996, 39, .341}, + {1997, 40, .305}, + {1998, 41, .281}, + }; + + public ResultsTable createTable() { + final ResultsTable table = + new DefaultResultsTable(DATA[0].length, DATA.length); + + for (int c=0; c Date: Tue, 22 Apr 2014 15:34:17 -0500 Subject: [PATCH 03/42] Organize imports --- src/test/java/net/imagej/table/DefaultResultsTableTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index 5af4a9c..d6b5be3 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -33,9 +33,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; -import net.imagej.table.DefaultResultsTable; -import net.imagej.table.DoubleColumn; -import net.imagej.table.ResultsTable; import org.junit.Test; From f9667543c9cd30fddd427f9ef86460f5596fd972 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Mon, 4 Aug 2014 16:54:39 -0500 Subject: [PATCH 04/42] DefaultTableDisplay: handle double array as table In this specific case (double[] and double[][]), it is easy to wrap the data in DoubleColumn objects. Ideally, we want to support all types of primitive 1D and 2D arrays, or even all Collection, but that will require a little more infrastructural work to accomplish. This approach is good enough for now, for MATLAB matrix support, which always uses doubles. --- .../net/imagej/table/DefaultTableDisplay.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java index 0b8bffa..a628a7c 100644 --- a/src/main/java/net/imagej/table/DefaultTableDisplay.java +++ b/src/main/java/net/imagej/table/DefaultTableDisplay.java @@ -50,4 +50,75 @@ public DefaultTableDisplay() { super((Class) Table.class); } + // -- Display methods -- + + @Override + public boolean canDisplay(final Class c) { + if (c == double[].class || c == double[][].class) return true; + return super.canDisplay(c); + } + + @Override + public void display(final Object o) { + // wrap 1D array as results table + if (o instanceof double[]) { + display(wrapArrayAsTable(new double[][] { (double[]) o })); + return; + } + // wrap 2D array as results table + if (o instanceof double[][]) { + display(wrapArrayAsTable((double[][]) o)); + return; + } + + super.display(o); + } + + @Override + public boolean isDisplaying(final Object o) { + if (super.isDisplaying(o)) return true; + + // check for wrapped arrays + if (o instanceof double[]) { + arrayEqualsTable(new double[][] {(double[]) o}); + } + if (o instanceof double[][]) { + arrayEqualsTable((double[][]) o); + } + + return false; + } + + // -- Helper methods -- + + private ResultsTable wrapArrayAsTable(final double[][] array) { + final ResultsTable table = new DefaultResultsTable(); + int rowCount = 0; + for (int d = 0; d < array.length; d++) { + final DoubleColumn column = new DoubleColumn(); + column.setArray(array[d]); + table.add(column); + if (rowCount < array[d].length) rowCount = array[d].length; + } + table.setRowCount(rowCount); + return table; + } + + private boolean arrayEqualsTable(final double[][] array) { + for (final Table table : this) { + if (!(table instanceof ResultsTable)) continue; + final ResultsTable resultsTable = (ResultsTable) table; + if (array.length != resultsTable.getColumnCount()) continue; + boolean equal = true; + for (int c = 0; c < array.length; c++) { + if (array[c] != resultsTable.get(c).getArray()) { + equal = false; + break; + } + } + return equal; + } + return false; + } + } From 64ddcf733c98a6f8cac54a31464eeb4cd9926942 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 22 Oct 2014 12:56:18 -0500 Subject: [PATCH 05/42] POM: update to the ImgLib2 2.0.1 release This makes the necessary code changes to account for backwards incompatibilities. It also updates several dependencies to their latest versions, and removes the obsolete imglib2-ops dependency. --- src/main/java/net/imagej/table/ResultsImg.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java index 9befbc8..7c096ad 100644 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -193,13 +193,6 @@ public Object iterationOrder() { throw new UnsupportedOperationException("Unimplemented"); } - @Override - @Deprecated - public boolean equalIterationOrder(final IterableRealInterval f) { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - // -- Iterable methods -- @Override From 86b4cfad0c1b20b574e08af1229f844d18e06825 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 23 Dec 2014 17:03:02 -0600 Subject: [PATCH 06/42] Eliminate deprecated net.imglib2.meta usages There is still much work to be done cleaning up the ImgPlus class and related interfaces. However, this is an important first step. --- src/main/java/net/imagej/table/DefaultResultsTable.java | 6 +++--- src/main/java/net/imagej/table/ResultsTable.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index c07463b..efb1ad4 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -31,10 +31,10 @@ package net.imagej.table; +import net.imagej.ImgPlus; +import net.imagej.axis.Axes; +import net.imagej.axis.AxisType; import net.imglib2.img.Img; -import net.imglib2.meta.Axes; -import net.imglib2.meta.AxisType; -import net.imglib2.meta.ImgPlus; import net.imglib2.type.numeric.real.DoubleType; /** diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java index 9f7ee5c..7fd2d0e 100644 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -31,7 +31,7 @@ package net.imagej.table; -import net.imglib2.meta.ImgPlus; +import net.imagej.ImgPlus; import net.imglib2.type.numeric.real.DoubleType; /** From ddad54ec4a4f424c543c7a66719880858558b12b Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 16 Jan 2015 17:01:33 -0600 Subject: [PATCH 07/42] Happy New Year 2015! --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- src/main/java/net/imagej/table/Column.java | 2 +- src/main/java/net/imagej/table/DefaultColumn.java | 2 +- src/main/java/net/imagej/table/DefaultGenericTable.java | 2 +- src/main/java/net/imagej/table/DefaultResultsTable.java | 2 +- src/main/java/net/imagej/table/DefaultTableDisplay.java | 2 +- src/main/java/net/imagej/table/DoubleColumn.java | 2 +- src/main/java/net/imagej/table/GenericColumn.java | 2 +- src/main/java/net/imagej/table/GenericTable.java | 2 +- src/main/java/net/imagej/table/ResultsImg.java | 2 +- src/main/java/net/imagej/table/ResultsTable.java | 2 +- src/main/java/net/imagej/table/Table.java | 2 +- src/main/java/net/imagej/table/TableDisplay.java | 2 +- src/main/java/net/imagej/table/TableLoader.java | 2 +- src/test/java/net/imagej/table/DefaultResultsTableTest.java | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index ff0ec38..e78a9ff 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index 51cb37d..7afea35 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index 6920e45..f69a2b9 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/net/imagej/table/DefaultGenericTable.java index de77214..ff84217 100644 --- a/src/main/java/net/imagej/table/DefaultGenericTable.java +++ b/src/main/java/net/imagej/table/DefaultGenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index efb1ad4..6f28e55 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java index a628a7c..40e9d84 100644 --- a/src/main/java/net/imagej/table/DefaultTableDisplay.java +++ b/src/main/java/net/imagej/table/DefaultTableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 5b2b14b..8c89f21 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java index 9b34e5e..83cdc62 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/net/imagej/table/GenericTable.java index 6c62d70..1fb0e7e 100644 --- a/src/main/java/net/imagej/table/GenericTable.java +++ b/src/main/java/net/imagej/table/GenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java index 7c096ad..796db9e 100644 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java index 7fd2d0e..7300af3 100644 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java index 36b4151..ea79367 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/net/imagej/table/Table.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableDisplay.java b/src/main/java/net/imagej/table/TableDisplay.java index 1505a0f..11e1ed6 100644 --- a/src/main/java/net/imagej/table/TableDisplay.java +++ b/src/main/java/net/imagej/table/TableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableLoader.java b/src/main/java/net/imagej/table/TableLoader.java index 515e271..fc2ca7e 100644 --- a/src/main/java/net/imagej/table/TableLoader.java +++ b/src/main/java/net/imagej/table/TableLoader.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index d6b5be3..cb5f735 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2014 Board of Regents of the University of + * Copyright (C) 2009 - 2015 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% From 46e2f3141ff53282b7125d132ee2217eb4b00813 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 22 Jun 2016 22:38:32 -0400 Subject: [PATCH 08/42] Use the diamond syntax Thanks, Java 7! --- src/main/java/net/imagej/table/AbstractTable.java | 12 ++++++------ .../java/net/imagej/table/DefaultResultsTable.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index e78a9ff..10e91a1 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -60,7 +60,7 @@ public AbstractTable() { public AbstractTable(final int colCount, final int rowCount) { super(); checkRowCount(rowCount); - rowHeaders = new SizableArrayList(); + rowHeaders = new SizableArrayList<>(); this.rowCount = rowCount; setColumnCount(colCount); } @@ -96,7 +96,7 @@ public C appendColumn(final String header) { @Override public ArrayList appendColumns(final int count) { - final ArrayList result = new ArrayList(count); + final ArrayList result = new ArrayList<>(count); for (int c = 0; c < count; c++) { result.add(appendColumn()); } @@ -105,7 +105,7 @@ public ArrayList appendColumns(final int count) { @Override public ArrayList appendColumns(final String... headers) { - final ArrayList result = new ArrayList(headers.length); + final ArrayList result = new ArrayList<>(headers.length); for (final String header : headers) { result.add(appendColumn(header)); } @@ -140,7 +140,7 @@ public ArrayList insertColumns(final int col, final int count) { } // insert new blank columns - final ArrayList result = new ArrayList(count); + final ArrayList result = new ArrayList<>(count); for (int c = 0; c < count; c++) { final C column = createColumn(null); result.add(column); @@ -177,7 +177,7 @@ public ArrayList removeColumns(final int col, final int count) { checkCol(col, count); // save to-be-removed columns - final ArrayList result = new ArrayList(count); + final ArrayList result = new ArrayList<>(count); for (int c = 0; c < count; c++) { result.add(get(col + c)); } @@ -197,7 +197,7 @@ public ArrayList removeColumns(final int col, final int count) { @Override public ArrayList removeColumns(final String... headers) { - final ArrayList result = new ArrayList(headers.length); + final ArrayList result = new ArrayList<>(headers.length); for (final String header : headers) { result.add(removeColumn(header)); } diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index 6f28e55..c7568c7 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -74,7 +74,7 @@ public ImgPlus img() { final AxisType[] axes = { Axes.X, Axes.Y }; final String name = "Results"; final ImgPlus imgPlus = - new ImgPlus(img, name, axes); + new ImgPlus<>(img, name, axes); // TODO: Once ImgPlus has a place for row & column labels, add those too. return imgPlus; } From 027eda4952dc4ab31ead2ed1a5d2b028b206b2ae Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Thu, 23 Jun 2016 10:51:37 -0400 Subject: [PATCH 09/42] Happy belated New Year 2016 --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- src/main/java/net/imagej/table/Column.java | 2 +- src/main/java/net/imagej/table/DefaultColumn.java | 2 +- src/main/java/net/imagej/table/DefaultGenericTable.java | 2 +- src/main/java/net/imagej/table/DefaultResultsTable.java | 2 +- src/main/java/net/imagej/table/DefaultTableDisplay.java | 2 +- src/main/java/net/imagej/table/DoubleColumn.java | 2 +- src/main/java/net/imagej/table/GenericColumn.java | 2 +- src/main/java/net/imagej/table/GenericTable.java | 2 +- src/main/java/net/imagej/table/ResultsImg.java | 2 +- src/main/java/net/imagej/table/ResultsTable.java | 2 +- src/main/java/net/imagej/table/Table.java | 2 +- src/main/java/net/imagej/table/TableDisplay.java | 2 +- src/main/java/net/imagej/table/TableLoader.java | 2 +- src/test/java/net/imagej/table/DefaultResultsTableTest.java | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index 10e91a1..f8969cb 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index 7afea35..91006f0 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index f69a2b9..ed11a2c 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/net/imagej/table/DefaultGenericTable.java index ff84217..651f23c 100644 --- a/src/main/java/net/imagej/table/DefaultGenericTable.java +++ b/src/main/java/net/imagej/table/DefaultGenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index c7568c7..58a6315 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java index 40e9d84..24f155c 100644 --- a/src/main/java/net/imagej/table/DefaultTableDisplay.java +++ b/src/main/java/net/imagej/table/DefaultTableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 8c89f21..08a7e62 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java index 83cdc62..8ad169e 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/net/imagej/table/GenericTable.java index 1fb0e7e..8172df8 100644 --- a/src/main/java/net/imagej/table/GenericTable.java +++ b/src/main/java/net/imagej/table/GenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java index 796db9e..5442998 100644 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java index 7300af3..cd06519 100644 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java index ea79367..9d9eab2 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/net/imagej/table/Table.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableDisplay.java b/src/main/java/net/imagej/table/TableDisplay.java index 11e1ed6..d862917 100644 --- a/src/main/java/net/imagej/table/TableDisplay.java +++ b/src/main/java/net/imagej/table/TableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableLoader.java b/src/main/java/net/imagej/table/TableLoader.java index fc2ca7e..9d06e04 100644 --- a/src/main/java/net/imagej/table/TableLoader.java +++ b/src/main/java/net/imagej/table/TableLoader.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index cb5f735..b9ea3bc 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% From ef82fbf07e6d6993b7364aeb41bdd68284faa68c Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 3 Feb 2016 12:57:51 -0600 Subject: [PATCH 10/42] Add column implementations for primitive types --- .../java/net/imagej/table/BoolColumn.java | 64 +++++++++++++++++++ .../java/net/imagej/table/ByteColumn.java | 64 +++++++++++++++++++ .../java/net/imagej/table/CharColumn.java | 64 +++++++++++++++++++ .../java/net/imagej/table/FloatColumn.java | 64 +++++++++++++++++++ src/main/java/net/imagej/table/IntColumn.java | 64 +++++++++++++++++++ .../java/net/imagej/table/LongColumn.java | 64 +++++++++++++++++++ .../java/net/imagej/table/ShortColumn.java | 64 +++++++++++++++++++ 7 files changed, 448 insertions(+) create mode 100644 src/main/java/net/imagej/table/BoolColumn.java create mode 100644 src/main/java/net/imagej/table/ByteColumn.java create mode 100644 src/main/java/net/imagej/table/CharColumn.java create mode 100644 src/main/java/net/imagej/table/FloatColumn.java create mode 100644 src/main/java/net/imagej/table/IntColumn.java create mode 100644 src/main/java/net/imagej/table/LongColumn.java create mode 100644 src/main/java/net/imagej/table/ShortColumn.java diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java new file mode 100644 index 0000000..4b742cf --- /dev/null +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.BoolArray; + +/** + * Efficient implementation of {@link Column} for {@code boolean} primitives. + * + * @author Alison Walter + */ +public class BoolColumn extends BoolArray implements Column { + + /** The column header. */ + private String header; + + public BoolColumn() {} + + public BoolColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java new file mode 100644 index 0000000..eb05dc9 --- /dev/null +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.ByteArray; + +/** + * Efficient implementation of {@link Column} for {@code byte} primitives. + * + * @author Alison Walter + */ +public class ByteColumn extends ByteArray implements Column { + + /** The column header. */ + private String header; + + public ByteColumn() {} + + public ByteColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java new file mode 100644 index 0000000..5665611 --- /dev/null +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.CharArray; + +/** + * Efficient implementation of {@link Column} for {@code char} primitives. + * + * @author Alison Walter + */ +public class CharColumn extends CharArray implements Column { + + /** The column header. */ + private String header; + + public CharColumn() {} + + public CharColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java new file mode 100644 index 0000000..93847b3 --- /dev/null +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.FloatArray; + +/** + * Efficient implementation of {@link Column} for {@code float} primitives. + * + * @author Alison Walter + */ +public class FloatColumn extends FloatArray implements Column { + + /** The column header. */ + private String header; + + public FloatColumn() {} + + public FloatColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java new file mode 100644 index 0000000..c9f0aac --- /dev/null +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.IntArray; + +/** + * Efficient implementation of {@link Column} for {@code int} primitives. + * + * @author Alison Walter + */ +public class IntColumn extends IntArray implements Column { + + /** The column header. */ + private String header; + + public IntColumn() {} + + public IntColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java new file mode 100644 index 0000000..554b2b5 --- /dev/null +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.LongArray; + +/** + * Efficient implementation of {@link Column} for {@code long} primitives. + * + * @author Alison Walter + */ +public class LongColumn extends LongArray implements Column { + + /** The column header. */ + private String header; + + public LongColumn() {} + + public LongColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java new file mode 100644 index 0000000..553e8d3 --- /dev/null +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -0,0 +1,64 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.ShortArray; + +/** + * Efficient implementation of {@link Column} for {@code short} primitives. + * + * @author Alison Walter + */ +public class ShortColumn extends ShortArray implements Column { + + /** The column header. */ + private String header; + + public ShortColumn() {} + + public ShortColumn(final String header) { + this.header = header; + } + + // -- Column methods -- + + @Override + public String getHeader() { + return header; + } + + @Override + public void setHeader(final String header) { + this.header = header; + } + +} From 1301dddf068ec8ce15128973d88cbe76ca28e470 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 3 Feb 2016 17:07:31 -0600 Subject: [PATCH 11/42] Add getType method to different columns --- src/main/java/net/imagej/table/BoolColumn.java | 5 +++++ src/main/java/net/imagej/table/ByteColumn.java | 5 +++++ src/main/java/net/imagej/table/CharColumn.java | 5 +++++ src/main/java/net/imagej/table/Column.java | 4 +++- src/main/java/net/imagej/table/DefaultColumn.java | 11 ++++++++++- src/main/java/net/imagej/table/DoubleColumn.java | 5 +++++ src/main/java/net/imagej/table/FloatColumn.java | 5 +++++ src/main/java/net/imagej/table/GenericColumn.java | 2 +- src/main/java/net/imagej/table/IntColumn.java | 5 +++++ src/main/java/net/imagej/table/LongColumn.java | 5 +++++ src/main/java/net/imagej/table/ShortColumn.java | 5 +++++ 11 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index 4b742cf..1179eda 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Boolean.class; + } + } diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index eb05dc9..5ad5c0b 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Byte.class; + } + } diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index 5665611..bd8a3d8 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Character.class; + } + } diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index 91006f0..a501631 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -56,5 +56,7 @@ public interface Column extends List, Sizable { /** Sets the column's size (i.e., number of rows). */ @Override void setSize(int size); - + + /** Returns the actual type of data stored in the column. */ + Class getType(); } diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index ed11a2c..a4e786c 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -41,12 +41,16 @@ */ public class DefaultColumn extends SizableArrayList implements Column { + /** The type of this column. */ + private Class type; + /** The column header. */ private String header; public DefaultColumn() {} - public DefaultColumn(final String header) { + public DefaultColumn(final Class type, final String header) { + this.type = type; this.header = header; } @@ -62,4 +66,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return type; + } + } diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 08a7e62..4059764 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Double.class; + } + } diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index 93847b3..a85dc83 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Float.class; + } + } diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java index 8ad169e..e781eae 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -43,7 +43,7 @@ public GenericColumn() { } public GenericColumn(final String header) { - super(header); + super(Object.class, header); } } diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index c9f0aac..50dbd92 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Integer.class; + } + } diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index 554b2b5..5109313 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Long.class; + } + } diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index 553e8d3..12592b1 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -61,4 +61,9 @@ public void setHeader(final String header) { this.header = header; } + @Override + public Class getType() { + return Short.class; + } + } From 88e44061f596832eb4b1756e0905bdb08d220de7 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 16 Mar 2016 17:00:45 -0500 Subject: [PATCH 12/42] Add fill methods to columns --- .../java/net/imagej/table/BoolColumn.java | 29 ++++++++++++++++++- .../java/net/imagej/table/ByteColumn.java | 29 ++++++++++++++++++- .../java/net/imagej/table/CharColumn.java | 29 ++++++++++++++++++- src/main/java/net/imagej/table/Column.java | 9 +++++- .../java/net/imagej/table/DefaultColumn.java | 10 +++++++ .../java/net/imagej/table/DoubleColumn.java | 29 ++++++++++++++++++- .../java/net/imagej/table/FloatColumn.java | 29 ++++++++++++++++++- src/main/java/net/imagej/table/IntColumn.java | 29 ++++++++++++++++++- .../java/net/imagej/table/LongColumn.java | 29 ++++++++++++++++++- .../java/net/imagej/table/ShortColumn.java | 29 ++++++++++++++++++- 10 files changed, 242 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index 1179eda..e7c6f33 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code boolean} primitives. - * + * * @author Alison Walter */ public class BoolColumn extends BoolArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Boolean.class; } + @Override + public void fill(final Boolean[] values) { + final boolean[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Boolean[] values, final int offset) { + final boolean[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private boolean[] toPrimitive(final Boolean[] values) { + final boolean[] prim = new boolean[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].booleanValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index 5ad5c0b..9dd371b 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code byte} primitives. - * + * * @author Alison Walter */ public class ByteColumn extends ByteArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Byte.class; } + @Override + public void fill(final Byte[] values) { + final byte[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Byte[] values, final int offset) { + final byte[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private byte[] toPrimitive(final Byte[] values) { + final byte[] prim = new byte[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].byteValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index bd8a3d8..87107f1 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code char} primitives. - * + * * @author Alison Walter */ public class CharColumn extends CharArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Character.class; } + @Override + public void fill(final Character[] values) { + final char[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Character[] values, final int offset) { + final char[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private char[] toPrimitive(final Character[] values) { + final char[] prim = new char[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].charValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index a501631..0cbbf15 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -37,7 +37,7 @@ /** * A column of data of a {@link Table}. - * + * * @author Curtis Rueden * @param The type of data stored in the table. */ @@ -59,4 +59,11 @@ public interface Column extends List, Sizable { /** Returns the actual type of data stored in the column. */ Class getType(); + + /** Fills the column with the values in the given array. */ + void fill(T[] values); + + /** Fills the column with the values in the given array. */ + void fill(T[] values, int offset); + } diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index a4e786c..3025326 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -71,4 +71,14 @@ public Class getType() { return type; } + @Override + public void fill(final T[] values) { + fill(values, 0); + } + + @Override + public void fill(final T[] values, final int offset) { + System.arraycopy(values, 0, this.toArray(), 0, values.length); + } + } diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 4059764..bfee9b2 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code double} primitives. - * + * * @author Curtis Rueden */ public class DoubleColumn extends DoubleArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Double.class; } + @Override + public void fill(final Double[] values) { + final double[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Double[] values, final int offset) { + final double[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private double[] toPrimitive(final Double[] values) { + final double[] prim = new double[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].doubleValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index a85dc83..cefee03 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code float} primitives. - * + * * @author Alison Walter */ public class FloatColumn extends FloatArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Float.class; } + @Override + public void fill(final Float[] values) { + final float[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Float[] values, final int offset) { + final float[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private float[] toPrimitive(final Float[] values) { + final float[] prim = new float[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].floatValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index 50dbd92..502ca3e 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code int} primitives. - * + * * @author Alison Walter */ public class IntColumn extends IntArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Integer.class; } + @Override + public void fill(final Integer[] values) { + final int[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Integer[] values, final int offset) { + final int[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private int[] toPrimitive(final Integer[] values) { + final int[] prim = new int[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].intValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index 5109313..3565009 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code long} primitives. - * + * * @author Alison Walter */ public class LongColumn extends LongArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Long.class; } + @Override + public void fill(final Long[] values) { + final long[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Long[] values, final int offset) { + final long[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private long[] toPrimitive(final Long[] values) { + final long[] prim = new long[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].longValue(); + } + return prim; + } + } diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index 12592b1..bd8ffa8 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -35,7 +35,7 @@ /** * Efficient implementation of {@link Column} for {@code short} primitives. - * + * * @author Alison Walter */ public class ShortColumn extends ShortArray implements Column { @@ -66,4 +66,31 @@ public Class getType() { return Short.class; } + @Override + public void fill(final Short[] values) { + final short[] prim = toPrimitive(values); + this.setArray(prim); + } + + @Override + public void fill(final Short[] values, final int offset) { + final short[] prim = toPrimitive(values); + + // Check if array has been initialized + if (this.getArray() == null) this.setArray(prim); + else { + System.arraycopy(prim, 0, this.getArray(), offset, prim.length); + } + } + + // -- Helper methods -- + + private short[] toPrimitive(final Short[] values) { + final short[] prim = new short[values.length]; + for (int i = 0; i < prim.length; i++) { + prim[i] = values[i].shortValue(); + } + return prim; + } + } From 49a3b241b3bd8b84dda9213ea23dd3abb327e403 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 18 Mar 2016 12:22:52 -0500 Subject: [PATCH 13/42] Add table implementations for primitive types --- src/main/java/net/imagej/table/BoolTable.java | 47 ++++++++++++ src/main/java/net/imagej/table/ByteTable.java | 47 ++++++++++++ src/main/java/net/imagej/table/CharTable.java | 47 ++++++++++++ .../net/imagej/table/DefaultBoolTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultByteTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultCharTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultFloatTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultIntTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultLongTable.java | 71 +++++++++++++++++++ .../net/imagej/table/DefaultShortTable.java | 71 +++++++++++++++++++ .../java/net/imagej/table/FloatTable.java | 47 ++++++++++++ src/main/java/net/imagej/table/IntTable.java | 47 ++++++++++++ src/main/java/net/imagej/table/LongTable.java | 47 ++++++++++++ .../java/net/imagej/table/ShortTable.java | 47 ++++++++++++ 14 files changed, 826 insertions(+) create mode 100644 src/main/java/net/imagej/table/BoolTable.java create mode 100644 src/main/java/net/imagej/table/ByteTable.java create mode 100644 src/main/java/net/imagej/table/CharTable.java create mode 100644 src/main/java/net/imagej/table/DefaultBoolTable.java create mode 100644 src/main/java/net/imagej/table/DefaultByteTable.java create mode 100644 src/main/java/net/imagej/table/DefaultCharTable.java create mode 100644 src/main/java/net/imagej/table/DefaultFloatTable.java create mode 100644 src/main/java/net/imagej/table/DefaultIntTable.java create mode 100644 src/main/java/net/imagej/table/DefaultLongTable.java create mode 100644 src/main/java/net/imagej/table/DefaultShortTable.java create mode 100644 src/main/java/net/imagej/table/FloatTable.java create mode 100644 src/main/java/net/imagej/table/IntTable.java create mode 100644 src/main/java/net/imagej/table/LongTable.java create mode 100644 src/main/java/net/imagej/table/ShortTable.java diff --git a/src/main/java/net/imagej/table/BoolTable.java b/src/main/java/net/imagej/table/BoolTable.java new file mode 100644 index 0000000..dd8d1d6 --- /dev/null +++ b/src/main/java/net/imagej/table/BoolTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of {@code boolean} values. + * + * @author Alison Walter + */ +public interface BoolTable extends Table { + + /** Gets the value of the given table cell. */ + boolean getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, boolean value); + +} diff --git a/src/main/java/net/imagej/table/ByteTable.java b/src/main/java/net/imagej/table/ByteTable.java new file mode 100644 index 0000000..4b1464e --- /dev/null +++ b/src/main/java/net/imagej/table/ByteTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of byte-precision integer values. + * + * @author Alison Walter + */ +public interface ByteTable extends Table { + + /** Gets the value of the given table cell. */ + byte getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, byte value); + +} diff --git a/src/main/java/net/imagej/table/CharTable.java b/src/main/java/net/imagej/table/CharTable.java new file mode 100644 index 0000000..29a22b2 --- /dev/null +++ b/src/main/java/net/imagej/table/CharTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of {@code char} values. + * + * @author Alison Walter + */ +public interface CharTable extends Table { + + /** Gets the value of the given table cell. */ + char getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, char value); + +} diff --git a/src/main/java/net/imagej/table/DefaultBoolTable.java b/src/main/java/net/imagej/table/DefaultBoolTable.java new file mode 100644 index 0000000..5b4110d --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultBoolTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link BoolTable}. + * + * @author Alison Walter + */ +public class DefaultBoolTable extends AbstractTable + implements BoolTable { + + /** Creates an empty boolean table. */ + public DefaultBoolTable() { + super(); + } + + /** Creates a boolean table with the given row and column dimensions. */ + public DefaultBoolTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- BoolTable methods -- + + @Override + public boolean getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final boolean value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected BoolColumn createColumn(String header) { + return new BoolColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultByteTable.java b/src/main/java/net/imagej/table/DefaultByteTable.java new file mode 100644 index 0000000..4a9c571 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultByteTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link ByteTable}. + * + * @author Alison Walter + */ +public class DefaultByteTable extends AbstractTable + implements ByteTable { + + /** Creates an empty byte table. */ + public DefaultByteTable() { + super(); + } + + /** Creates a byte table with the given row and column dimensions. */ + public DefaultByteTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- ByteTable methods -- + + @Override + public byte getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final byte value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected ByteColumn createColumn(String header) { + return new ByteColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultCharTable.java b/src/main/java/net/imagej/table/DefaultCharTable.java new file mode 100644 index 0000000..36d3106 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultCharTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link CharTable}. + * + * @author Alison Walter + */ +public class DefaultCharTable extends AbstractTable + implements CharTable { + + /** Creates an empty char table. */ + public DefaultCharTable() { + super(); + } + + /** Creates a char table with the given row and column dimensions. */ + public DefaultCharTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- CharTable methods -- + + @Override + public char getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final char value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected CharColumn createColumn(String header) { + return new CharColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultFloatTable.java b/src/main/java/net/imagej/table/DefaultFloatTable.java new file mode 100644 index 0000000..27ad517 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultFloatTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link FloatTable}. + * + * @author Alison Walter + */ +public class DefaultFloatTable extends AbstractTable + implements FloatTable { + + /** Creates an empty float table. */ + public DefaultFloatTable() { + super(); + } + + /** Creates a float table with the given row and column dimensions. */ + public DefaultFloatTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- FloatTable methods -- + + @Override + public float getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final float value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected FloatColumn createColumn(String header) { + return new FloatColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultIntTable.java b/src/main/java/net/imagej/table/DefaultIntTable.java new file mode 100644 index 0000000..0140784 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultIntTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link IntTable}. + * + * @author Alison Walter + */ +public class DefaultIntTable extends AbstractTable + implements IntTable { + + /** Creates an empty int table. */ + public DefaultIntTable() { + super(); + } + + /** Creates a int table with the given row and column dimensions. */ + public DefaultIntTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- IntTable methods -- + + @Override + public int getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final int value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected IntColumn createColumn(String header) { + return new IntColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultLongTable.java b/src/main/java/net/imagej/table/DefaultLongTable.java new file mode 100644 index 0000000..d6bc34d --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultLongTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link LongTable}. + * + * @author Alison Walter + */ +public class DefaultLongTable extends AbstractTable + implements LongTable { + + /** Creates an empty long table. */ + public DefaultLongTable() { + super(); + } + + /** Creates a long table with the given row and column dimensions. */ + public DefaultLongTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- LongTable methods -- + + @Override + public long getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final long value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected LongColumn createColumn(String header) { + return new LongColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/DefaultShortTable.java b/src/main/java/net/imagej/table/DefaultShortTable.java new file mode 100644 index 0000000..4945f73 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultShortTable.java @@ -0,0 +1,71 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * Default implementation of {@link ShortTable}. + * + * @author Alison Walter + */ +public class DefaultShortTable extends AbstractTable + implements ShortTable { + + /** Creates an empty short table. */ + public DefaultShortTable() { + super(); + } + + /** Creates a short table with the given row and column dimensions. */ + public DefaultShortTable(final int columnCount, final int rowCount) { + super(columnCount, rowCount); + } + + // -- ShortTable methods -- + + @Override + public short getValue(final int col, final int row) { + return get(col).getValue(row); + } + + @Override + public void setValue(final int col, final int row, final short value) { + get(col).setValue(row, value); + } + + // -- Internal methods -- + + @Override + protected ShortColumn createColumn(String header) { + return new ShortColumn(header); + } + +} diff --git a/src/main/java/net/imagej/table/FloatTable.java b/src/main/java/net/imagej/table/FloatTable.java new file mode 100644 index 0000000..26c49b1 --- /dev/null +++ b/src/main/java/net/imagej/table/FloatTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of float-precision floating point values. + * + * @author Alison Walter + */ +public interface FloatTable extends Table { + + /** Gets the value of the given table cell. */ + float getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, float value); + +} diff --git a/src/main/java/net/imagej/table/IntTable.java b/src/main/java/net/imagej/table/IntTable.java new file mode 100644 index 0000000..4942264 --- /dev/null +++ b/src/main/java/net/imagej/table/IntTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of int-precision integer values. + * + * @author Alison Walter + */ +public interface IntTable extends Table { + + /** Gets the value of the given table cell. */ + int getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, int value); + +} diff --git a/src/main/java/net/imagej/table/LongTable.java b/src/main/java/net/imagej/table/LongTable.java new file mode 100644 index 0000000..b2a17e1 --- /dev/null +++ b/src/main/java/net/imagej/table/LongTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of long-precision integer values. + * + * @author Alison Walter + */ +public interface LongTable extends Table { + + /** Gets the value of the given table cell. */ + long getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, long value); + +} diff --git a/src/main/java/net/imagej/table/ShortTable.java b/src/main/java/net/imagej/table/ShortTable.java new file mode 100644 index 0000000..cdaa357 --- /dev/null +++ b/src/main/java/net/imagej/table/ShortTable.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +/** + * A table of short-precision integer values. + * + * @author Alison Walter + */ +public interface ShortTable extends Table { + + /** Gets the value of the given table cell. */ + short getValue(int col, int row); + + /** Sets the value of the given table cell. */ + void setValue(int col, int row, short value); + +} From 9e35d9a2f14cea11b80883db4498b4dbe386c23f Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 12:42:21 -0500 Subject: [PATCH 14/42] Add tests for primitive table types and update ResultsTable test --- .../imagej/table/DefaultBoolTableTest.java | 111 ++++++++++++++++ .../imagej/table/DefaultByteTableTest.java | 110 ++++++++++++++++ .../imagej/table/DefaultCharTableTest.java | 112 ++++++++++++++++ .../imagej/table/DefaultFloatTableTest.java | 111 ++++++++++++++++ .../net/imagej/table/DefaultIntTableTest.java | 123 ++++++++++++++++++ .../imagej/table/DefaultLongTableTest.java | 106 +++++++++++++++ .../imagej/table/DefaultResultsTableTest.java | 44 ++++--- .../imagej/table/DefaultShortTableTest.java | 113 ++++++++++++++++ 8 files changed, 812 insertions(+), 18 deletions(-) create mode 100644 src/test/java/net/imagej/table/DefaultBoolTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultByteTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultCharTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultFloatTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultIntTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultLongTableTest.java create mode 100644 src/test/java/net/imagej/table/DefaultShortTableTest.java diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java new file mode 100644 index 0000000..33e9b9d --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -0,0 +1,111 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultBoolTable}. + * + * @author Alison Walter + */ +public class DefaultBoolTableTest { + + private static final String[] HEADERS = { "Header1", "Header2", "Header3" }; + + private static final boolean[][] DATA = { + { true, true, true }, + { true, true, false }, + { true, false, true }, + { true, false, false }, + { false, true, true }, + { false, true, false }, + { false, false, true }, + { false, false, false }, + }; + + @Test + public void testStructure() { + final BoolTable table = createTable(); + assertEquals(3, table.getColumnCount()); + assertEquals(8, table.getRowCount()); + for (final BoolColumn column : table) { + assertEquals(8, column.size()); + } + + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.get(n).getHeader(), HEADERS[n]); + } + + for (int c = 0; c < table.getColumnCount(); c++) { + final BoolColumn columnByHeader = table.get(HEADERS[c]); + final BoolColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r)); + assertEquals(DATA[r][c], columnByHeader.getValue(r)); + } + } + } + + @Test + public void testGetColumnType() { + final BoolTable table = createTable(); + final BoolColumn col = table.get(0); + assertEquals(col.getType(), Boolean.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private BoolTable createTable() { + final BoolTable table = new DefaultBoolTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java new file mode 100644 index 0000000..fa6a41c --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -0,0 +1,110 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultByteTable}. + * + * @author Alison Walter + */ +public class DefaultByteTableTest { + + private static final String[] HEADERS = { "Header1", "Header2" }; + + private static final byte[][] DATA = { + { 127, -45 }, + { -128, 0 }, + { 64, 17 }, + { -32, 6 }, + { 4, 98 }, + { -74, -104 }, + { 12, 89 }, + }; + + @Test + public void testStructure() { + final ByteTable table = createTable(); + assertEquals(2, table.getColumnCount()); + assertEquals(7, table.getRowCount()); + for (final ByteColumn column : table) { + assertEquals(7, column.size()); + } + + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.get(n).getHeader(), HEADERS[n]); + } + + for (int c = 0; c < table.getColumnCount(); c++) { + final ByteColumn columnByHeader = table.get(HEADERS[c]); + final ByteColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r)); + assertEquals(DATA[r][c], columnByHeader.getValue(r)); + } + } + } + + @Test + public void testGetColumnType() { + final ByteTable table = createTable(); + final ByteColumn col = table.get(0); + assertEquals(col.getType(), Byte.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private ByteTable createTable() { + final ByteTable table = new DefaultByteTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java new file mode 100644 index 0000000..aba356f --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -0,0 +1,112 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultCharTable}. + * + * @author Alison Walter + */ +public class DefaultCharTableTest { + + private static final String[] HEADERS = { "Header1", "Header2", "Header3" }; + + private static final char[][] DATA = { + { 'a', 'B', 'c' }, + { 'D', 'e', 'f' }, + { 'g', 'h', 'I'}, + { 'J', 'K', 'l' }, + { 'm', 'N', 'O' }, + { 'P', 'q', 'R' }, + { 's', 't', 'u' }, + { 'V', 'W', 'X' }, + { 'y', '&', 'z'}, + }; + + @Test + public void testStructure() { + final CharTable table = createTable(); + assertEquals(3, table.getColumnCount()); + assertEquals(9, table.getRowCount()); + for (final CharColumn column : table) { + assertEquals(9, column.size()); + } + + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.get(n).getHeader(), HEADERS[n]); + } + + for (int c = 0; c < table.getColumnCount(); c++) { + final CharColumn columnByHeader = table.get(HEADERS[c]); + final CharColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r)); + assertEquals(DATA[r][c], columnByHeader.getValue(r)); + } + } + } + + @Test + public void testGetColumnType() { + final CharTable table = createTable(); + final CharColumn col = table.get(0); + assertEquals(col.getType(), Character.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private CharTable createTable() { + final CharTable table = new DefaultCharTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java new file mode 100644 index 0000000..688c4e1 --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -0,0 +1,111 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultFloatTable}. + * + * @author Alison Walter + */ +public class DefaultFloatTableTest { + + private static final String[] HEADERS = { "Header1", "Header2", "Header3", + "Header4", "Header5" }; + + private static final float[][] DATA = { + { -4314.5f, 3214.015625f, -415.0078125f, 256f, 4.00390625f }, + { 5.125f, 0.25f, 4325.5f, -32.0625f, -9.0078125f }, + { 435.0009765625f, -5891.25f, -869.015625f, 3.00390625f, 75.015625f }, + { -5.00048828125f, -78.5f, 194.125f, -93.0009765625f, 923.25f }, + { 412f, 203985.03125f, 245.5f, -25.25f, -10943.0625f }, + { -0.125f, 6798.00048828125f, 2435.00024414062f, -42134.25f, 0f }, + { 35.0078125f, 298.125f, 698.0625f, 3405.5f, -3121.001953125f }, + }; + + @Test + public void testStructure() { + final FloatTable table = createTable(); + assertEquals(5, table.getColumnCount()); + assertEquals(7, table.getRowCount()); + for (final FloatColumn column : table) { + assertEquals(7, column.size()); + } + + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.get(n).getHeader(), HEADERS[n]); + } + + for (int c = 0; c < table.getColumnCount(); c++) { + final FloatColumn columnByHeader = table.get(HEADERS[c]); + final FloatColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r), 0); + assertEquals(DATA[r][c], columnByHeader.getValue(r), 0); + } + } + } + + @Test + public void testGetColumnType() { + final FloatTable table = createTable(); + final FloatColumn col = table.get(0); + assertEquals(col.getType(), Float.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private FloatTable createTable() { + final FloatTable table = new DefaultFloatTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java new file mode 100644 index 0000000..288b3df --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -0,0 +1,123 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultIntTable}. + * + * @author Alison Walter + */ +public class DefaultIntTableTest { + + private static final String[] HEADERS = { "Header1", "Header2", "Header3", + "Header4", "Header5", "Header6" }; + + private static final int[][] DATA = { + { 127, -45, 605, -123440804, -4082, 57823 }, + { 0, 0, 9, 12, 856, 1036 }, + { 17, 77, -684325, 894, -3246, 423 }, + { -3, -5234, 97, 93726, 672, -2 }, + { 4, 6, -22222222, 56234, -934270, -1938475430 }, + { 2147483647, -104, 867, -8, 386443263, 1248 }, + { 12, -2147483648, 456, 4652, -17, 95 }, + { 9275, -676, 7, 134, -32176368, 759 }, + { 184, 56, 104920256, 1436437635, -435, 1 }, + { 67, 3, -9, 94754, 4, -287934657 }, + { 48, -356, -748, -93784, 5879, 5 }, + { 289, 546453765, 0, 0, -6456, -23455 }, + { 768, -1411556, 7, 2356, 7925, 7468 }, + { -45, 25367, 546, 6757, -3, 1645 }, + { 1, 6, -2562345, -23565584, -35815, 956 }, + }; + + @Test + public void testStructure() { + final IntTable table = createTable(); + // Check table size + assertEquals(6, table.getColumnCount()); + assertEquals(15, table.getRowCount()); + for (final IntColumn column : table) { + assertEquals(15, column.size()); + } + + // Test headers + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.getColumnHeader(n), HEADERS[n]); + } + + // Test getting columns + for (int c = 0; c < table.getColumnCount(); c++) { + final IntColumn columnByHeader = table.get(HEADERS[c]); + final IntColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + // Test columns have expected row values + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r)); + assertEquals(DATA[r][c], columnByHeader.getValue(r)); + } + } + } + + @Test + public void testGetColumnType() { + final IntTable table = createTable(); + final IntColumn col = table.get(0); + assertEquals(col.getType(), Integer.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private IntTable createTable() { + final IntTable table = new DefaultIntTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java new file mode 100644 index 0000000..83793b6 --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -0,0 +1,106 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Tests {@link DefaultLongTable}. + * + * @author Alison Walter + */ +public class DefaultLongTableTest { + + private static final String[] HEADERS = { "Header1", "Header2" }; + + private static final long[][] DATA = { + { -9223372036854775808l, 9223372036854775807l }, + { 53, 0 }, + { 92, -1098570 }, + }; + + @Test + public void testStructure() { + final LongTable table = createTable(); + assertEquals(2, table.getColumnCount()); + assertEquals(3, table.getRowCount()); + for (final LongColumn column : table) { + assertEquals(3, column.size()); + } + + for (int n = 0; n < table.getColumnCount(); n++) { + assertEquals(table.get(n).getHeader(), HEADERS[n]); + } + + for (int c = 0; c < table.getColumnCount(); c++) { + final LongColumn columnByHeader = table.get(HEADERS[c]); + final LongColumn columnByIndex = table.get(c); + assertSame(columnByHeader, columnByIndex); + assertEquals(DATA.length, columnByHeader.size()); + for (int r = 0; r < table.getRowCount(); r++) { + assertEquals(DATA[r][c], table.getValue(c, r)); + assertEquals(DATA[r][c], columnByHeader.getValue(r)); + } + } + } + + @Test + public void testGetColumnType() { + final LongTable table = createTable(); + final LongColumn col = table.get(0); + assertEquals(col.getType(), Long.class); + } + + // TODO - Add more tests. + + // -- Helper methods -- + + private LongTable createTable() { + final LongTable table = new DefaultLongTable(DATA[0].length, DATA.length); + + for (int c = 0; c < HEADERS.length; c++) { + table.setColumnHeader(c, HEADERS[c]); + } + + for (int r = 0; r < DATA.length; r++) { + for (int c = 0; c < DATA[r].length; c++) { + table.setValue(c, r, DATA[r][c]); + } + } + + return table; + } + +} diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index b9ea3bc..28ea0af 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -40,6 +40,7 @@ * Tests {@link DefaultResultsTable}. * * @author Curtis Rueden + * @author Alison Walter */ public class DefaultResultsTableTest { @@ -70,23 +71,6 @@ public class DefaultResultsTableTest { {1998, 41, .281}, }; - public ResultsTable createTable() { - final ResultsTable table = - new DefaultResultsTable(DATA[0].length, DATA.length); - - for (int c=0; c Date: Mon, 6 Jun 2016 14:20:36 -0500 Subject: [PATCH 15/42] Initialize appended/inserted Column backing arrays When appending or inserting a new column into a table, the backing arrays for those columns will now be initialized. This prevents null pointer exceptions when attempting to modify appended or inserted columns. --- src/main/java/net/imagej/table/AbstractTable.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index f8969cb..491222b 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -143,6 +143,8 @@ public ArrayList insertColumns(final int col, final int count) { final ArrayList result = new ArrayList<>(count); for (int c = 0; c < count; c++) { final C column = createColumn(null); + // initialize array + column.setSize(getRowCount()); result.add(column); set(col + c, column); } From 459436c98e28f314fc8569c384641024640aba7e Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 10:27:23 -0500 Subject: [PATCH 16/42] Modify removeRows to use zero indexing --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index 491222b..bdf6c18 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -322,7 +322,7 @@ public void removeRows(final int row, final int count) { final int oldRowCount = getRowCount(); final int newRowCount = oldRowCount - count; // copy data after the deleted range into the new position - for (int oldR = row; oldR < oldRowCount; oldR++) { + for (int oldR = row+1; oldR < oldRowCount; oldR++) { final int newR = oldR - count; setRowHeader(newR, getRowHeader(oldR)); for (int c = 0; c < getColumnCount(); c++) { From 3e7f24897b5334ca0c3a79c010f98bc5954b630f Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 14:15:35 -0500 Subject: [PATCH 17/42] Add tests for remove/append a row/column to tables --- .../imagej/table/DefaultBoolTableTest.java | 102 +++++++++++++++++ .../imagej/table/DefaultByteTableTest.java | 102 +++++++++++++++++ .../imagej/table/DefaultCharTableTest.java | 102 +++++++++++++++++ .../imagej/table/DefaultFloatTableTest.java | 103 +++++++++++++++++ .../net/imagej/table/DefaultIntTableTest.java | 104 +++++++++++++++++ .../imagej/table/DefaultLongTableTest.java | 103 +++++++++++++++++ .../imagej/table/DefaultResultsTableTest.java | 107 +++++++++++++++++- .../imagej/table/DefaultShortTableTest.java | 103 +++++++++++++++++ 8 files changed, 825 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index 33e9b9d..17b384a 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -88,6 +88,66 @@ public void testGetColumnType() { assertEquals(col.getType(), Boolean.class); } + @Test + public void testAppendColumn() { + final BoolTable table = createTable(); + final Boolean[] values = + { true, true, true, true, false, true, false, true }; + + final BoolColumn col = table.appendColumn("Header4"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(3).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 3); + } + + @Test + public void testRemoveColumn() { + final BoolTable table = createTable(); + final BoolColumn col = table.removeColumn(2); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][2]); + } + assertEquals(table.getColumnCount(), 2); + + checkTableModifiedColumn(table, null, 2); + } + + @Test + public void testAppendRow() { + final BoolTable table = createTable(); + final boolean[] values = { true, true, false }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 9); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 8, values[i]); + assertEquals(table.getValue(i, 8), values[i]); + } + + checkTableModifiedRow(table, values, 8); + } + + @Test + public void testRemoveRow() { + final BoolTable table = createTable(); + + table.removeRow(1); + + assertEquals(table.getRowCount(), 7); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 1), DATA[2][i]); + } + + checkTableModifiedRow(table, null, 1); + } + // TODO - Add more tests. // -- Helper methods -- @@ -108,4 +168,46 @@ private BoolTable createTable() { return table; } + private void checkTableModifiedColumn(final BoolTable table, + final Boolean[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r]); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final BoolTable table, + final boolean[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index fa6a41c..6d7981c 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -87,6 +87,66 @@ public void testGetColumnType() { assertEquals(col.getType(), Byte.class); } + @Test + public void testAppendColumn() { + final ByteTable table = createTable(); + final Byte[] values = { 17, 23, -12, 0, -93, -7, 127 }; + + final ByteColumn col = table.appendColumn("Header3"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 3); + assertEquals(table.get(2).getHeader(), "Header3"); + + checkTableModifiedColumn(table, values, 2); + } + + @Test + public void testRemoveColumn() { + final ByteTable table = createTable(); + final ByteColumn col = table.removeColumn(1); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][1]); + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumn(table, null, 1); + } + + @Test + public void testAppendRow() { + final ByteTable table = createTable(); + final byte[] values = { 79, 8 }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 8); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 7, values[i]); + assertEquals(table.getValue(i, 7), values[i]); + } + + checkTableModifiedRow(table, values, 7); + } + + @Test + public void testRemoveRow() { + final ByteTable table = createTable(); + + // Test removing a row + table.removeRow(2); + + assertEquals(table.getRowCount(), 6); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 2), DATA[3][i]); + } + + checkTableModifiedRow(table, null, 2); + } + // TODO - Add more tests. // -- Helper methods -- @@ -107,4 +167,46 @@ private ByteTable createTable() { return table; } + private void checkTableModifiedColumn(final ByteTable table, + final Byte[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].byteValue()); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final ByteTable table, + final byte[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index aba356f..59e79fa 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -89,6 +89,66 @@ public void testGetColumnType() { assertEquals(col.getType(), Character.class); } + @Test + public void testAppendColumn() { + final CharTable table = createTable(); + final Character[] values = { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }; + + final CharColumn col = table.appendColumn("Header4"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(3).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 3); + } + + @Test + public void testRemoveColumn() { + final CharTable table = createTable(); + + final CharColumn col = table.removeColumn(2); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][2]); + } + assertEquals(table.getColumnCount(), 2); + + checkTableModifiedColumn(table, null, 2); + } + + @Test + public void testAppendRow() { + final CharTable table = createTable(); + final char[] values = { '\t', '\uffff', '\u0000' }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 10); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 9, values[i]); + assertEquals(table.getValue(i, 9), values[i]); + } + + checkTableModifiedRow(table, values, 9); + } + + @Test + public void testRemoveRow() { + final CharTable table = createTable(); + + // Test removing a row + table.removeRow(7); + assertEquals(table.getRowCount(), 8); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 7), DATA[8][i]); + } + + checkTableModifiedRow(table, null, 7); + } + // TODO - Add more tests. // -- Helper methods -- @@ -109,4 +169,46 @@ private CharTable createTable() { return table; } + private void checkTableModifiedColumn(final CharTable table, + final Character[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].charValue()); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final CharTable table, final char[] values, + final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index 688c4e1..148cbc8 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -88,6 +88,67 @@ public void testGetColumnType() { assertEquals(col.getType(), Float.class); } + @Test + public void testAppendColumn() { + final FloatTable table = createTable(); + final Float[] values = + { 17.0625f, 22.125f, -0.00000762939f, 0f, -2.03125f, -717.5f, 127.5f }; + + final FloatColumn col = table.appendColumn("Header6"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 6); + assertEquals(table.getColumnHeader(5), "Header6"); + + checkTableModifiedColumn(table, values, 5); + } + + @Test + public void testRemoveColumn() { + final FloatTable table = createTable(); + final FloatColumn col = table.removeColumn(1); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][1], 0); + } + assertEquals(table.getColumnCount(), 4); + + checkTableModifiedColumn(table, null, 1); + } + + @Test + public void testAppendRow() { + final FloatTable table = createTable(); + final float[] values = { -0.0625f, 5.5f, -4.03125f, 46.125f, 10489.5f }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 8); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 7, values[i]); + assertEquals(table.getValue(i, 7), values[i], 0); + } + + checkTableModifiedRow(table, values, 7); + } + + @Test + public void testRemoveRow() { + final FloatTable table = createTable(); + + // Test removing a row + table.removeRow(4); + + assertEquals(table.getRowCount(), 6); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 4), DATA[5][i], 0); + } + + checkTableModifiedRow(table, null, 4); + } + // TODO - Add more tests. // -- Helper methods -- @@ -108,4 +169,46 @@ private FloatTable createTable() { return table; } + private void checkTableModifiedColumn(final FloatTable table, + final Float[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].floatValue(), 0); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1], 0); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + + private void checkTableModifiedRow(final FloatTable table, + final float[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c], 0); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c], 0); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index 288b3df..e75db50 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -100,6 +100,68 @@ public void testGetColumnType() { assertEquals(col.getType(), Integer.class); } + @Test + public void testAppendColumn() { + final IntTable table = createTable(); + final Integer[] values = + { 30, 3109842, 28, 25, -432579, 22, -12, 0, 54235423, -7858345, -34, -3, + -35648443, 43512356, 999 }; + + final IntColumn col = table.appendColumn("Header7"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(6).getHeader(), "Header7"); + + checkTableModifiedColumn(table, values, 6); + } + + @Test + public void testRemoveColumn() { + final IntTable table = createTable(); + + // Test removing a column + final IntColumn col = table.removeColumn(5); + + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][5]); + } + assertEquals(table.getColumnCount(), 5); + + checkTableModifiedColumn(table, null, 5); + } + + @Test + public void testAppendRow() { + final IntTable table = createTable(); + final int[] values = { 179, 43148, -36, 1, 6, -356 }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 16); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 15, values[i]); + assertEquals(table.getValue(i, 15), values[i]); + } + + checkTableModifiedRow(table, values, 15); + } + + @Test + public void testRemoveRow() { + final IntTable table = createTable(); + + // Test removing a row + table.removeRow(10); + assertEquals(table.getRowCount(), 14); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 10), DATA[11][i]); + } + + checkTableModifiedRow(table, null, 10); + } + // TODO - Add more tests. // -- Helper methods -- @@ -120,4 +182,46 @@ private IntTable createTable() { return table; } + private void checkTableModifiedColumn(final IntTable table, + final Integer[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].intValue()); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final IntTable table, final int[] values, + final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index 83793b6..30638c9 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -83,6 +83,67 @@ public void testGetColumnType() { assertEquals(col.getType(), Long.class); } + @Test + public void testAppendColumn() { + final LongTable table = createTable(); + final Long[] values = { 542908l, 9574597419085l, -11l }; + + final LongColumn col = table.appendColumn("Header3"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 3); + assertEquals(table.get(2).getHeader(), "Header3"); + + checkTableModifiedColumn(table, values, 2); + } + + @Test + public void testRemoveColumn() { + final LongTable table = createTable(); + + final LongColumn col = table.removeColumn(1); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][1]); + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumn(table, null, 1); + } + + @Test + public void testAppendRow() { + final LongTable table = createTable(); + final long[] values = { 301984l, 15l }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 4); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 3, values[i]); + assertEquals(table.getValue(i, 3), values[i]); + } + + checkTableModifiedRow(table, values, 3); + } + + @Test + public void testRemoveRow() { + final LongTable table = createTable(); + + // Test removing a row + table.removeRow(0); + + assertEquals(table.getRowCount(), 2); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 0), DATA[1][i]); + } + + checkTableModifiedRow(table, null, 0); + } + // TODO - Add more tests. // -- Helper methods -- @@ -103,4 +164,46 @@ private LongTable createTable() { return table; } + private void checkTableModifiedColumn(final LongTable table, + final Long[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].longValue()); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final LongTable table, + final long[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index 28ea0af..c0d3ef1 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -103,6 +103,69 @@ public void testGetColumnType() { assertEquals(col.getType(), Double.class); } + @Test + public void testAppendColumn() { + final ResultsTable table = createTable(); + final Double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, + 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, + -0.0325, 940385034958.5, -301284390284.25, 17.25 }; + + final DoubleColumn col = table.appendColumn("Header4"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(3).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 3); + } + + @Test + public void testRemoveColumn() { + final ResultsTable table = createTable(); + final DoubleColumn col = table.removeColumn(0); + + // Test removing a column + for (int i = 0; i < col.size(); i++) { + assertEquals(col.getValue(i), DATA[i][0], 0); + } + assertEquals(table.getColumnCount(), 2); + + checkTableModifiedColumn(table, null, 0); + } + + @Test + public void testAppendRow() { + final ResultsTable table = createTable(); + final double[] values = { 1999, 42, 0.0 }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 22); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 21, values[i]); + assertEquals(table.getValue(i, 21), values[i], 0); + } + + checkTableModifiedRow(table, values, 21); + } + + @Test + public void testRemoveRow() { + final ResultsTable table = createTable(); + + table.removeRow(4); + + assertEquals(table.getRowCount(), 20); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 4), DATA[5][i], 0); + } + + checkTableModifiedRow(table, null, 4); + } + + //TODO - Add more tests. + // -- Helper methods -- private ResultsTable createTable() { @@ -122,4 +185,46 @@ private ResultsTable createTable() { return table; } -} + private void checkTableModifiedColumn(final ResultsTable table, + final Double[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r], 0); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1], 0); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + + private void checkTableModifiedRow(final ResultsTable table, + final double[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c], 0); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c], 0); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + +} \ No newline at end of file diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index 5c82faf..7c45d75 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -90,6 +90,67 @@ public void testGetColumnType() { assertEquals(col.getType(), Short.class); } + @Test + public void testAppendColumn() { + final ShortTable table = createTable(); + final Short[] values = { -11, 32000, 9798, -18687, 97 }; + + final ShortColumn col = table.appendColumn("Header5"); + col.fill(values); + + // Test appending a column + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(4).getHeader(), "Header5"); + + checkTableModifiedColumn(table, values, 4); + } + + @Test + public void testRemoveColumn() { + final ShortTable table = createTable(); + + final ShortColumn col2 = table.removeColumn(2); + + // Test removing a column + for (int i = 0; i < col2.size(); i++) { + assertEquals(col2.getValue(i), DATA[i][2]); + } + assertEquals(table.getColumnCount(), 3); + + checkTableModifiedColumn(table, null, 2); + } + + @Test + public void testAppendRow() { + final ShortTable table = createTable(); + final short[] values = { 7911, 937, -1508, -8 }; + + // Test appending a row + table.appendRow(); + assertEquals(table.getRowCount(), 6); + for (int i = 0; i < values.length; i++) { + table.setValue(i, 5, values[i]); + assertEquals(table.getValue(i, 5), values[i]); + } + + checkTableModifiedRow(table, values, 5); + } + + @Test + public void testRemoveRow() { + final ShortTable table = createTable(); + + // Test removing a row + table.removeRow(2); + + assertEquals(table.getRowCount(), 4); + for (int i = 0; i < table.getColumnCount(); i++) { + assertEquals(table.getValue(i, 2), DATA[3][i]); + } + + checkTableModifiedRow(table, null, 2); + } + // TODO - Add more tests. // -- Helper methods -- @@ -110,4 +171,46 @@ private ShortTable createTable() { return table; } + private void checkTableModifiedColumn(final ShortTable table, + final Short[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c == mod && values != null ) { + assertEquals(table.getValue(c, r), values[r].shortValue()); + } + else if ( c > mod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - 1]); + } + else if ( c >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + 1]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRow(final ShortTable table, + final short[] values, final int mod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r == mod && values != null ) { + assertEquals(table.getValue(c, r), values[c]); + } + else if ( r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r-1][c]); + } + else if ( r >= mod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r+1][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } From 08f1fa5b763552c76055d7b03cc0731bfd4c183e Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 10 Jun 2016 12:46:29 -0500 Subject: [PATCH 18/42] Fix insert rows/columns operations The loops for shifting the rows/columns now loop backwards. This was done because if the loops go forwards it doesn't shift the rows/columns, it instead repeats the column/row following the insert. --- src/main/java/net/imagej/table/AbstractTable.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index bdf6c18..3a5a1d0 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -134,7 +134,7 @@ public ArrayList insertColumns(final int col, final int count) { setColumnCount(newColCount); // copy columns after the inserted range into the new position - for (int oldC = col; oldC < oldColCount; oldC++) { + for (int oldC = oldColCount - 1; oldC >= col; oldC--) { final int newC = oldC + count; set(newC, get(oldC)); } @@ -263,7 +263,9 @@ public void insertRows(final int row, final int count) { setRowCount(newRowCount); // copy data after the inserted range into the new position - for (int oldR = row; oldR < oldRowCount; oldR++) { + // NB: This loop goes backwards to prevent the same row from being copied + // over and over again. + for (int oldR = oldRowCount - 1; oldR >= row; oldR--) { final int newR = oldR + count; for (int c = 0; c < getColumnCount(); c++) { set(c, newR, get(c, oldR)); From 9bde616d168e045a1449b6ff5935b7389868d74f Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 14:19:00 -0500 Subject: [PATCH 19/42] Add tests for inserting a row/column to ResultsTable --- .../imagej/table/DefaultResultsTableTest.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index c0d3ef1..1d33e83 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -134,6 +134,22 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 0); } + @Test + public void testInsertColumn() { + final ResultsTable table = createTable(); + final Double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, + 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, + -0.0325, 940385034958.5, -301284390284.25, 17.25 }; + + final DoubleColumn col = table.insertColumn(1, "Header4"); + col.fill(values); + + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(1).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 1); + } + @Test public void testAppendRow() { final ResultsTable table = createTable(); @@ -164,6 +180,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 4); } + @Test + public void testRowInsert() { + final ResultsTable table = createTable(); + final double[] values = { 1999, 42, 0.0 }; + + table.insertRow(6); + + assertEquals(table.getRowCount(), 22); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 6, values[i]); + } + + checkTableModifiedRow(table, values, 6); + } + //TODO - Add more tests. // -- Helper methods -- From b2bfdee177d8cd66b53db8a439d67bfe7a3e3c4e Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 12:05:09 -0500 Subject: [PATCH 20/42] Fix removeColumns to allow removal of columns starting zero --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index 3a5a1d0..c527349 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -188,7 +188,7 @@ public ArrayList removeColumns(final int col, final int count) { final int newColCount = oldColCount - count; // copy data after the deleted range into the new position - for (int oldC = col; oldC < oldColCount; oldC++) { + for (int oldC = col+count; oldC < oldColCount; oldC++) { final int newC = oldC - count; set(newC, get(oldC)); } From 3a0fed88a7b150e5b621eaf4adac9ba0c9e0e080 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 12:10:52 -0500 Subject: [PATCH 21/42] Fix removeRows to start at specified row Prior to this change the removal would end at the specified row, instead of starting from it. --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index c527349..55e8230 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -324,7 +324,7 @@ public void removeRows(final int row, final int count) { final int oldRowCount = getRowCount(); final int newRowCount = oldRowCount - count; // copy data after the deleted range into the new position - for (int oldR = row+1; oldR < oldRowCount; oldR++) { + for (int oldR = row+count; oldR < oldRowCount; oldR++) { final int newR = oldR - count; setRowHeader(newR, getRowHeader(oldR)); for (int c = 0; c < getColumnCount(); c++) { From 6280b4efe1e2e7049031179df8092cf1cab779fc Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 14:38:16 -0500 Subject: [PATCH 22/42] Add tests for removing/adding rows/columns to ResultsTable --- .../imagej/table/DefaultResultsTableTest.java | 167 +++++++++++++++++- 1 file changed, 166 insertions(+), 1 deletion(-) diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index 1d33e83..0f2baf0 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -150,6 +152,72 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 1); } + @Test + public void testAppendColumns() { + final ResultsTable table = createTable(); + final Double[][] values = { + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }, + { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, + -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, + -1.25, 17.25 } + }; + + final String[] headers = {"Header4", "Header5"}; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + // Test appending a column + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(3).getHeader(), "Header4"); + assertEquals(table.get(4).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 3, 4); + } + + @Test + public void testRemoveColumns() { + final ResultsTable table = createTable(); + + final List col = table.removeColumns(0,2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q], 0); + } + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumns(table, null, 0, 2); + } + + @Test + public void testInsertColumns() { + final ResultsTable table = createTable(); + final Double[][] values = { + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }, + { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, + -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, + -1.25, 17.25 } + }; + + final String[] headers = {"Header4", "Header5"}; + final List col = table.insertColumns(1, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(1).getHeader(), "Header4"); + assertEquals(table.get(2).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 1, 2); + } + @Test public void testAppendRow() { final ResultsTable table = createTable(); @@ -181,7 +249,7 @@ public void testRemoveRow() { } @Test - public void testRowInsert() { + public void testInsertRow() { final ResultsTable table = createTable(); final double[] values = { 1999, 42, 0.0 }; @@ -195,6 +263,61 @@ public void testRowInsert() { checkTableModifiedRow(table, values, 6); } + @Test + public void testAppendRows() { + final ResultsTable table = createTable(); + final double[][] values = { + { 1999, 42, 0.123 }, + { 2000, 43, 0.006 }, + { 2001, 44, 0.89 }, + { 2002, 45, 0.0 }, + }; + + // Test appending a row + table.appendRows(4); + assertEquals(table.getRowCount(), 25); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 21, values[r][c]); + assertEquals(table.getValue(c, r + 21), values[r][c], 0); + } + } + + checkTableModifiedRows(table, values, 21, 24); + } + + @Test + public void testRemoveRows() { + final ResultsTable table = createTable(); + table.removeRows(11, 6); + assertEquals(table.getRowCount(), 15); + + checkTableModifiedRows(table, null, 11, 16); + } + + @Test + public void testInsertRows() { + final ResultsTable table = createTable(); + final double[][] values = { + { 1999, 42, 0.123 }, + { 2000, 43, 0.006 }, + { 2001, 44, 0.89 }, + { 2002, 45, 0.0 }, + }; + + table.insertRows(3, 4); + + assertEquals(table.getRowCount(), 25); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 3, values[r][c]); + assertEquals(table.getValue(c, r + 3), values[r][c], 0); + } + } + + checkTableModifiedRows(table, values, 3, 6); + } + //TODO - Add more tests. // -- Helper methods -- @@ -258,4 +381,46 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final ResultsTable table, + final Double[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( c >= startMod && c <= endMod && values != null ) { + assertEquals(table.getValue(c, r), values[c - startMod][r], 0); + } + else if ( c > endMod && values != null ) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length], 0); + } + else if ( c >= startMod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod-startMod)], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + + private void checkTableModifiedRows(final ResultsTable table, + final double[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if ( r >= startMod && r <= endMod && values != null ) { + assertEquals(table.getValue(c, r), values[r - startMod][c], 0); + } + else if ( r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c], 0); + } + else if ( r >= startMod && values == null ) { + assertEquals(table.getValue(c, r), DATA[r + (endMod-startMod + 1)][c], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + } \ No newline at end of file From 447c4ef18582dff9548797d877766b3265819bdf Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 14:49:48 -0500 Subject: [PATCH 23/42] Clean up table test --- .../imagej/table/DefaultResultsTableTest.java | 88 ++++++++++--------- 1 file changed, 46 insertions(+), 42 deletions(-) diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index 0f2baf0..efe8d86 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -46,7 +46,7 @@ */ public class DefaultResultsTableTest { - private static final String[] HEADERS = {"Year", "Age", "BA"}; + private static final String[] HEADERS = { "Year", "Age", "BA" }; // Paul Molitor private static final double[][] DATA = { @@ -78,7 +78,7 @@ public void testStructure() { final ResultsTable table = createTable(); assertEquals(3, table.getColumnCount()); assertEquals(21, table.getRowCount()); - for (DoubleColumn column : table) { + for (final DoubleColumn column : table) { assertEquals(21, column.size()); } @@ -108,9 +108,10 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final ResultsTable table = createTable(); - final Double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, - 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, - -0.0325, 940385034958.5, -301284390284.25, 17.25 }; + final Double[] values = + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }; final DoubleColumn col = table.appendColumn("Header4"); col.fill(values); @@ -139,9 +140,10 @@ public void testRemoveColumn() { @Test public void testInsertColumn() { final ResultsTable table = createTable(); - final Double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, - 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, - -0.0325, 940385034958.5, -301284390284.25, 17.25 }; + final Double[] values = + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }; final DoubleColumn col = table.insertColumn(1, "Header4"); col.fill(values); @@ -155,16 +157,16 @@ public void testInsertColumn() { @Test public void testAppendColumns() { final ResultsTable table = createTable(); - final Double[][] values = { - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }, + final Double[][] values = + { + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }, { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, - -1.25, 17.25 } - }; + -1.25, 17.25 } }; - final String[] headers = {"Header4", "Header5"}; + final String[] headers = { "Header4", "Header5" }; final List col = table.appendColumns(headers); col.get(0).fill(values[0]); col.get(1).fill(values[1]); @@ -181,7 +183,7 @@ public void testAppendColumns() { public void testRemoveColumns() { final ResultsTable table = createTable(); - final List col = table.removeColumns(0,2); + final List col = table.removeColumns(0, 2); // Test removing a column for (int q = 0; q < col.size(); q++) { @@ -197,16 +199,16 @@ public void testRemoveColumns() { @Test public void testInsertColumns() { final ResultsTable table = createTable(); - final Double[][] values = { - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }, + final Double[][] values = + { + { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, + 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, + 940385034958.5, -301284390284.25, 17.25 }, { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, - -1.25, 17.25 } - }; + -1.25, 17.25 } }; - final String[] headers = {"Header4", "Header5"}; + final String[] headers = { "Header4", "Header5" }; final List col = table.insertColumns(1, headers); col.get(0).fill(values[0]); col.get(1).fill(values[1]); @@ -318,7 +320,7 @@ public void testInsertRows() { checkTableModifiedRows(table, values, 3, 6); } - //TODO - Add more tests. + // TODO - Add more tests. // -- Helper methods -- @@ -326,7 +328,7 @@ private ResultsTable createTable() { final ResultsTable table = new DefaultResultsTable(DATA[0].length, DATA.length); - for (int c=0; c mod && values != null ) { + else if (c > mod && values != null) { assertEquals(table.getValue(c, r), DATA[r][c - 1], 0); } - else if ( c >= mod && values == null ) { + else if (c >= mod && values == null) { assertEquals(table.getValue(c, r), DATA[r][c + 1], 0); } else { @@ -365,14 +367,14 @@ private void checkTableModifiedRow(final ResultsTable table, { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { - if ( r == mod && values != null ) { + if (r == mod && values != null) { assertEquals(table.getValue(c, r), values[c], 0); } - else if ( r > mod && values != null) { - assertEquals(table.getValue(c, r), DATA[r-1][c], 0); + else if (r > mod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - 1][c], 0); } - else if ( r >= mod && values == null ) { - assertEquals(table.getValue(c, r), DATA[r+1][c], 0); + else if (r >= mod && values == null) { + assertEquals(table.getValue(c, r), DATA[r + 1][c], 0); } else { assertEquals(table.getValue(c, r), DATA[r][c], 0); @@ -386,14 +388,15 @@ private void checkTableModifiedColumns(final ResultsTable table, { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { - if ( c >= startMod && c <= endMod && values != null ) { + if (c >= startMod && c <= endMod && values != null) { assertEquals(table.getValue(c, r), values[c - startMod][r], 0); } - else if ( c > endMod && values != null ) { + else if (c > endMod && values != null) { assertEquals(table.getValue(c, r), DATA[r][c - values.length], 0); } - else if ( c >= startMod && values == null ) { - assertEquals(table.getValue(c, r), DATA[r][c + (endMod-startMod)], 0); + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)], + 0); } else { assertEquals(table.getValue(c, r), DATA[r][c], 0); @@ -407,14 +410,15 @@ private void checkTableModifiedRows(final ResultsTable table, { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { - if ( r >= startMod && r <= endMod && values != null ) { + if (r >= startMod && r <= endMod && values != null) { assertEquals(table.getValue(c, r), values[r - startMod][c], 0); } - else if ( r > endMod && values != null) { + else if (r > endMod && values != null) { assertEquals(table.getValue(c, r), DATA[r - values.length][c], 0); } - else if ( r >= startMod && values == null ) { - assertEquals(table.getValue(c, r), DATA[r + (endMod-startMod + 1)][c], 0); + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c], 0); } else { assertEquals(table.getValue(c, r), DATA[r][c], 0); @@ -423,4 +427,4 @@ else if ( r >= startMod && values == null ) { } } -} \ No newline at end of file +} From 6af44ca451736b644ee0eac416e153ecfccb096f Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 15 Jun 2016 17:13:35 -0500 Subject: [PATCH 24/42] Create and implement PrimitiveColumn, and update tests --- .../java/net/imagej/table/BoolColumn.java | 29 ++++------ src/main/java/net/imagej/table/BoolTable.java | 8 ++- .../java/net/imagej/table/ByteColumn.java | 29 ++++------ src/main/java/net/imagej/table/ByteTable.java | 8 ++- .../java/net/imagej/table/CharColumn.java | 29 ++++------ src/main/java/net/imagej/table/CharTable.java | 8 ++- src/main/java/net/imagej/table/Column.java | 6 --- .../net/imagej/table/DefaultBoolTable.java | 15 +----- .../net/imagej/table/DefaultByteTable.java | 15 +----- .../net/imagej/table/DefaultCharTable.java | 15 +----- .../java/net/imagej/table/DefaultColumn.java | 10 ---- .../net/imagej/table/DefaultFloatTable.java | 15 +----- .../net/imagej/table/DefaultIntTable.java | 15 +----- .../net/imagej/table/DefaultLongTable.java | 15 +----- .../net/imagej/table/DefaultResultsTable.java | 10 ---- .../net/imagej/table/DefaultShortTable.java | 15 +----- .../java/net/imagej/table/DoubleColumn.java | 29 ++++------ .../java/net/imagej/table/FloatColumn.java | 29 ++++------ .../java/net/imagej/table/FloatTable.java | 8 ++- src/main/java/net/imagej/table/IntColumn.java | 29 ++++------ src/main/java/net/imagej/table/IntTable.java | 8 ++- .../java/net/imagej/table/LongColumn.java | 29 ++++------ src/main/java/net/imagej/table/LongTable.java | 8 ++- .../net/imagej/table/PrimitiveColumn.java | 54 +++++++++++++++++++ .../java/net/imagej/table/ResultsTable.java | 8 ++- .../java/net/imagej/table/ShortColumn.java | 29 ++++------ .../java/net/imagej/table/ShortTable.java | 8 ++- .../imagej/table/DefaultBoolTableTest.java | 4 +- .../imagej/table/DefaultByteTableTest.java | 6 +-- .../imagej/table/DefaultCharTableTest.java | 6 +-- .../imagej/table/DefaultFloatTableTest.java | 6 +-- .../net/imagej/table/DefaultIntTableTest.java | 6 +-- .../imagej/table/DefaultLongTableTest.java | 6 +-- .../imagej/table/DefaultResultsTableTest.java | 12 ++--- .../imagej/table/DefaultShortTableTest.java | 6 +-- 35 files changed, 222 insertions(+), 311 deletions(-) create mode 100644 src/main/java/net/imagej/table/PrimitiveColumn.java diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index e7c6f33..0d1aab1 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class BoolColumn extends BoolArray implements Column { +public class BoolColumn extends BoolArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Boolean.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Boolean[] values) { - final boolean[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final boolean[] values) { + setArray(values.clone()); } @Override - public void fill(final Boolean[] values, final int offset) { - final boolean[] prim = toPrimitive(values); - + public void fill(final boolean[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values.clone()); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private boolean[] toPrimitive(final Boolean[] values) { - final boolean[] prim = new boolean[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].booleanValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/BoolTable.java b/src/main/java/net/imagej/table/BoolTable.java index dd8d1d6..ee02953 100644 --- a/src/main/java/net/imagej/table/BoolTable.java +++ b/src/main/java/net/imagej/table/BoolTable.java @@ -39,9 +39,13 @@ public interface BoolTable extends Table { /** Gets the value of the given table cell. */ - boolean getValue(int col, int row); + default boolean getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, boolean value); + default void setValue(final int col, final int row, final boolean value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index 9dd371b..d751b54 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class ByteColumn extends ByteArray implements Column { +public class ByteColumn extends ByteArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Byte.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Byte[] values) { - final byte[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final byte[] values) { + setArray(values.clone()); } @Override - public void fill(final Byte[] values, final int offset) { - final byte[] prim = toPrimitive(values); - + public void fill(final byte[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values.clone()); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private byte[] toPrimitive(final Byte[] values) { - final byte[] prim = new byte[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].byteValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/ByteTable.java b/src/main/java/net/imagej/table/ByteTable.java index 4b1464e..57ee34e 100644 --- a/src/main/java/net/imagej/table/ByteTable.java +++ b/src/main/java/net/imagej/table/ByteTable.java @@ -39,9 +39,13 @@ public interface ByteTable extends Table { /** Gets the value of the given table cell. */ - byte getValue(int col, int row); + default byte getValue(int col, int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, byte value); + default void setValue(int col, int row, byte value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index 87107f1..084df50 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class CharColumn extends CharArray implements Column { +public class CharColumn extends CharArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Character.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Character[] values) { - final char[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final char[] values) { + setArray(values.clone()); } @Override - public void fill(final Character[] values, final int offset) { - final char[] prim = toPrimitive(values); - + public void fill(final char[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values.clone()); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private char[] toPrimitive(final Character[] values) { - final char[] prim = new char[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].charValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/CharTable.java b/src/main/java/net/imagej/table/CharTable.java index 29a22b2..c289afc 100644 --- a/src/main/java/net/imagej/table/CharTable.java +++ b/src/main/java/net/imagej/table/CharTable.java @@ -39,9 +39,13 @@ public interface CharTable extends Table { /** Gets the value of the given table cell. */ - char getValue(int col, int row); + default char getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, char value); + default void setValue(final int col, final int row, final char value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index 0cbbf15..e0273ed 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -60,10 +60,4 @@ public interface Column extends List, Sizable { /** Returns the actual type of data stored in the column. */ Class getType(); - /** Fills the column with the values in the given array. */ - void fill(T[] values); - - /** Fills the column with the values in the given array. */ - void fill(T[] values, int offset); - } diff --git a/src/main/java/net/imagej/table/DefaultBoolTable.java b/src/main/java/net/imagej/table/DefaultBoolTable.java index 5b4110d..c4bcdca 100644 --- a/src/main/java/net/imagej/table/DefaultBoolTable.java +++ b/src/main/java/net/imagej/table/DefaultBoolTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultBoolTable extends AbstractTable - implements BoolTable { + implements BoolTable +{ /** Creates an empty boolean table. */ public DefaultBoolTable() { @@ -49,18 +50,6 @@ public DefaultBoolTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- BoolTable methods -- - - @Override - public boolean getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final boolean value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultByteTable.java b/src/main/java/net/imagej/table/DefaultByteTable.java index 4a9c571..6df54b5 100644 --- a/src/main/java/net/imagej/table/DefaultByteTable.java +++ b/src/main/java/net/imagej/table/DefaultByteTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultByteTable extends AbstractTable - implements ByteTable { + implements ByteTable +{ /** Creates an empty byte table. */ public DefaultByteTable() { @@ -49,18 +50,6 @@ public DefaultByteTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- ByteTable methods -- - - @Override - public byte getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final byte value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultCharTable.java b/src/main/java/net/imagej/table/DefaultCharTable.java index 36d3106..d33d54f 100644 --- a/src/main/java/net/imagej/table/DefaultCharTable.java +++ b/src/main/java/net/imagej/table/DefaultCharTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultCharTable extends AbstractTable - implements CharTable { + implements CharTable +{ /** Creates an empty char table. */ public DefaultCharTable() { @@ -49,18 +50,6 @@ public DefaultCharTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- CharTable methods -- - - @Override - public char getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final char value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index 3025326..a4e786c 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -71,14 +71,4 @@ public Class getType() { return type; } - @Override - public void fill(final T[] values) { - fill(values, 0); - } - - @Override - public void fill(final T[] values, final int offset) { - System.arraycopy(values, 0, this.toArray(), 0, values.length); - } - } diff --git a/src/main/java/net/imagej/table/DefaultFloatTable.java b/src/main/java/net/imagej/table/DefaultFloatTable.java index 27ad517..20a8875 100644 --- a/src/main/java/net/imagej/table/DefaultFloatTable.java +++ b/src/main/java/net/imagej/table/DefaultFloatTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultFloatTable extends AbstractTable - implements FloatTable { + implements FloatTable +{ /** Creates an empty float table. */ public DefaultFloatTable() { @@ -49,18 +50,6 @@ public DefaultFloatTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- FloatTable methods -- - - @Override - public float getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final float value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultIntTable.java b/src/main/java/net/imagej/table/DefaultIntTable.java index 0140784..1f800d2 100644 --- a/src/main/java/net/imagej/table/DefaultIntTable.java +++ b/src/main/java/net/imagej/table/DefaultIntTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultIntTable extends AbstractTable - implements IntTable { + implements IntTable +{ /** Creates an empty int table. */ public DefaultIntTable() { @@ -49,18 +50,6 @@ public DefaultIntTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- IntTable methods -- - - @Override - public int getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final int value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultLongTable.java b/src/main/java/net/imagej/table/DefaultLongTable.java index d6bc34d..0e4ac00 100644 --- a/src/main/java/net/imagej/table/DefaultLongTable.java +++ b/src/main/java/net/imagej/table/DefaultLongTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultLongTable extends AbstractTable - implements LongTable { + implements LongTable +{ /** Creates an empty long table. */ public DefaultLongTable() { @@ -49,18 +50,6 @@ public DefaultLongTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- LongTable methods -- - - @Override - public long getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final long value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index 58a6315..14c8ab3 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -58,16 +58,6 @@ public DefaultResultsTable(final int columnCount, final int rowCount) { // -- ResultsTable methods -- - @Override - public double getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final double value) { - get(col).setValue(row, value); - } - @Override public ImgPlus img() { final Img img = new ResultsImg(this); diff --git a/src/main/java/net/imagej/table/DefaultShortTable.java b/src/main/java/net/imagej/table/DefaultShortTable.java index 4945f73..1f3cf50 100644 --- a/src/main/java/net/imagej/table/DefaultShortTable.java +++ b/src/main/java/net/imagej/table/DefaultShortTable.java @@ -37,7 +37,8 @@ * @author Alison Walter */ public class DefaultShortTable extends AbstractTable - implements ShortTable { + implements ShortTable +{ /** Creates an empty short table. */ public DefaultShortTable() { @@ -49,18 +50,6 @@ public DefaultShortTable(final int columnCount, final int rowCount) { super(columnCount, rowCount); } - // -- ShortTable methods -- - - @Override - public short getValue(final int col, final int row) { - return get(col).getValue(row); - } - - @Override - public void setValue(final int col, final int row, final short value) { - get(col).setValue(row, value); - } - // -- Internal methods -- @Override diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index bfee9b2..6774023 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -38,7 +38,9 @@ * * @author Curtis Rueden */ -public class DoubleColumn extends DoubleArray implements Column { +public class DoubleColumn extends DoubleArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Double.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Double[] values) { - final double[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final double[] values) { + setArray(values); } @Override - public void fill(final Double[] values, final int offset) { - final double[] prim = toPrimitive(values); - + public void fill(final double[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private double[] toPrimitive(final Double[] values) { - final double[] prim = new double[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].doubleValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index cefee03..d4a7bc7 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class FloatColumn extends FloatArray implements Column { +public class FloatColumn extends FloatArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Float.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Float[] values) { - final float[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final float[] values) { + setArray(values.clone()); } @Override - public void fill(final Float[] values, final int offset) { - final float[] prim = toPrimitive(values); - + public void fill(final float[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values.clone()); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private float[] toPrimitive(final Float[] values) { - final float[] prim = new float[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].floatValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/FloatTable.java b/src/main/java/net/imagej/table/FloatTable.java index 26c49b1..d6306bb 100644 --- a/src/main/java/net/imagej/table/FloatTable.java +++ b/src/main/java/net/imagej/table/FloatTable.java @@ -39,9 +39,13 @@ public interface FloatTable extends Table { /** Gets the value of the given table cell. */ - float getValue(int col, int row); + default float getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, float value); + default void setValue(final int col, final int row, final float value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index 502ca3e..e055a1d 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class IntColumn extends IntArray implements Column { +public class IntColumn extends IntArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Integer.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Integer[] values) { - final int[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final int[] values) { + setArray(values); } @Override - public void fill(final Integer[] values, final int offset) { - final int[] prim = toPrimitive(values); - + public void fill(final int[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private int[] toPrimitive(final Integer[] values) { - final int[] prim = new int[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].intValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/IntTable.java b/src/main/java/net/imagej/table/IntTable.java index 4942264..20988cb 100644 --- a/src/main/java/net/imagej/table/IntTable.java +++ b/src/main/java/net/imagej/table/IntTable.java @@ -39,9 +39,13 @@ public interface IntTable extends Table { /** Gets the value of the given table cell. */ - int getValue(int col, int row); + default int getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, int value); + default void setValue(final int col, final int row, final int value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index 3565009..f6c8af3 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class LongColumn extends LongArray implements Column { +public class LongColumn extends LongArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Long.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Long[] values) { - final long[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final long[] values) { + this.setArray(values.clone()); } @Override - public void fill(final Long[] values, final int offset) { - final long[] prim = toPrimitive(values); - + public void fill(final long[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values.clone()); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private long[] toPrimitive(final Long[] values) { - final long[] prim = new long[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].longValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/LongTable.java b/src/main/java/net/imagej/table/LongTable.java index b2a17e1..4cd0a74 100644 --- a/src/main/java/net/imagej/table/LongTable.java +++ b/src/main/java/net/imagej/table/LongTable.java @@ -39,9 +39,13 @@ public interface LongTable extends Table { /** Gets the value of the given table cell. */ - long getValue(int col, int row); + default long getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, long value); + default void setValue(final int col, final int row, final long value) { + get(col).setValue(row, value); + } } diff --git a/src/main/java/net/imagej/table/PrimitiveColumn.java b/src/main/java/net/imagej/table/PrimitiveColumn.java new file mode 100644 index 0000000..9e5fef4 --- /dev/null +++ b/src/main/java/net/imagej/table/PrimitiveColumn.java @@ -0,0 +1,54 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import org.scijava.util.PrimitiveArray; + +/** + * A column of data backed by a {@link PrimitiveArray}. + * + * @author Curtis Rueden + * @author Alison Walter + * @param Type of the primitive array; e.g., {@code double[]}. + * @param Boxed type of the array element; e.g., {@code Double}. + */ +public interface PrimitiveColumn extends Column, + PrimitiveArray +{ + + /** Fills the column with the values in the given array. */ + void fill(ArrayType values); + + /** Fills the column with the values in the given array. */ + void fill(ArrayType values, int offset); + +} diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java index cd06519..7a7d222 100644 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -42,10 +42,14 @@ public interface ResultsTable extends Table { /** Gets the value of the given table cell. */ - double getValue(int col, int row); + default double getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, double value); + default void setValue(final int col, final int row, final double value) { + get(col).setValue(row, value); + } /** Wraps the results table in an ImgLib {@link net.imglib2.img.Img}. */ ImgPlus img(); diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index bd8ffa8..b63b511 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -38,7 +38,9 @@ * * @author Alison Walter */ -public class ShortColumn extends ShortArray implements Column { +public class ShortColumn extends ShortArray implements + PrimitiveColumn +{ /** The column header. */ private String header; @@ -66,31 +68,20 @@ public Class getType() { return Short.class; } + // -- PrimitiveColumn methods -- + @Override - public void fill(final Short[] values) { - final short[] prim = toPrimitive(values); - this.setArray(prim); + public void fill(final short[] values) { + setArray(values); } @Override - public void fill(final Short[] values, final int offset) { - final short[] prim = toPrimitive(values); - + public void fill(final short[] values, final int offset) { // Check if array has been initialized - if (this.getArray() == null) this.setArray(prim); + if (getArray() == null) setArray(values); else { - System.arraycopy(prim, 0, this.getArray(), offset, prim.length); - } - } - - // -- Helper methods -- - - private short[] toPrimitive(final Short[] values) { - final short[] prim = new short[values.length]; - for (int i = 0; i < prim.length; i++) { - prim[i] = values[i].shortValue(); + System.arraycopy(values, 0, getArray(), offset, values.length); } - return prim; } } diff --git a/src/main/java/net/imagej/table/ShortTable.java b/src/main/java/net/imagej/table/ShortTable.java index cdaa357..6c58ac0 100644 --- a/src/main/java/net/imagej/table/ShortTable.java +++ b/src/main/java/net/imagej/table/ShortTable.java @@ -39,9 +39,13 @@ public interface ShortTable extends Table { /** Gets the value of the given table cell. */ - short getValue(int col, int row); + default short getValue(final int col, final int row) { + return get(col).getValue(row); + } /** Sets the value of the given table cell. */ - void setValue(int col, int row, short value); + default void setValue(final int col, final int row, final short value) { + get(col).setValue(row, value); + } } diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index 17b384a..b3899ac 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -91,7 +91,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final BoolTable table = createTable(); - final Boolean[] values = + final boolean[] values = { true, true, true, true, false, true, false, true }; final BoolColumn col = table.appendColumn("Header4"); @@ -169,7 +169,7 @@ private BoolTable createTable() { } private void checkTableModifiedColumn(final BoolTable table, - final Boolean[] values, final int mod) + final boolean[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index 6d7981c..77c5c4e 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -90,7 +90,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final ByteTable table = createTable(); - final Byte[] values = { 17, 23, -12, 0, -93, -7, 127 }; + final byte[] values = { 17, 23, -12, 0, -93, -7, 127 }; final ByteColumn col = table.appendColumn("Header3"); col.fill(values); @@ -168,12 +168,12 @@ private ByteTable createTable() { } private void checkTableModifiedColumn(final ByteTable table, - final Byte[] values, final int mod) + final byte[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].byteValue()); + assertEquals(table.getValue(c, r), values[r]); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1]); diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index 59e79fa..5787a82 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -92,7 +92,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final CharTable table = createTable(); - final Character[] values = { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }; + final char[] values = { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }; final CharColumn col = table.appendColumn("Header4"); col.fill(values); @@ -170,12 +170,12 @@ private CharTable createTable() { } private void checkTableModifiedColumn(final CharTable table, - final Character[] values, final int mod) + final char[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].charValue()); + assertEquals(table.getValue(c, r), values[r]); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1]); diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index 148cbc8..92dbc69 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -91,7 +91,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final FloatTable table = createTable(); - final Float[] values = + final float[] values = { 17.0625f, 22.125f, -0.00000762939f, 0f, -2.03125f, -717.5f, 127.5f }; final FloatColumn col = table.appendColumn("Header6"); @@ -170,12 +170,12 @@ private FloatTable createTable() { } private void checkTableModifiedColumn(final FloatTable table, - final Float[] values, final int mod) + final float[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].floatValue(), 0); + assertEquals(table.getValue(c, r), values[r], 0); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1], 0); diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index e75db50..ab89121 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -103,7 +103,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final IntTable table = createTable(); - final Integer[] values = + final int[] values = { 30, 3109842, 28, 25, -432579, 22, -12, 0, 54235423, -7858345, -34, -3, -35648443, 43512356, 999 }; @@ -183,12 +183,12 @@ private IntTable createTable() { } private void checkTableModifiedColumn(final IntTable table, - final Integer[] values, final int mod) + final int[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].intValue()); + assertEquals(table.getValue(c, r), values[r]); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1]); diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index 30638c9..b071ddc 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -86,7 +86,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final LongTable table = createTable(); - final Long[] values = { 542908l, 9574597419085l, -11l }; + final long[] values = { 542908l, 9574597419085l, -11l }; final LongColumn col = table.appendColumn("Header3"); col.fill(values); @@ -165,12 +165,12 @@ private LongTable createTable() { } private void checkTableModifiedColumn(final LongTable table, - final Long[] values, final int mod) + final long[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].longValue()); + assertEquals(table.getValue(c, r), values[r]); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1]); diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index efe8d86..8c45e33 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -108,7 +108,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final ResultsTable table = createTable(); - final Double[] values = + final double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, 940385034958.5, -301284390284.25, 17.25 }; @@ -140,7 +140,7 @@ public void testRemoveColumn() { @Test public void testInsertColumn() { final ResultsTable table = createTable(); - final Double[] values = + final double[] values = { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, 940385034958.5, -301284390284.25, 17.25 }; @@ -157,7 +157,7 @@ public void testInsertColumn() { @Test public void testAppendColumns() { final ResultsTable table = createTable(); - final Double[][] values = + final double[][] values = { { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, @@ -199,7 +199,7 @@ public void testRemoveColumns() { @Test public void testInsertColumns() { final ResultsTable table = createTable(); - final Double[][] values = + final double[][] values = { { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, @@ -342,7 +342,7 @@ private ResultsTable createTable() { } private void checkTableModifiedColumn(final ResultsTable table, - final Double[] values, final int mod) + final double[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { @@ -384,7 +384,7 @@ else if (r >= mod && values == null) { } private void checkTableModifiedColumns(final ResultsTable table, - final Double[][] values, final int startMod, final int endMod) + final double[][] values, final int startMod, final int endMod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index 7c45d75..b15549e 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -93,7 +93,7 @@ public void testGetColumnType() { @Test public void testAppendColumn() { final ShortTable table = createTable(); - final Short[] values = { -11, 32000, 9798, -18687, 97 }; + final short[] values = { -11, 32000, 9798, -18687, 97 }; final ShortColumn col = table.appendColumn("Header5"); col.fill(values); @@ -172,12 +172,12 @@ private ShortTable createTable() { } private void checkTableModifiedColumn(final ShortTable table, - final Short[] values, final int mod) + final short[] values, final int mod) { for (int r = 0; r < table.getRowCount(); r++) { for (int c = 0; c < table.getColumnCount(); c++) { if ( c == mod && values != null ) { - assertEquals(table.getValue(c, r), values[r].shortValue()); + assertEquals(table.getValue(c, r), values[r]); } else if ( c > mod && values != null ) { assertEquals(table.getValue(c, r), DATA[r][c - 1]); From ae714af2788fb0b88fbedceea3b4c50e7b1bc8c2 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 17 Jun 2016 09:06:53 -0500 Subject: [PATCH 25/42] Add insert row/column test for remaining primitive tables --- .../imagej/table/DefaultBoolTableTest.java | 30 ++++++++++++++++++ .../imagej/table/DefaultByteTableTest.java | 29 +++++++++++++++++ .../imagej/table/DefaultCharTableTest.java | 29 +++++++++++++++++ .../imagej/table/DefaultFloatTableTest.java | 30 ++++++++++++++++++ .../net/imagej/table/DefaultIntTableTest.java | 31 +++++++++++++++++++ .../imagej/table/DefaultLongTableTest.java | 29 +++++++++++++++++ .../imagej/table/DefaultShortTableTest.java | 29 +++++++++++++++++ 7 files changed, 207 insertions(+) diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index b3899ac..424ccf7 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -118,6 +118,21 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 2); } + @Test + public void testInsertColumn() { + final BoolTable table = createTable(); + final boolean[] values = + { true, true, true, true, false, true, false, true }; + + final BoolColumn col = table.insertColumn(1, "Header4"); + col.fill(values); + + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(1).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 1); + } + @Test public void testAppendRow() { final BoolTable table = createTable(); @@ -148,6 +163,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 1); } + @Test + public void testInsertRow() { + final BoolTable table = createTable(); + final boolean[] values = { true, true, false }; + + table.insertRow(6); + + assertEquals(table.getRowCount(), 9); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 6, values[i]); + } + + checkTableModifiedRow(table, values, 6); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index 77c5c4e..0fedb4d 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -116,6 +116,20 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 1); } + @Test + public void testInsertColumn() { + final ByteTable table = createTable(); + final byte[] values = { 17, 23, -12, 0, -93, -7, 127 }; + + final ByteColumn col = table.insertColumn(0, "Header3"); + col.fill(values); + + assertEquals(table.getColumnCount(), 3); + assertEquals(table.get(0).getHeader(), "Header3"); + + checkTableModifiedColumn(table, values, 0); + } + @Test public void testAppendRow() { final ByteTable table = createTable(); @@ -147,6 +161,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 2); } + @Test + public void testInsertRow() { + final ByteTable table = createTable(); + final byte[] values = { 79, 8 }; + + table.insertRow(5); + + assertEquals(table.getRowCount(), 8); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 5, values[i]); + } + + checkTableModifiedRow(table, values, 5); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index 5787a82..ae54cd2 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -119,6 +119,20 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 2); } + @Test + public void testInsertColumn() { + final CharTable table = createTable(); + final char[] values = { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }; + + final CharColumn col = table.insertColumn(2, "Header4"); + col.fill(values); + + assertEquals(table.getColumnCount(), 4); + assertEquals(table.get(2).getHeader(), "Header4"); + + checkTableModifiedColumn(table, values, 2); + } + @Test public void testAppendRow() { final CharTable table = createTable(); @@ -149,6 +163,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 7); } + @Test + public void testInsertRow() { + final CharTable table = createTable(); + final char[] values = { '\t', '\uffff', '\u0000' }; + + table.insertRow(7); + + assertEquals(table.getRowCount(), 10); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 7, values[i]); + } + + checkTableModifiedRow(table, values, 7); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index 92dbc69..75a8dcf 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -118,6 +118,21 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 1); } + @Test + public void testInsertColumn() { + final FloatTable table = createTable(); + final float[] values = + { 17.0625f, 22.125f, -0.00000762939f, 0f, -2.03125f, -717.5f, 127.5f }; + + final FloatColumn col = table.insertColumn(4, "Header6"); + col.fill(values); + + assertEquals(table.getColumnCount(), 6); + assertEquals(table.get(4).getHeader(), "Header6"); + + checkTableModifiedColumn(table, values, 4); + } + @Test public void testAppendRow() { final FloatTable table = createTable(); @@ -149,6 +164,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 4); } + @Test + public void testInsertRow() { + final FloatTable table = createTable(); + final float[] values = { -0.0625f, 5.5f, -4.03125f, 46.125f, 10489.5f }; + + table.insertRow(0); + + assertEquals(table.getRowCount(), 8); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 0, values[i]); + } + + checkTableModifiedRow(table, values, 0); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index ab89121..41f4ead 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -132,6 +132,22 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 5); } + @Test + public void testInsertColumn() { + final IntTable table = createTable(); + final int[] values = + { 30, 3109842, 28, 25, -432579, 22, -12, 0, 54235423, -7858345, -34, -3, + -35648443, 43512356, 999 }; + + final IntColumn col = table.insertColumn(3, "Header7"); + col.fill(values); + + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(3).getHeader(), "Header7"); + + checkTableModifiedColumn(table, values, 3); + } + @Test public void testAppendRow() { final IntTable table = createTable(); @@ -162,6 +178,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 10); } + @Test + public void testInsertRow() { + final IntTable table = createTable(); + final int[] values = { 179, 43148, -36, 1, 6, -356 }; + + table.insertRow(13); + + assertEquals(table.getRowCount(), 16); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 13, values[i]); + } + + checkTableModifiedRow(table, values, 13); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index b071ddc..2e54b19 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -113,6 +113,20 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 1); } + @Test + public void testInsertColumn() { + final LongTable table = createTable(); + final long[] values = { 542908l, 9574597419085l, -11l }; + + final LongColumn col = table.insertColumn(1, "Header3"); + col.fill(values); + + assertEquals(table.getColumnCount(), 3); + assertEquals(table.get(1).getHeader(), "Header3"); + + checkTableModifiedColumn(table, values, 1); + } + @Test public void testAppendRow() { final LongTable table = createTable(); @@ -144,6 +158,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 0); } + @Test + public void testInsertRow() { + final LongTable table = createTable(); + final long[] values = { 301984l, 15l }; + + table.insertRow(1); + + assertEquals(table.getRowCount(), 4); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 1, values[i]); + } + + checkTableModifiedRow(table, values, 1); + } + // TODO - Add more tests. // -- Helper methods -- diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index b15549e..4724ab0 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -105,6 +105,20 @@ public void testAppendColumn() { checkTableModifiedColumn(table, values, 4); } + @Test + public void testInsertColumn() { + final ShortTable table = createTable(); + final short[] values = { -11, 32000, 9798, -18687, 97 }; + + final ShortColumn col = table.insertColumn(2, "Header5"); + col.fill(values); + + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(2).getHeader(), "Header5"); + + checkTableModifiedColumn(table, values, 2); + } + @Test public void testRemoveColumn() { final ShortTable table = createTable(); @@ -151,6 +165,21 @@ public void testRemoveRow() { checkTableModifiedRow(table, null, 2); } + @Test + public void testInsertRow() { + final ShortTable table = createTable(); + final short[] values = { 7911, 937, -1508, -8 }; + + table.insertRow(3); + + assertEquals(table.getRowCount(), 6); + for (int i = 0; i < table.getColumnCount(); i++) { + table.setValue(i, 3, values[i]); + } + + checkTableModifiedRow(table, values, 3); + } + // TODO - Add more tests. // -- Helper methods -- From 7f2cb1eec688e18b4f55bea648977d5b9257fbd0 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 17 Jun 2016 11:09:28 -0500 Subject: [PATCH 26/42] Add tests for modifying multiple rows/columns --- .../imagej/table/DefaultBoolTableTest.java | 166 +++++++++++++++++ .../imagej/table/DefaultByteTableTest.java | 158 ++++++++++++++++ .../imagej/table/DefaultCharTableTest.java | 150 +++++++++++++++ .../imagej/table/DefaultFloatTableTest.java | 170 +++++++++++++++++ .../net/imagej/table/DefaultIntTableTest.java | 157 ++++++++++++++++ .../imagej/table/DefaultLongTableTest.java | 173 ++++++++++++++++++ .../imagej/table/DefaultShortTableTest.java | 157 ++++++++++++++++ 7 files changed, 1131 insertions(+) diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index 424ccf7..61a8ccd 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -133,6 +135,78 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 1); } + @Test + public void testAppendColumns() { + final BoolTable table = createTable(); + final boolean[][] values = + { + { true, true, true, true, false, true, false, true }, + { true, false, true, false, false, true, false, true }, + { false, true, true, true, false, true, false, false }, + { true, false, false, true, false, false, false, true } }; + + final String[] headers = { "Header4", "Header5", "Header6", "Header7" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(3).getHeader(), "Header4"); + assertEquals(table.get(4).getHeader(), "Header5"); + assertEquals(table.get(5).getHeader(), "Header6"); + assertEquals(table.get(6).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 3, 6); + } + + @Test + public void testRemoveColumns() { + final BoolTable table = createTable(); + + final List col = table.removeColumns(1, 2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q + 1]); + } + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumns(table, null, 1, 3); + } + + @Test + public void testInsertColumns() { + final BoolTable table = createTable(); + final boolean[][] values = + { + { true, true, true, true, false, true, false, true }, + { true, false, true, false, false, true, false, true }, + { false, true, true, true, false, true, false, false }, + { true, false, false, true, false, false, false, true } }; + + + final String[] headers = { "Header4", "Header5", "Header6", "Header7" }; + final List col = table.insertColumns(0, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(0).getHeader(), "Header4"); + assertEquals(table.get(1).getHeader(), "Header5"); + assertEquals(table.get(2).getHeader(), "Header6"); + assertEquals(table.get(3).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 0, 3); + } + @Test public void testAppendRow() { final BoolTable table = createTable(); @@ -178,6 +252,55 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 6); } + @Test + public void testAppendRows() { + final BoolTable table = createTable(); + final boolean[][] values = + { { true, true, false }, { false, true, false }, { true, false, true }, + { true, false, false }, { false, false, false } }; + + // Test appending a row + table.appendRows(5); + assertEquals(table.getRowCount(), 13); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 8, values[r][c]); + assertEquals(table.getValue(c, r + 8), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 8, 12); + } + + @Test + public void testRemoveRows() { + final BoolTable table = createTable(); + table.removeRows(4, 3); + assertEquals(table.getRowCount(), 5); + + checkTableModifiedRows(table, null, 4, 6); + } + + @Test + public void testInsertRows() { + final BoolTable table = createTable(); + final boolean[][] values = + { { true, true, false }, { false, true, false }, { true, false, true }, + { true, false, false }, { false, false, false } }; + + table.insertRows(5, 5); + + assertEquals(table.getRowCount(), 13); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 5, values[r][c]); + assertEquals(table.getValue(c, r + 5), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 5, 9); + } + // TODO - Add more tests. // -- Helper methods -- @@ -240,4 +363,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final BoolTable table, + final boolean[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final BoolTable table, + final boolean[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index 0fedb4d..7964310 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -130,6 +132,70 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 0); } + @Test + public void testAppendColumns() { + final ByteTable table = createTable(); + final byte[][] values = + { + { 17, 23, -12, 0, -93, -7, 127 }, + { -100, 54, 93, -2, 111, -86, -74 }, + { -12, 120, 6, 8, -4, -121, 13 } }; + + final String[] headers = { "Header3", "Header4", "Header5" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + + // Test appending a column + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(2).getHeader(), "Header3"); + assertEquals(table.get(3).getHeader(), "Header4"); + assertEquals(table.get(4).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 2, 4); + } + + @Test + public void testRemoveColumns() { + final ByteTable table = createTable(); + + final List col = table.removeColumns(0, 2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q]); + } + } + assertEquals(table.getColumnCount(), 0); + + checkTableModifiedColumns(table, null, 0, 1); + } + + @Test + public void testInsertColumns() { + final ByteTable table = createTable(); + final byte[][] values = + { + { 17, 23, -12, 0, -93, -7, 127 }, + { -100, 54, 93, -2, 111, -86, -74 }, + { -12, 120, 6, 8, -4, -121, 13 } }; + + final String[] headers = { "Header3", "Header4", "Header5" }; + final List col = table.insertColumns(1, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(1).getHeader(), "Header3"); + assertEquals(table.get(2).getHeader(), "Header4"); + assertEquals(table.get(3).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 1, 3); + } + @Test public void testAppendRow() { final ByteTable table = createTable(); @@ -176,6 +242,55 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 5); } + @Test + public void testAppendRows() { + final ByteTable table = createTable(); + final byte[][] values = + { { 79, 8 }, { 100, -12 }, { 54, 36 }, { -100, -86 }, { -43, 60 }, + { 92, -122 } }; + + // Test appending a row + table.appendRows(6); + assertEquals(table.getRowCount(), 13); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 7, values[r][c]); + assertEquals(table.getValue(c, r + 7), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 7, 12); + } + + @Test + public void testRemoveRows() { + final ByteTable table = createTable(); + table.removeRows(2, 3); + assertEquals(table.getRowCount(), 4); + + checkTableModifiedRows(table, null, 2, 4); + } + + @Test + public void testInsertRows() { + final ByteTable table = createTable(); + final byte[][] values = + { { 79, 8 }, { 100, -12 }, { 54, 36 }, { -100, -86 }, { -43, 60 }, + { 92, -122 } }; + + table.insertRows(4, 6); + + assertEquals(table.getRowCount(), 13); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 4, values[r][c]); + assertEquals(table.getValue(c, r + 4), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 4, 9); + } + // TODO - Add more tests. // -- Helper methods -- @@ -238,4 +353,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final ByteTable table, + final byte[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final ByteTable table, + final byte[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index ae54cd2..8a3ab71 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -133,6 +135,64 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 2); } + @Test + public void testAppendColumns() { + final CharTable table = createTable(); + final char[][] values = + { + { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }, + { '1', 'Q', '%', 'j', ')', '8', '0', 'O', '\n' } }; + + final String[] headers = { "Header4", "Header5" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + // Test appending a column + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(3).getHeader(), "Header4"); + assertEquals(table.get(4).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 3, 4); + } + + @Test + public void testRemoveColumns() { + final CharTable table = createTable(); + + final List col = table.removeColumns(1, 2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q + 1]); + } + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumns(table, null, 1, 2); + } + + @Test + public void testInsertColumns() { + final CharTable table = createTable(); + final char[][] values = + { + { '2', 'W', '!', '*', 'o', 'E', ' ', 'A', '\t' }, + { '1', 'Q', '%', 'j', ')', '8', '0', 'O', '\n' } }; + + final String[] headers = { "Header4", "Header5" }; + final List col = table.insertColumns(0, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + assertEquals(table.getColumnCount(), 5); + assertEquals(table.get(0).getHeader(), "Header4"); + assertEquals(table.get(1).getHeader(), "Header5"); + + checkTableModifiedColumns(table, values, 0, 1); + } + @Test public void testAppendRow() { final CharTable table = createTable(); @@ -178,6 +238,53 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 7); } + @Test + public void testAppendRows() { + final CharTable table = createTable(); + final char[][] values = + { { '\t', '\uffff', '\u0000' }, { 'e', '\ufffd', '7' } }; + + // Test appending a row + table.appendRows(2); + assertEquals(table.getRowCount(), 11); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 9, values[r][c]); + assertEquals(table.getValue(c, r + 9), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 9, 10); + } + + @Test + public void testRemoveRows() { + final CharTable table = createTable(); + table.removeRows(3, 4); + assertEquals(table.getRowCount(), 5); + + checkTableModifiedRows(table, null, 3, 6); + } + + @Test + public void testInsertRows() { + final CharTable table = createTable(); + final char[][] values = + { { '\t', '\uffff', '\u0000' }, { 'e', '\ufffd', '7' } }; + + table.insertRows(2, 2); + + assertEquals(table.getRowCount(), 11); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 2, values[r][c]); + assertEquals(table.getValue(c, r + 2), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 2, 3); + } + // TODO - Add more tests. // -- Helper methods -- @@ -240,4 +347,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final CharTable table, + final char[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final CharTable table, + final char[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index 75a8dcf..e1ce2b6 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -133,6 +135,77 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 4); } + @Test + public void testAppendColumns() { + final FloatTable table = createTable(); + final float[][] values = + { + { 17.0625f, 22.125f, -0.00000762939f, 0f, -2.03125f, -717.5f, 127.5f }, + { 7.25f, 8.5f, -12.0625f, 100f, -2.03125f, -77.25f, 17.03125f }, + { 9.125f, 19038.25f, 0.00000762939f, 12.5f, -2.0f, -333.125f, 7.5f }, + { 120984.5f, 1.0f, -1.5f, 0.0625f, 11.03125f, 0.25f, 1.25f } }; + + final String[] headers = { "Header6", "Header7", "Header8", "Header9" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + + // Test appending a column + assertEquals(table.getColumnCount(), 9); + assertEquals(table.get(5).getHeader(), "Header6"); + assertEquals(table.get(6).getHeader(), "Header7"); + assertEquals(table.get(7).getHeader(), "Header8"); + assertEquals(table.get(8).getHeader(), "Header9"); + + checkTableModifiedColumns(table, values, 5, 8); + } + + @Test + public void testRemoveColumns() { + final FloatTable table = createTable(); + + final List col = table.removeColumns(1, 3); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q + 1], 0); + } + } + assertEquals(table.getColumnCount(), 2); + + checkTableModifiedColumns(table, null, 1, 4); + } + + @Test + public void testInsertColumns() { + final FloatTable table = createTable(); + final float[][] values = + { + { 17.0625f, 22.125f, -0.00000762939f, 0f, -2.03125f, -717.5f, 127.5f }, + { 7.25f, 8.5f, -12.0625f, 100f, -2.03125f, -77.25f, 17.03125f }, + { 9.125f, 19038.25f, 0.00000762939f, 12.5f, -2.0f, -333.125f, 7.5f }, + { 120984.5f, 1.0f, -1.5f, 0.0625f, 11.03125f, 0.25f, 1.25f } }; + + final String[] headers = { "Header6", "Header7", "Header8", "Header9" }; + final List col = table.insertColumns(3, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + + // Test appending a column + assertEquals(table.getColumnCount(), 9); + assertEquals(table.get(3).getHeader(), "Header6"); + assertEquals(table.get(4).getHeader(), "Header7"); + assertEquals(table.get(5).getHeader(), "Header8"); + assertEquals(table.get(6).getHeader(), "Header9"); + + checkTableModifiedColumns(table, values, 3, 6); + } + @Test public void testAppendRow() { final FloatTable table = createTable(); @@ -179,6 +252,59 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 0); } + @Test + public void testAppendRows() { + final FloatTable table = createTable(); + final float[][] values = + { + { -0.0625f, 5.5f, -4.03125f, 46.125f, 10489.5f }, + { 6.25f, 10.03125f, 10809234.5f, -110.0625f, 12.0f } + }; + + // Test appending a row + table.appendRows(2); + assertEquals(table.getRowCount(), 9); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 7, values[r][c]); + assertEquals(table.getValue(c, r + 7), values[r][c], 0); + } + } + + checkTableModifiedRows(table, values, 7, 8); + } + + @Test + public void testRemoveRows() { + final FloatTable table = createTable(); + table.removeRows(1, 3); + assertEquals(table.getRowCount(), 4); + + checkTableModifiedRows(table, null, 1, 3); + } + + @Test + public void testInsertRows() { + final FloatTable table = createTable(); + final float[][] values = + { + { -0.0625f, 5.5f, -4.03125f, 46.125f, 10489.5f }, + { 6.25f, 10.03125f, 10809234.5f, -110.0625f, 12.0f } + }; + + table.insertRows(4, 2); + + assertEquals(table.getRowCount(), 9); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 4, values[r][c]); + assertEquals(table.getValue(c, r + 4), values[r][c], 0); + } + } + + checkTableModifiedRows(table, values, 4, 5); + } + // TODO - Add more tests. // -- Helper methods -- @@ -241,4 +367,48 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final FloatTable table, + final float[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r], 0); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length], 0); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)], + 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + + private void checkTableModifiedRows(final FloatTable table, + final float[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c], 0); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c], 0); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c], 0); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c], 0); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index 41f4ead..6955fba 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -148,6 +150,69 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 3); } + @Test + public void testAppendColumns() { + final IntTable table = createTable(); + final int[][] values = + { + { 30, 3109842, 28, 25, -432579, 22, -12, 0, 54235423, -7858345, -34, -3, + -35648443, 43512356, 999 }, + { 9, 310, -11111, -979324, -4092345, 1, -5, 0, 7, -13, -4903285, 42032, + -840, 974, 1 } }; + + final String[] headers = { "Header7", "Header8" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + // Test appending a column + assertEquals(table.getColumnCount(), 8); + assertEquals(table.get(6).getHeader(), "Header7"); + assertEquals(table.get(7).getHeader(), "Header8"); + + checkTableModifiedColumns(table, values, 6, 7); + } + + @Test + public void testRemoveColumns() { + final IntTable table = createTable(); + + final List col = table.removeColumns(2, 2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q + 2]); + } + } + assertEquals(table.getColumnCount(), 4); + + checkTableModifiedColumns(table, null, 2, 4); + } + + @Test + public void testInsertColumns() { + final IntTable table = createTable(); + final int[][] values = + { + { 30, 3109842, 28, 25, -432579, 22, -12, 0, 54235423, -7858345, -34, -3, + -35648443, 43512356, 999 }, + { 9, 310, -11111, -979324, -4092345, 1, -5, 0, 7, -13, -4903285, 42032, + -840, 974, 1 } }; + + final String[] headers = { "Header7", "Header8" }; + final List col = table.insertColumns(4, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + + // Test appending a column + assertEquals(table.getColumnCount(), 8); + assertEquals(table.get(4).getHeader(), "Header7"); + assertEquals(table.get(5).getHeader(), "Header8"); + + checkTableModifiedColumns(table, values, 4, 5); + } + @Test public void testAppendRow() { final IntTable table = createTable(); @@ -193,6 +258,55 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 13); } + @Test + public void testAppendRows() { + final IntTable table = createTable(); + final int[][] values = + { { 179, 43148, -36, 1, 6, -356 }, { 1, 438, -6, 145, -632, -6123 }, + { -419, 4, -0, -41, 43, 134 } }; + + // Test appending a row + table.appendRows(3); + assertEquals(table.getRowCount(), 18); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 15, values[r][c]); + assertEquals(table.getValue(c, r + 15), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 15, 17); + } + + @Test + public void testRemoveRows() { + final IntTable table = createTable(); + table.removeRows(9, 2); + assertEquals(table.getRowCount(), 13); + + checkTableModifiedRows(table, null, 9, 10); + } + + @Test + public void testInsertRows() { + final IntTable table = createTable(); + final int[][] values = + { { 179, 43148, -36, 1, 6, -356 }, { 1, 438, -6, 145, -632, -6123 }, + { -419, 4, -0, -41, 43, 134 } }; + + table.insertRows(2, 3); + + assertEquals(table.getRowCount(), 18); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 2, values[r][c]); + assertEquals(table.getValue(c, r + 2), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 2, 4); + } + // TODO - Add more tests. // -- Helper methods -- @@ -255,4 +369,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final IntTable table, + final int[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final IntTable table, + final int[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index 2e54b19..a73c13b 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -127,6 +129,85 @@ public void testInsertColumn() { checkTableModifiedColumn(table, values, 1); } + @Test + public void testAppendColumns() { + final LongTable table = createTable(); + final long[][] values = + { + { 542908l, 9574597419085l, -11l }, + { 8l, -574l, -1l }, + { 0l, -1112313l, 98137l }, + { 30l, 672534l, -173271l }, + { 310249871l, -9879723194187l, -294l } }; + + final String[] headers = + { "Header3", "Header4", "Header5", "Header6", "Header7" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + col.get(4).fill(values[4]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(2).getHeader(), "Header3"); + assertEquals(table.get(3).getHeader(), "Header4"); + assertEquals(table.get(4).getHeader(), "Header5"); + assertEquals(table.get(5).getHeader(), "Header6"); + assertEquals(table.get(6).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 2, 6); + } + + @Test + public void testRemoveColumns() { + final LongTable table = createTable(); + + final List col = table.removeColumns(0, 2); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q]); + } + } + assertEquals(table.getColumnCount(), 0); + + checkTableModifiedColumns(table, null, 0, 2); + } + + @Test + public void testInsertColumns() { + final LongTable table = createTable(); + final long[][] values = + { + { 542908l, 9574597419085l, -11l }, + { 8l, -574l, -1l }, + { 0l, -1112313l, 98137l }, + { 30l, 672534l, -173271l }, + { 310249871l, -9879723194187l, -294l } }; + + final String[] headers = + { "Header3", "Header4", "Header5", "Header6", "Header7" }; + final List col = table.insertColumns(1, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + col.get(3).fill(values[3]); + col.get(4).fill(values[4]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(1).getHeader(), "Header3"); + assertEquals(table.get(2).getHeader(), "Header4"); + assertEquals(table.get(3).getHeader(), "Header5"); + assertEquals(table.get(4).getHeader(), "Header6"); + assertEquals(table.get(5).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 1, 5); + } + @Test public void testAppendRow() { final LongTable table = createTable(); @@ -173,6 +254,55 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 1); } + @Test + public void testAppendRows() { + final LongTable table = createTable(); + final long[][] values = + { { 301984l, 15l }, { -12l, -10849l }, { 0l, -8l }, { 90l, -110l }, + { -9879128347l, -91874l }, { -330l, 8910347l }, { 13214l, -98417l } }; + + // Test appending a row + table.appendRows(7); + assertEquals(table.getRowCount(), 10); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 3, values[r][c]); + assertEquals(table.getValue(c, r + 3), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 3, 10); + } + + @Test + public void testRemoveRows() { + final LongTable table = createTable(); + table.removeRows(0, 2); + assertEquals(table.getRowCount(), 1); + + checkTableModifiedRows(table, null, 0, 1); + } + + @Test + public void testInsertRows() { + final LongTable table = createTable(); + final long[][] values = + { { 301984l, 15l }, { -12l, -10849l }, { 0l, -8l }, { 90l, -110l }, + { -9879128347l, -91874l }, { -330l, 8910347l }, { 13214l, -98417l } }; + + table.insertRows(1, 7); + + assertEquals(table.getRowCount(), 10); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 1, values[r][c]); + assertEquals(table.getValue(c, r + 1), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 1, 7); + } + // TODO - Add more tests. // -- Helper methods -- @@ -235,4 +365,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final LongTable table, + final long[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final LongTable table, + final long[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index 4724ab0..fbcc1af 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -34,6 +34,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; +import java.util.List; + import org.junit.Test; /** @@ -134,6 +136,71 @@ public void testRemoveColumn() { checkTableModifiedColumn(table, null, 2); } + @Test + public void testAppendColumns() { + final ShortTable table = createTable(); + final short[][] values = + { + { -11, 32000, 9798, -18687, 97 }, + { 19487, 3, 786, 12984, 113 }, + { -1, 8, -234, -9, 10 } }; + + final String[] headers = { "Header5", "Header6", "Header7" }; + final List col = table.appendColumns(headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(4).getHeader(), "Header5"); + assertEquals(table.get(5).getHeader(), "Header6"); + assertEquals(table.get(6).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 4, 7); + } + + @Test + public void testRemoveColumns() { + final ShortTable table = createTable(); + + final List col = table.removeColumns(1, 3); + + // Test removing a column + for (int q = 0; q < col.size(); q++) { + for (int i = 0; i < col.get(0).size(); i++) { + assertEquals(col.get(q).getValue(i), DATA[i][q + 1]); + } + } + assertEquals(table.getColumnCount(), 1); + + checkTableModifiedColumns(table, null, 1, 4); + } + + @Test + public void testInsertColumns() { + final ShortTable table = createTable(); + final short[][] values = + { + { -11, 32000, 9798, -18687, 97 }, + { 19487, 3, 786, 12984, 113 }, + { -1, 8, -234, -9, 10 } }; + + final String[] headers = { "Header5", "Header6", "Header7" }; + final List col = table.insertColumns(3, headers); + col.get(0).fill(values[0]); + col.get(1).fill(values[1]); + col.get(2).fill(values[2]); + + // Test appending a column + assertEquals(table.getColumnCount(), 7); + assertEquals(table.get(3).getHeader(), "Header5"); + assertEquals(table.get(4).getHeader(), "Header6"); + assertEquals(table.get(5).getHeader(), "Header7"); + + checkTableModifiedColumns(table, values, 3, 5); + } + @Test public void testAppendRow() { final ShortTable table = createTable(); @@ -180,6 +247,53 @@ public void testInsertRow() { checkTableModifiedRow(table, values, 3); } + @Test + public void testAppendRows() { + final ShortTable table = createTable(); + final short[][] values = + { { 7911, 937, -1508, -8 }, { -1212, 16, -1, -10 } }; + + // Test appending a row + table.appendRows(2); + assertEquals(table.getRowCount(), 7); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 5, values[r][c]); + assertEquals(table.getValue(c, r + 5), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 5, 6); + } + + @Test + public void testRemoveRows() { + final ShortTable table = createTable(); + table.removeRows(2, 2); + assertEquals(table.getRowCount(), 3); + + checkTableModifiedRows(table, null, 2, 3); + } + + @Test + public void testInsertRows() { + final ShortTable table = createTable(); + final short[][] values = + { { 7911, 937, -1508, -8 }, { -1212, 16, -1, -10 } }; + + table.insertRows(3, 2); + + assertEquals(table.getRowCount(), 7); + for (int r = 0; r < values.length; r++) { + for (int c = 0; c < values[0].length; c++) { + table.setValue(c, r + 3, values[r][c]); + assertEquals(table.getValue(c, r + 3), values[r][c]); + } + } + + checkTableModifiedRows(table, values, 3, 4); + } + // TODO - Add more tests. // -- Helper methods -- @@ -242,4 +356,47 @@ else if ( r >= mod && values == null ) { } } + private void checkTableModifiedColumns(final ShortTable table, + final short[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (c >= startMod && c <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[c - startMod][r]); + } + else if (c > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r][c - values.length]); + } + else if (c >= startMod && values == null) { + assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + + private void checkTableModifiedRows(final ShortTable table, + final short[][] values, final int startMod, final int endMod) + { + for (int r = 0; r < table.getRowCount(); r++) { + for (int c = 0; c < table.getColumnCount(); c++) { + if (r >= startMod && r <= endMod && values != null) { + assertEquals(table.getValue(c, r), values[r - startMod][c]); + } + else if (r > endMod && values != null) { + assertEquals(table.getValue(c, r), DATA[r - values.length][c]); + } + else if (r >= startMod && values == null) { + assertEquals(table.getValue(c, r), + DATA[r + (endMod - startMod + 1)][c]); + } + else { + assertEquals(table.getValue(c, r), DATA[r][c]); + } + } + } + } + } From 21ce0f7704d84c56affdc7600674c2c1fe91a751 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 17 Jun 2016 13:01:25 -0500 Subject: [PATCH 27/42] Make table methods more generic --- .../java/net/imagej/table/AbstractTable.java | 22 ++++++++++++++++--- src/main/java/net/imagej/table/Table.java | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index 55e8230..28315e5 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -41,7 +41,7 @@ * @author Curtis Rueden * @param The type of data stored in the table. */ -public abstract class AbstractTable, T> extends +public abstract class AbstractTable, T> extends SizableArrayList implements Table { @@ -398,14 +398,14 @@ public int getRowIndex(final String header) { @Override public void set(final int col, final int row, final T value) { check(col, row); - get(col).set(row, value); + assign((Column) get(col), row, value); } @Override public void set(final String colHeader, final int row, final T value) { final int col = colIndex(colHeader); checkRow(row, 1); - get(col).set(row, value); + assign((Column) get(col), row, value); } @Override @@ -495,6 +495,22 @@ private int colIndex(final String header) { return col; } + /** + * Generics-friendly helper method for {@link #set(int, int, Object)} and + * {@link #set(String, int, Object)}. + */ + private void assign(final Column column, final int row, + final Object value) + { + if (value != null && !column.getType().isInstance(value)) { + throw new IllegalArgumentException("value of type " + value.getClass() + + " is not a " + column.getType()); + } + @SuppressWarnings("unchecked") + final U typedValue = (U) value; + column.set(row, typedValue); + } + /** * Returns true iff both objects are null, or the objects are equal via * {@link Object#equals}. diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java index 9d9eab2..a259aac 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/net/imagej/table/Table.java @@ -43,7 +43,7 @@ * @param The type of column used by the table. * @param The type of data stored in the table. */ -public interface Table, T> extends List { +public interface Table, T> extends List { /** Gets the number of columns in the table. */ int getColumnCount(); From fc34d4f1b02489ba3660ac391b0c2aada46d6246 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Wed, 22 Jun 2016 10:43:27 -0500 Subject: [PATCH 28/42] Modify table API to allow GenericTable to store multiple column types --- src/main/java/net/imagej/table/DefaultColumn.java | 12 ++++++++---- .../java/net/imagej/table/DefaultGenericTable.java | 4 ++-- src/main/java/net/imagej/table/GenericColumn.java | 2 +- src/main/java/net/imagej/table/GenericTable.java | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index a4e786c..4424b26 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -31,7 +31,7 @@ package net.imagej.table; -import org.scijava.util.SizableArrayList; +import org.scijava.util.ObjectArray; /** * Default implementation of {@link Column}. @@ -39,17 +39,21 @@ * @author Curtis Rueden * @param The type of data stored in the table. */ -public class DefaultColumn extends SizableArrayList implements Column { +public class DefaultColumn extends ObjectArray implements Column { /** The type of this column. */ - private Class type; + private final Class type; /** The column header. */ private String header; - public DefaultColumn() {} + public DefaultColumn(final Class type) { + super(type); + this.type = type; + } public DefaultColumn(final Class type, final String header) { + super(type); this.type = type; this.header = header; } diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/net/imagej/table/DefaultGenericTable.java index 651f23c..d5e7046 100644 --- a/src/main/java/net/imagej/table/DefaultGenericTable.java +++ b/src/main/java/net/imagej/table/DefaultGenericTable.java @@ -36,8 +36,8 @@ * * @author Curtis Rueden */ -public class DefaultGenericTable extends AbstractTable - implements GenericTable +public class DefaultGenericTable extends + AbstractTable, Object> implements GenericTable { /** Creates an empty table. */ diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java index e781eae..fb892ad 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -39,7 +39,7 @@ public class GenericColumn extends DefaultColumn { public GenericColumn() { - super(); + super(Object.class); } public GenericColumn(final String header) { diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/net/imagej/table/GenericTable.java index 8172df8..4e1d605 100644 --- a/src/main/java/net/imagej/table/GenericTable.java +++ b/src/main/java/net/imagej/table/GenericTable.java @@ -36,6 +36,6 @@ * * @author Curtis Rueden */ -public interface GenericTable extends Table { +public interface GenericTable extends Table, Object> { // NB: No implementation needed. } From 5f3b8238a2f88179d05fe3f2175777136d409d8e Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Mon, 27 Jun 2016 14:58:56 -0500 Subject: [PATCH 29/42] Fix fill methods to update the size of the column --- src/main/java/net/imagej/table/BoolColumn.java | 2 ++ src/main/java/net/imagej/table/ByteColumn.java | 2 ++ src/main/java/net/imagej/table/CharColumn.java | 2 ++ src/main/java/net/imagej/table/DoubleColumn.java | 2 ++ src/main/java/net/imagej/table/FloatColumn.java | 2 ++ src/main/java/net/imagej/table/IntColumn.java | 2 ++ src/main/java/net/imagej/table/LongColumn.java | 4 +++- src/main/java/net/imagej/table/ShortColumn.java | 2 ++ 8 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index 0d1aab1..316d8cb 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final boolean[] values) { setArray(values.clone()); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final boolean[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index d751b54..93599dd 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final byte[] values) { setArray(values.clone()); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final byte[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index 084df50..085d707 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final char[] values) { setArray(values.clone()); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final char[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 6774023..44a9714 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final double[] values) { setArray(values); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final double[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index d4a7bc7..d777d9f 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final float[] values) { setArray(values.clone()); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final float[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index e055a1d..026c1b5 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final int[] values) { setArray(values); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final int[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index f6c8af3..edb2371 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -72,7 +72,8 @@ public Class getType() { @Override public void fill(final long[] values) { - this.setArray(values.clone()); + setArray(values.clone()); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final long[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index b63b511..75a3d85 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -73,6 +73,7 @@ public Class getType() { @Override public void fill(final short[] values) { setArray(values); + setSize(values.length); } @Override @@ -82,6 +83,7 @@ public void fill(final short[] values, final int offset) { else { System.arraycopy(values, 0, getArray(), offset, values.length); } + setSize(values.length); } } From c902d40603b78bd3fe1d4ee17f3ba51c5d03d5c8 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Mon, 27 Jun 2016 14:59:50 -0500 Subject: [PATCH 30/42] Override list add methods to update rowCount --- .../java/net/imagej/table/AbstractTable.java | 35 +++++++++++++++++++ src/main/java/net/imagej/table/Table.java | 16 ++++----- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index 28315e5..bdf7c9a 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -32,6 +32,7 @@ package net.imagej.table; import java.util.ArrayList; +import java.util.Collection; import org.scijava.util.SizableArrayList; @@ -421,6 +422,40 @@ public T get(final String colHeader, final int row) { return get(col).get(row); } + // -- List methods -- + + @Override + public boolean add(final C column) { + if (column.size() > rowCount) rowCount = column.size(); + scaleColumns(); + return super.add(column); + } + + @Override + public void add(final int col, final C column) { + super.add(col, column); + if (column.size() > rowCount) rowCount = column.size(); + scaleColumns(); + } + + @Override + public boolean addAll(final Collection c) { + for (final C column : c) { + if (column.size() > rowCount) rowCount = column.size(); + } + scaleColumns(); + return super.addAll(c); + } + + @Override + public boolean addAll(final int col, final Collection c) { + for (final C column : c) { + if (column.size() > rowCount) rowCount = column.size(); + } + scaleColumns(); + return super.addAll(col, c); + } + // -- Internal methods -- protected abstract C createColumn(final String header); diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java index a259aac..4636de2 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/net/imagej/table/Table.java @@ -270,8 +270,8 @@ public interface Table, T> extends List { /** * Appends the specified column to the end of the table. *

- * No checking is done to ensure the new column has the same number of rows as - * the other existing columns. + * Updates the row count if this column has more rows than current table and + * scales the existing columns to have the same number of rows. *

*/ @Override @@ -298,8 +298,8 @@ public interface Table, T> extends List { * table, in the order that they are returned by the specified collection's * iterator. *

- * No checking is done to ensure the new columns have the same number of rows - * as the other existing columns. + * Updates the row count if necessary, and scales the columns to match the row + * count if necessary. *

* * @return true if the table changed as a result of the call @@ -311,8 +311,8 @@ public interface Table, T> extends List { * Inserts all of the columns in the specified collection into this list at * the specified position. *

- * No checking is done to ensure the new columns have the same number of rows - * as the other existing columns. + * Updates the row count if necessary, and scales the columns to match the row + * count if necessary. *

* * @return true if the table changed as a result of the call @@ -371,8 +371,8 @@ public interface Table, T> extends List { /** * Inserts the specified column at the specified position in the table. *

- * No checking is done to ensure the new column has the same number of rows as - * the other existing columns. + * Updates the row count if this column has more rows than current table and + * scales the existing columns to have the same number of rows. *

*/ @Override From 02273031e201ea8d916e1f8e0ac2264d5435181f Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Mon, 27 Jun 2016 15:33:12 -0500 Subject: [PATCH 31/42] Add test for GenericTable --- .../imagej/table/DefaultGenericTableTest.java | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 src/test/java/net/imagej/table/DefaultGenericTableTest.java diff --git a/src/test/java/net/imagej/table/DefaultGenericTableTest.java b/src/test/java/net/imagej/table/DefaultGenericTableTest.java new file mode 100644 index 0000000..b1c6545 --- /dev/null +++ b/src/test/java/net/imagej/table/DefaultGenericTableTest.java @@ -0,0 +1,151 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Collection; + +import org.junit.Test; + +/** + * Tests {@link DefaultGenericTable}. + * + * @author Alison Walter + */ +public class DefaultGenericTableTest { + + @Test + public void testTypes() { + final GenericTable table = makeTable(); + table.appendColumn(); + assertEquals(table.get(0).getType(), Byte.class); + assertEquals(table.get(1).getType(), Character.class); + assertEquals(table.get(2).getType(), Float.class); + assertEquals(table.get(3).getType(), String.class); + assertEquals(table.get(4).getType(), Object.class); + assertTrue(GenericColumn.class.isInstance(table.get(4))); + } + + @Test + public void testValues() { + final GenericTable table = makeTable(); + + assertTrue(Byte.class.isInstance(table.get(0, 0))); + assertEquals(table.get(0, 3), (byte) 0); + assertEquals(table.get(0).getHeader(), "ByteHeader"); + + assertTrue(Character.class.isInstance(table.get(1, 0))); + assertEquals(table.get(1, 0), 'A'); + assertEquals(table.get(1).getHeader(), "CharHeader"); + + assertTrue(Float.class.isInstance(table.get(2, 0))); + assertEquals(table.get(2, 2), -100.25f); + assertEquals(table.get(2).getHeader(), "FloatHeader"); + + assertTrue(String.class.isInstance(table.get(3, 0))); + assertEquals(table.get(3, 1), "hello"); + assertEquals(table.get(3).getHeader(), "StringHeader"); + } + + @Test + public void testAddOps() { + final GenericTable table = makeTable(); + final BoolColumn bcol = new BoolColumn(); + final boolean[] bval = { true, true, true, false }; + bcol.fill(bval); + + table.add(1, bcol); + assertTrue(BoolColumn.class.isInstance(table.get(1))); + + final Collection> c = new ArrayList<>(); + final ShortColumn scol = new ShortColumn(); + final short[] sval = { 1, 11234, -13124, -18 }; + scol.fill(sval); + c.add(scol); + c.add(bcol); + + table.addAll(c); + assertTrue(ShortColumn.class.isInstance(table.get(5))); + assertTrue(BoolColumn.class.isInstance(table.get(6))); + assertEquals(table.getRowCount(), 4); + assertEquals(table.getColumnCount(), 7); + + final IntColumn icol = new IntColumn(); + final int[] ival = { 1, 2, 3, 4, 5, 6, 7, 8 }; + icol.fill(ival); + c.add(icol); + + table.addAll(0, c); + assertTrue(ShortColumn.class.isInstance(table.get(0))); + assertTrue(BoolColumn.class.isInstance(table.get(1))); + assertTrue(IntColumn.class.isInstance(table.get(2))); + assertEquals(table.getRowCount(), 8); + assertEquals(table.getColumnCount(), 10); + assertEquals(table.get(3, 6), (byte) 0); + } + + // TODO add more tests + + // -- Helper methods -- + + private GenericTable makeTable() { + // create table and columns + final GenericTable table = new DefaultGenericTable(); + final ByteColumn col = new ByteColumn("ByteHeader"); + final CharColumn col1 = new CharColumn("CharHeader"); + final FloatColumn col2 = new FloatColumn("FloatHeader"); + final DefaultColumn col3 = + new DefaultColumn<>(String.class, "StringHeader"); + + // fill columns with values + final byte[] bval = { 3, 127, -128, 0 }; + final char[] cval = { 'A', '&', '\t', '4' }; + final float[] fval = { 12.125f, 100.5f, -100.25f, -0.03125f }; + final String[] sval = { "hi", "hello", "good day", "greetings!" }; + col.fill(bval); + col1.fill(cval); + col2.fill(fval); + col3.setArray(sval.clone()); + col3.setSize(sval.length); + + // add columns to table + table.add(col); + table.add(col1); + table.add(col2); + table.add(col3); + return table; + } + +} From 809133c56656711ce77078ad241fcea7f53b5993 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 2 Sep 2016 11:31:02 -0500 Subject: [PATCH 32/42] Happy New Year 2016 --- src/main/java/net/imagej/table/BoolColumn.java | 2 +- src/main/java/net/imagej/table/BoolTable.java | 2 +- src/main/java/net/imagej/table/ByteColumn.java | 2 +- src/main/java/net/imagej/table/ByteTable.java | 2 +- src/main/java/net/imagej/table/CharColumn.java | 2 +- src/main/java/net/imagej/table/CharTable.java | 2 +- src/main/java/net/imagej/table/DefaultBoolTable.java | 2 +- src/main/java/net/imagej/table/DefaultByteTable.java | 2 +- src/main/java/net/imagej/table/DefaultCharTable.java | 2 +- src/main/java/net/imagej/table/DefaultFloatTable.java | 2 +- src/main/java/net/imagej/table/DefaultIntTable.java | 2 +- src/main/java/net/imagej/table/DefaultLongTable.java | 2 +- src/main/java/net/imagej/table/DefaultShortTable.java | 2 +- src/main/java/net/imagej/table/FloatColumn.java | 2 +- src/main/java/net/imagej/table/FloatTable.java | 2 +- src/main/java/net/imagej/table/IntColumn.java | 2 +- src/main/java/net/imagej/table/IntTable.java | 2 +- src/main/java/net/imagej/table/LongColumn.java | 2 +- src/main/java/net/imagej/table/LongTable.java | 2 +- src/main/java/net/imagej/table/PrimitiveColumn.java | 2 +- src/main/java/net/imagej/table/ShortColumn.java | 2 +- src/main/java/net/imagej/table/ShortTable.java | 2 +- src/test/java/net/imagej/table/DefaultBoolTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultByteTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultCharTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultFloatTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultGenericTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultIntTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultLongTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultShortTableTest.java | 2 +- 30 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index 316d8cb..606096c 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/BoolTable.java b/src/main/java/net/imagej/table/BoolTable.java index ee02953..d75ad85 100644 --- a/src/main/java/net/imagej/table/BoolTable.java +++ b/src/main/java/net/imagej/table/BoolTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index 93599dd..29af101 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ByteTable.java b/src/main/java/net/imagej/table/ByteTable.java index 57ee34e..90720db 100644 --- a/src/main/java/net/imagej/table/ByteTable.java +++ b/src/main/java/net/imagej/table/ByteTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index 085d707..1442cc3 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/CharTable.java b/src/main/java/net/imagej/table/CharTable.java index c289afc..3e7327a 100644 --- a/src/main/java/net/imagej/table/CharTable.java +++ b/src/main/java/net/imagej/table/CharTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultBoolTable.java b/src/main/java/net/imagej/table/DefaultBoolTable.java index c4bcdca..75c55d8 100644 --- a/src/main/java/net/imagej/table/DefaultBoolTable.java +++ b/src/main/java/net/imagej/table/DefaultBoolTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultByteTable.java b/src/main/java/net/imagej/table/DefaultByteTable.java index 6df54b5..4c6e99f 100644 --- a/src/main/java/net/imagej/table/DefaultByteTable.java +++ b/src/main/java/net/imagej/table/DefaultByteTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultCharTable.java b/src/main/java/net/imagej/table/DefaultCharTable.java index d33d54f..a0024cc 100644 --- a/src/main/java/net/imagej/table/DefaultCharTable.java +++ b/src/main/java/net/imagej/table/DefaultCharTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultFloatTable.java b/src/main/java/net/imagej/table/DefaultFloatTable.java index 20a8875..775114e 100644 --- a/src/main/java/net/imagej/table/DefaultFloatTable.java +++ b/src/main/java/net/imagej/table/DefaultFloatTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultIntTable.java b/src/main/java/net/imagej/table/DefaultIntTable.java index 1f800d2..ead06d2 100644 --- a/src/main/java/net/imagej/table/DefaultIntTable.java +++ b/src/main/java/net/imagej/table/DefaultIntTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultLongTable.java b/src/main/java/net/imagej/table/DefaultLongTable.java index 0e4ac00..82b43b0 100644 --- a/src/main/java/net/imagej/table/DefaultLongTable.java +++ b/src/main/java/net/imagej/table/DefaultLongTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultShortTable.java b/src/main/java/net/imagej/table/DefaultShortTable.java index 1f3cf50..98867f8 100644 --- a/src/main/java/net/imagej/table/DefaultShortTable.java +++ b/src/main/java/net/imagej/table/DefaultShortTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index d777d9f..4bf97d5 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/FloatTable.java b/src/main/java/net/imagej/table/FloatTable.java index d6306bb..03c2e29 100644 --- a/src/main/java/net/imagej/table/FloatTable.java +++ b/src/main/java/net/imagej/table/FloatTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index 026c1b5..c8d6203 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/IntTable.java b/src/main/java/net/imagej/table/IntTable.java index 20988cb..bfd2977 100644 --- a/src/main/java/net/imagej/table/IntTable.java +++ b/src/main/java/net/imagej/table/IntTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index edb2371..619dd17 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/LongTable.java b/src/main/java/net/imagej/table/LongTable.java index 4cd0a74..acb618c 100644 --- a/src/main/java/net/imagej/table/LongTable.java +++ b/src/main/java/net/imagej/table/LongTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/PrimitiveColumn.java b/src/main/java/net/imagej/table/PrimitiveColumn.java index 9e5fef4..f0d7076 100644 --- a/src/main/java/net/imagej/table/PrimitiveColumn.java +++ b/src/main/java/net/imagej/table/PrimitiveColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index 75a3d85..959e79f 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ShortTable.java b/src/main/java/net/imagej/table/ShortTable.java index 6c58ac0..a560d41 100644 --- a/src/main/java/net/imagej/table/ShortTable.java +++ b/src/main/java/net/imagej/table/ShortTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index 61a8ccd..5202428 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index 7964310..1e53a04 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index 8a3ab71..0300761 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index e1ce2b6..bea2a06 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultGenericTableTest.java b/src/test/java/net/imagej/table/DefaultGenericTableTest.java index b1c6545..3254b38 100644 --- a/src/test/java/net/imagej/table/DefaultGenericTableTest.java +++ b/src/test/java/net/imagej/table/DefaultGenericTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index 6955fba..9450842 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index a73c13b..5a71d50 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index fbcc1af..690f543 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2015 Board of Regents of the University of + * Copyright (C) 2009 - 2016 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% From 15980d20072325d915c4d769d239d58913e8bf9d Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 2 Sep 2016 11:09:18 -0500 Subject: [PATCH 33/42] Aggregate display of simple outputs into a table This change is an attempt to address two related problems: 1. There are no Display plugins (and hence no DisplayViewers) for numbers or booleans. 2. The DisplayPostprocessor tries to handle each output using its own Display, which is pretty clunky when there are several simple (text/number/boolean) outputs and several windows pop up. This postprocessor acts just before the display postprocessor, aggregating all simple outputs into a single GenericTable, which is then shown to the user via the UIService. The heuristic on whether and how to use a table is as follows: - Only simple outputs are included: text, numbers and booleans. - If there is only a single simple output, and it is text, no table is created. This minimizes negative impact on certain existing plugins which produce a large amount of text output and expect it to be displayed in a TextDisplay. --- .../table/process/ResultsPostprocessor.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/main/java/net/imagej/table/process/ResultsPostprocessor.java diff --git a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java new file mode 100644 index 0000000..45d2f43 --- /dev/null +++ b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java @@ -0,0 +1,112 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck + * Institute of Molecular Cell Biology and Genetics. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.table.process; + +import java.util.ArrayList; + +import net.imagej.table.DefaultColumn; +import net.imagej.table.DefaultGenericTable; +import net.imagej.table.GenericTable; + +import org.scijava.Priority; +import org.scijava.module.Module; +import org.scijava.module.ModuleItem; +import org.scijava.module.process.AbstractPostprocessorPlugin; +import org.scijava.module.process.PostprocessorPlugin; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; +import org.scijava.ui.UIService; +import org.scijava.util.ClassUtils; + +/** + * A postprocessor which aggregates simple output values into a single table, + * for a nicer UI experience. + * + * @author Curtis Rueden + */ +@Plugin(type = PostprocessorPlugin.class, + priority = Priority.VERY_LOW_PRIORITY + 1) +public class ResultsPostprocessor extends AbstractPostprocessorPlugin { + + @Parameter + private UIService ui; + + // -- ModuleProcessor methods -- + + @Override + public void process(final Module module) { + // filter the compatible outputs (simple types: number, boolean, text) + final ArrayList> outputs = new ArrayList<>(); + module.getInfo().outputs().forEach(output -> { + final String name = output.getName(); + if (module.isOutputResolved(name)) return; + if (module.getOutput(name) == null) return; + if (!isSimpleType(output.getType())) return; + outputs.add(output); + }); + + if (outputs.isEmpty()) return; // no compatible outputs + if (outputs.size() == 1 && ClassUtils.isText(outputs.get(0).getType())) { + // sole compatible output is a string; let the TextDisplay handle it + return; + } + + // create a table to house the output values + final GenericTable outputTable = new DefaultGenericTable(); + final DefaultColumn names = // + new DefaultColumn<>(String.class, "Name"); + final DefaultColumn values = // + new DefaultColumn<>(Object.class, "Value"); + + // populate the columns + for (final ModuleItem output : outputs) { + final String name = output.getName(); + names.addValue(name); + values.addValue(module.getOutput(name)); + module.resolveOutput(name); + } + + // show the table + outputTable.add(names); + outputTable.add(values); + final String title = module.getInfo().getTitle(); + ui.show(title, outputTable); + } + + // -- Helper methods -- + + private boolean isSimpleType(final Class type) { + return ClassUtils.isText(type) || // + ClassUtils.isNumber(type) || // + ClassUtils.isBoolean(type); + } +} From c74cb0730b50c6b79c1ef7830435a4a80e579f08 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Fri, 2 Sep 2016 15:45:50 -0500 Subject: [PATCH 34/42] ResultsPostprocessor: handle Object outputs better If the output type is Object, let's look at the actual object value when deciding whether to lump it into the table. We use this heuristic here because an Object output is very often the default "result" output, and we want that value to show in the table if its type is compatible. --- .../imagej/table/process/ResultsPostprocessor.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java index 45d2f43..386d3df 100644 --- a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java +++ b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java @@ -70,7 +70,7 @@ public void process(final Module module) { final String name = output.getName(); if (module.isOutputResolved(name)) return; if (module.getOutput(name) == null) return; - if (!isSimpleType(output.getType())) return; + if (!isSimple(module, output)) return; outputs.add(output); }); @@ -104,9 +104,21 @@ public void process(final Module module) { // -- Helper methods -- + private boolean isSimple(final Module m, final ModuleItem item) { + final Class type = item.getType(); + return isSimpleType(type) || // + // NB: The output is typed on Object -- maybe the default result output. + // In this case, let's decide based on the actual value rather than type. + type == Object.class && isSimpleValue(item.getValue(m)); + } + private boolean isSimpleType(final Class type) { return ClassUtils.isText(type) || // ClassUtils.isNumber(type) || // ClassUtils.isBoolean(type); } + + private boolean isSimpleValue(final Object o) { + return o != null && isSimpleType(o.getClass()); + } } From 1d3907914745634518749a58f7c85bd59e2ce412 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Wed, 21 Dec 2016 10:41:14 -0600 Subject: [PATCH 35/42] ResultsPostprocessor: do not require UIService If there isn't one, we simply do nothing. This avoids "Required service is missing" injection errors when instantiating this postprocessor. --- .../net/imagej/table/process/ResultsPostprocessor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java index 386d3df..65d3927 100644 --- a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java +++ b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java @@ -57,13 +57,18 @@ priority = Priority.VERY_LOW_PRIORITY + 1) public class ResultsPostprocessor extends AbstractPostprocessorPlugin { - @Parameter + @Parameter(required = false) private UIService ui; // -- ModuleProcessor methods -- @Override public void process(final Module module) { + if (ui == null) { + // no UIService available for displaying results + return; + } + // filter the compatible outputs (simple types: number, boolean, text) final ArrayList> outputs = new ArrayList<>(); module.getInfo().outputs().forEach(output -> { From 8938075851086d7735e7a680b583b22830ad1cea Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 17 Jan 2017 07:08:25 -0600 Subject: [PATCH 36/42] Happy New Year 2017 --- src/main/java/net/imagej/table/AbstractTable.java | 2 +- src/main/java/net/imagej/table/BoolColumn.java | 2 +- src/main/java/net/imagej/table/BoolTable.java | 2 +- src/main/java/net/imagej/table/ByteColumn.java | 2 +- src/main/java/net/imagej/table/ByteTable.java | 2 +- src/main/java/net/imagej/table/CharColumn.java | 2 +- src/main/java/net/imagej/table/CharTable.java | 2 +- src/main/java/net/imagej/table/Column.java | 2 +- src/main/java/net/imagej/table/DefaultBoolTable.java | 2 +- src/main/java/net/imagej/table/DefaultByteTable.java | 2 +- src/main/java/net/imagej/table/DefaultCharTable.java | 2 +- src/main/java/net/imagej/table/DefaultColumn.java | 2 +- src/main/java/net/imagej/table/DefaultFloatTable.java | 2 +- src/main/java/net/imagej/table/DefaultGenericTable.java | 2 +- src/main/java/net/imagej/table/DefaultIntTable.java | 2 +- src/main/java/net/imagej/table/DefaultLongTable.java | 2 +- src/main/java/net/imagej/table/DefaultResultsTable.java | 2 +- src/main/java/net/imagej/table/DefaultShortTable.java | 2 +- src/main/java/net/imagej/table/DefaultTableDisplay.java | 2 +- src/main/java/net/imagej/table/DoubleColumn.java | 2 +- src/main/java/net/imagej/table/FloatColumn.java | 2 +- src/main/java/net/imagej/table/FloatTable.java | 2 +- src/main/java/net/imagej/table/GenericColumn.java | 2 +- src/main/java/net/imagej/table/GenericTable.java | 2 +- src/main/java/net/imagej/table/IntColumn.java | 2 +- src/main/java/net/imagej/table/IntTable.java | 2 +- src/main/java/net/imagej/table/LongColumn.java | 2 +- src/main/java/net/imagej/table/LongTable.java | 2 +- src/main/java/net/imagej/table/PrimitiveColumn.java | 2 +- src/main/java/net/imagej/table/ResultsImg.java | 2 +- src/main/java/net/imagej/table/ResultsTable.java | 2 +- src/main/java/net/imagej/table/ShortColumn.java | 2 +- src/main/java/net/imagej/table/ShortTable.java | 2 +- src/main/java/net/imagej/table/Table.java | 2 +- src/main/java/net/imagej/table/TableDisplay.java | 2 +- src/main/java/net/imagej/table/TableLoader.java | 2 +- .../java/net/imagej/table/process/ResultsPostprocessor.java | 2 +- src/test/java/net/imagej/table/DefaultBoolTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultByteTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultCharTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultFloatTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultGenericTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultIntTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultLongTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultResultsTableTest.java | 2 +- src/test/java/net/imagej/table/DefaultShortTableTest.java | 2 +- 46 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/net/imagej/table/AbstractTable.java index bdf7c9a..66bdcab 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/net/imagej/table/AbstractTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/net/imagej/table/BoolColumn.java index 606096c..87c9411 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/net/imagej/table/BoolColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/BoolTable.java b/src/main/java/net/imagej/table/BoolTable.java index d75ad85..a9f9653 100644 --- a/src/main/java/net/imagej/table/BoolTable.java +++ b/src/main/java/net/imagej/table/BoolTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/net/imagej/table/ByteColumn.java index 29af101..dd4151b 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/net/imagej/table/ByteColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ByteTable.java b/src/main/java/net/imagej/table/ByteTable.java index 90720db..2132dc8 100644 --- a/src/main/java/net/imagej/table/ByteTable.java +++ b/src/main/java/net/imagej/table/ByteTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/net/imagej/table/CharColumn.java index 1442cc3..feda1af 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/net/imagej/table/CharColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/CharTable.java b/src/main/java/net/imagej/table/CharTable.java index 3e7327a..bcb7ae2 100644 --- a/src/main/java/net/imagej/table/CharTable.java +++ b/src/main/java/net/imagej/table/CharTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/net/imagej/table/Column.java index e0273ed..9b97606 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/net/imagej/table/Column.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultBoolTable.java b/src/main/java/net/imagej/table/DefaultBoolTable.java index 75c55d8..9a144ba 100644 --- a/src/main/java/net/imagej/table/DefaultBoolTable.java +++ b/src/main/java/net/imagej/table/DefaultBoolTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultByteTable.java b/src/main/java/net/imagej/table/DefaultByteTable.java index 4c6e99f..47130be 100644 --- a/src/main/java/net/imagej/table/DefaultByteTable.java +++ b/src/main/java/net/imagej/table/DefaultByteTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultCharTable.java b/src/main/java/net/imagej/table/DefaultCharTable.java index a0024cc..9d44160 100644 --- a/src/main/java/net/imagej/table/DefaultCharTable.java +++ b/src/main/java/net/imagej/table/DefaultCharTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/net/imagej/table/DefaultColumn.java index 4424b26..8e7fdc4 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/net/imagej/table/DefaultColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultFloatTable.java b/src/main/java/net/imagej/table/DefaultFloatTable.java index 775114e..33ac607 100644 --- a/src/main/java/net/imagej/table/DefaultFloatTable.java +++ b/src/main/java/net/imagej/table/DefaultFloatTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/net/imagej/table/DefaultGenericTable.java index d5e7046..649c062 100644 --- a/src/main/java/net/imagej/table/DefaultGenericTable.java +++ b/src/main/java/net/imagej/table/DefaultGenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultIntTable.java b/src/main/java/net/imagej/table/DefaultIntTable.java index ead06d2..069b3e4 100644 --- a/src/main/java/net/imagej/table/DefaultIntTable.java +++ b/src/main/java/net/imagej/table/DefaultIntTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultLongTable.java b/src/main/java/net/imagej/table/DefaultLongTable.java index 82b43b0..226efbb 100644 --- a/src/main/java/net/imagej/table/DefaultLongTable.java +++ b/src/main/java/net/imagej/table/DefaultLongTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java index 14c8ab3..c829a22 100644 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ b/src/main/java/net/imagej/table/DefaultResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultShortTable.java b/src/main/java/net/imagej/table/DefaultShortTable.java index 98867f8..59a66bd 100644 --- a/src/main/java/net/imagej/table/DefaultShortTable.java +++ b/src/main/java/net/imagej/table/DefaultShortTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java index 24f155c..2a2faa7 100644 --- a/src/main/java/net/imagej/table/DefaultTableDisplay.java +++ b/src/main/java/net/imagej/table/DefaultTableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/net/imagej/table/DoubleColumn.java index 44a9714..27cfa7b 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/net/imagej/table/DoubleColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/net/imagej/table/FloatColumn.java index 4bf97d5..0b8caaa 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/net/imagej/table/FloatColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/FloatTable.java b/src/main/java/net/imagej/table/FloatTable.java index 03c2e29..07a5f2b 100644 --- a/src/main/java/net/imagej/table/FloatTable.java +++ b/src/main/java/net/imagej/table/FloatTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/net/imagej/table/GenericColumn.java index fb892ad..a6fe4a9 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/net/imagej/table/GenericColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/net/imagej/table/GenericTable.java index 4e1d605..c36305e 100644 --- a/src/main/java/net/imagej/table/GenericTable.java +++ b/src/main/java/net/imagej/table/GenericTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/net/imagej/table/IntColumn.java index c8d6203..8c1f0f2 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/net/imagej/table/IntColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/IntTable.java b/src/main/java/net/imagej/table/IntTable.java index bfd2977..8141f01 100644 --- a/src/main/java/net/imagej/table/IntTable.java +++ b/src/main/java/net/imagej/table/IntTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/net/imagej/table/LongColumn.java index 619dd17..680a0c7 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/net/imagej/table/LongColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/LongTable.java b/src/main/java/net/imagej/table/LongTable.java index acb618c..b6e4d8c 100644 --- a/src/main/java/net/imagej/table/LongTable.java +++ b/src/main/java/net/imagej/table/LongTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/PrimitiveColumn.java b/src/main/java/net/imagej/table/PrimitiveColumn.java index f0d7076..51ae021 100644 --- a/src/main/java/net/imagej/table/PrimitiveColumn.java +++ b/src/main/java/net/imagej/table/PrimitiveColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java index 5442998..66780fa 100644 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java index 7a7d222..2070d65 100644 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ b/src/main/java/net/imagej/table/ResultsTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/net/imagej/table/ShortColumn.java index 959e79f..f31d155 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/net/imagej/table/ShortColumn.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/ShortTable.java b/src/main/java/net/imagej/table/ShortTable.java index a560d41..380d646 100644 --- a/src/main/java/net/imagej/table/ShortTable.java +++ b/src/main/java/net/imagej/table/ShortTable.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/net/imagej/table/Table.java index 4636de2..cbbf136 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/net/imagej/table/Table.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableDisplay.java b/src/main/java/net/imagej/table/TableDisplay.java index d862917..09e9fcd 100644 --- a/src/main/java/net/imagej/table/TableDisplay.java +++ b/src/main/java/net/imagej/table/TableDisplay.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/TableLoader.java b/src/main/java/net/imagej/table/TableLoader.java index 9d06e04..0c1bc0e 100644 --- a/src/main/java/net/imagej/table/TableLoader.java +++ b/src/main/java/net/imagej/table/TableLoader.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java index 65d3927..6d8fcd0 100644 --- a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java +++ b/src/main/java/net/imagej/table/process/ResultsPostprocessor.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/net/imagej/table/DefaultBoolTableTest.java index 5202428..919cfa7 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/net/imagej/table/DefaultBoolTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/net/imagej/table/DefaultByteTableTest.java index 1e53a04..1c35690 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/net/imagej/table/DefaultByteTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/net/imagej/table/DefaultCharTableTest.java index 0300761..11d7add 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/net/imagej/table/DefaultCharTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/net/imagej/table/DefaultFloatTableTest.java index bea2a06..3cb7ee0 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/net/imagej/table/DefaultFloatTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultGenericTableTest.java b/src/test/java/net/imagej/table/DefaultGenericTableTest.java index 3254b38..fffa075 100644 --- a/src/test/java/net/imagej/table/DefaultGenericTableTest.java +++ b/src/test/java/net/imagej/table/DefaultGenericTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/net/imagej/table/DefaultIntTableTest.java index 9450842..8f7cb24 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/net/imagej/table/DefaultIntTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/net/imagej/table/DefaultLongTableTest.java index 5a71d50..5ae87c1 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/net/imagej/table/DefaultLongTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java index 8c45e33..6166583 100644 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ b/src/test/java/net/imagej/table/DefaultResultsTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/net/imagej/table/DefaultShortTableTest.java index 690f543..e5af4aa 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/net/imagej/table/DefaultShortTableTest.java @@ -2,7 +2,7 @@ * #%L * ImageJ software for multidimensional image processing and analysis. * %% - * Copyright (C) 2009 - 2016 Board of Regents of the University of + * Copyright (C) 2009 - 2017 Board of Regents of the University of * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck * Institute of Molecular Cell Biology and Genetics. * %% From 28ebe305223db380b2a94961d44589f3b274a2ce Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Tue, 24 Apr 2018 15:17:14 -0500 Subject: [PATCH 37/42] Update to imglib2 5.0.0 This updates the code to use the revised ImgFactory API. --- src/main/java/net/imagej/table/ResultsImg.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java index 66780fa..aa2a6a7 100644 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ b/src/main/java/net/imagej/table/ResultsImg.java @@ -35,7 +35,6 @@ import net.imglib2.Cursor; import net.imglib2.Interval; -import net.imglib2.IterableRealInterval; import net.imglib2.Positionable; import net.imglib2.RandomAccess; import net.imglib2.RealPositionable; From 8e3bf8f8f11ff2cd02ba7a820692756a58dcbd67 Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Tue, 24 Apr 2018 15:46:17 -0500 Subject: [PATCH 38/42] Add TableService --- .../java/net/imagej/table/TableService.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/net/imagej/table/TableService.java diff --git a/src/main/java/net/imagej/table/TableService.java b/src/main/java/net/imagej/table/TableService.java new file mode 100644 index 0000000..22bc66b --- /dev/null +++ b/src/main/java/net/imagej/table/TableService.java @@ -0,0 +1,57 @@ + +package net.imagej.table; + +import java.util.ArrayList; +import java.util.List; + +import net.imagej.Dataset; +import net.imagej.ImageJService; + +import org.scijava.service.Service; + +/** + * {@link Service} for working with {@link Table}s. + * + * @author Alison Walter + */ +public interface TableService extends ImageJService { + + public static final String TABLE_PROPERTY = "tables"; + + /** + * Retrieves the {@link Table}s attached to the given {@link Dataset}. + * + * @param img {@link Dataset} whose {@link Table}s are desired + * @return {@link Table}s associated with {@code img} + */ + List> getTables(final Dataset img); + + /** + * Attaches the given {@link Table} to the {@link Dataset} + * + * @param table {@link Table} to be attached + * @param img {@link Dataset} to attach the table to + */ + @SuppressWarnings("unchecked") + default void add(final Table table, final Dataset img) { + if (img.getProperties().get(TABLE_PROPERTY) != null) { + ((List>) img.getProperties().get(TABLE_PROPERTY)).add(table); + } + else { + final List> t = new ArrayList<>(); + t.add(table); + img.getProperties().put(TABLE_PROPERTY, t); + } + } + + /** + * Clears any {@link Table}s associated with the given {@link Dataset}. + * + * @param img the {@link Dataset} whose attached {@link Table}s will be + * cleared. + */ + default void clear(final Dataset img) { + img.getProperties().put(TABLE_PROPERTY, null); + } + +} From c127cd5aa731b1249c67d4e431885ab96979bcec Mon Sep 17 00:00:00 2001 From: Alison Walter Date: Fri, 27 Apr 2018 13:00:23 -0500 Subject: [PATCH 39/42] Add default table service --- .../net/imagej/table/DefaultTableService.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/net/imagej/table/DefaultTableService.java diff --git a/src/main/java/net/imagej/table/DefaultTableService.java b/src/main/java/net/imagej/table/DefaultTableService.java new file mode 100644 index 0000000..5d9cd15 --- /dev/null +++ b/src/main/java/net/imagej/table/DefaultTableService.java @@ -0,0 +1,23 @@ +package net.imagej.table; + +import java.util.List; + +import net.imagej.Dataset; + +import org.scijava.plugin.Plugin; +import org.scijava.service.AbstractService; +import org.scijava.service.Service; + +@Plugin(type = Service.class) +public class DefaultTableService extends AbstractService implements TableService{ + + @Override + @SuppressWarnings("unchecked") + public List> getTables(Dataset img) { + final Object tables = img.getProperties().get(TABLE_PROPERTY); + if (tables != null && tables instanceof List) + return (List>) tables; + return null; + } + +} From f9a70f618286d45d6a2ec5dceb615d175a155063 Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Tue, 17 Jul 2018 12:40:33 +0200 Subject: [PATCH 40/42] Remove ImageJ-specific table classes Also remove temporary imagej-common dependency --- pom.xml | 5 - .../net/imagej/table/DefaultResultsTable.java | 79 ---- .../net/imagej/table/DefaultTableDisplay.java | 124 ----- .../net/imagej/table/DefaultTableService.java | 23 - .../java/net/imagej/table/ResultsImg.java | 235 ---------- .../java/net/imagej/table/ResultsTable.java | 57 --- .../java/net/imagej/table/TableLoader.java | 208 --------- .../java/net/imagej/table/TableService.java | 57 --- .../imagej/table/DefaultResultsTableTest.java | 430 ------------------ 9 files changed, 1218 deletions(-) delete mode 100644 src/main/java/net/imagej/table/DefaultResultsTable.java delete mode 100644 src/main/java/net/imagej/table/DefaultTableDisplay.java delete mode 100644 src/main/java/net/imagej/table/DefaultTableService.java delete mode 100644 src/main/java/net/imagej/table/ResultsImg.java delete mode 100644 src/main/java/net/imagej/table/ResultsTable.java delete mode 100644 src/main/java/net/imagej/table/TableLoader.java delete mode 100644 src/main/java/net/imagej/table/TableService.java delete mode 100644 src/test/java/net/imagej/table/DefaultResultsTableTest.java diff --git a/pom.xml b/pom.xml index c7f5fcb..b747d01 100644 --- a/pom.xml +++ b/pom.xml @@ -103,11 +103,6 @@ Konstanz, and KNIME GmbH. scijava-common - - net.imagej - imagej-common - - junit diff --git a/src/main/java/net/imagej/table/DefaultResultsTable.java b/src/main/java/net/imagej/table/DefaultResultsTable.java deleted file mode 100644 index c829a22..0000000 --- a/src/main/java/net/imagej/table/DefaultResultsTable.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import net.imagej.ImgPlus; -import net.imagej.axis.Axes; -import net.imagej.axis.AxisType; -import net.imglib2.img.Img; -import net.imglib2.type.numeric.real.DoubleType; - -/** - * Default implementation of {@link ResultsTable}. - * - * @author Curtis Rueden - */ -public class DefaultResultsTable extends AbstractTable - implements ResultsTable -{ - - /** Creates an empty results table. */ - public DefaultResultsTable() { - super(); - } - - /** Creates a results table with the given row and column dimensions. */ - public DefaultResultsTable(final int columnCount, final int rowCount) { - super(columnCount, rowCount); - } - - // -- ResultsTable methods -- - - @Override - public ImgPlus img() { - final Img img = new ResultsImg(this); - final AxisType[] axes = { Axes.X, Axes.Y }; - final String name = "Results"; - final ImgPlus imgPlus = - new ImgPlus<>(img, name, axes); - // TODO: Once ImgPlus has a place for row & column labels, add those too. - return imgPlus; - } - - // -- Internal methods -- - - @Override - protected DoubleColumn createColumn(final String header) { - return new DoubleColumn(header); - } - -} diff --git a/src/main/java/net/imagej/table/DefaultTableDisplay.java b/src/main/java/net/imagej/table/DefaultTableDisplay.java deleted file mode 100644 index 2a2faa7..0000000 --- a/src/main/java/net/imagej/table/DefaultTableDisplay.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import org.scijava.display.AbstractDisplay; -import org.scijava.display.Display; -import org.scijava.plugin.Plugin; - -/** - * Default display for {@link Table}s, including {@link ResultsTable}s. - * - * @author Curtis Rueden - */ -@Plugin(type = Display.class) -public class DefaultTableDisplay extends AbstractDisplay> implements - TableDisplay -{ - - @SuppressWarnings({ "rawtypes", "unchecked" }) - public DefaultTableDisplay() { - super((Class) Table.class); - } - - // -- Display methods -- - - @Override - public boolean canDisplay(final Class c) { - if (c == double[].class || c == double[][].class) return true; - return super.canDisplay(c); - } - - @Override - public void display(final Object o) { - // wrap 1D array as results table - if (o instanceof double[]) { - display(wrapArrayAsTable(new double[][] { (double[]) o })); - return; - } - // wrap 2D array as results table - if (o instanceof double[][]) { - display(wrapArrayAsTable((double[][]) o)); - return; - } - - super.display(o); - } - - @Override - public boolean isDisplaying(final Object o) { - if (super.isDisplaying(o)) return true; - - // check for wrapped arrays - if (o instanceof double[]) { - arrayEqualsTable(new double[][] {(double[]) o}); - } - if (o instanceof double[][]) { - arrayEqualsTable((double[][]) o); - } - - return false; - } - - // -- Helper methods -- - - private ResultsTable wrapArrayAsTable(final double[][] array) { - final ResultsTable table = new DefaultResultsTable(); - int rowCount = 0; - for (int d = 0; d < array.length; d++) { - final DoubleColumn column = new DoubleColumn(); - column.setArray(array[d]); - table.add(column); - if (rowCount < array[d].length) rowCount = array[d].length; - } - table.setRowCount(rowCount); - return table; - } - - private boolean arrayEqualsTable(final double[][] array) { - for (final Table table : this) { - if (!(table instanceof ResultsTable)) continue; - final ResultsTable resultsTable = (ResultsTable) table; - if (array.length != resultsTable.getColumnCount()) continue; - boolean equal = true; - for (int c = 0; c < array.length; c++) { - if (array[c] != resultsTable.get(c).getArray()) { - equal = false; - break; - } - } - return equal; - } - return false; - } - -} diff --git a/src/main/java/net/imagej/table/DefaultTableService.java b/src/main/java/net/imagej/table/DefaultTableService.java deleted file mode 100644 index 5d9cd15..0000000 --- a/src/main/java/net/imagej/table/DefaultTableService.java +++ /dev/null @@ -1,23 +0,0 @@ -package net.imagej.table; - -import java.util.List; - -import net.imagej.Dataset; - -import org.scijava.plugin.Plugin; -import org.scijava.service.AbstractService; -import org.scijava.service.Service; - -@Plugin(type = Service.class) -public class DefaultTableService extends AbstractService implements TableService{ - - @Override - @SuppressWarnings("unchecked") - public List> getTables(Dataset img) { - final Object tables = img.getProperties().get(TABLE_PROPERTY); - if (tables != null && tables instanceof List) - return (List>) tables; - return null; - } - -} diff --git a/src/main/java/net/imagej/table/ResultsImg.java b/src/main/java/net/imagej/table/ResultsImg.java deleted file mode 100644 index aa2a6a7..0000000 --- a/src/main/java/net/imagej/table/ResultsImg.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import java.util.Iterator; - -import net.imglib2.Cursor; -import net.imglib2.Interval; -import net.imglib2.Positionable; -import net.imglib2.RandomAccess; -import net.imglib2.RealPositionable; -import net.imglib2.img.Img; -import net.imglib2.img.ImgFactory; -import net.imglib2.type.numeric.real.DoubleType; - -/** - * Expresses a {@link ResultsTable} as an {@link Img}. - * - * @author Curtis Rueden - */ -public class ResultsImg implements Img { - - private final ResultsTable table; - - public ResultsImg(final ResultsTable table) { - this.table = table; - } - - // -- RandomAccessible methods -- - - @Override - public RandomAccess randomAccess() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - @Override - public RandomAccess randomAccess(final Interval interval) { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - // -- EuclideanSpace methods -- - - @Override - public int numDimensions() { - return 2; - } - - // -- Interval methods -- - - @Override - public long min(final int d) { - if (d >= 0 && d <= 1) return 0; - throw new IllegalArgumentException("Invalid dimension: " + d); - } - - @Override - public void min(final long[] min) { - min[0] = min[1] = 0; - } - - @Override - public void min(final Positionable min) { - min.setPosition(0, 0); - min.setPosition(0, 1); - } - - @Override - public long max(final int d) { - if (d == 0) return max0(); - if (d == 1) return max1(); - throw new IllegalArgumentException("Invalid dimension: " + d); - } - - @Override - public void max(final long[] max) { - max[0] = max0(); - max[1] = max1(); - } - - @Override - public void max(final Positionable max) { - max.setPosition(0, max0()); - max.setPosition(0, max1()); - } - - // -- RealInterval methods -- - - @Override - public double realMin(final int d) { - return min(d); - } - - @Override - public void realMin(final double[] min) { - min[0] = min[1] = 0; - } - - @Override - public void realMin(final RealPositionable min) { - min(min); - } - - @Override - public double realMax(final int d) { - return max(d); - } - - @Override - public void realMax(final double[] max) { - max[0] = table.getColumnCount(); - max[1] = table.getRowCount(); - } - - @Override - public void realMax(final RealPositionable max) { - max(max); - } - - // -- Dimensions methods -- - - @Override - public void dimensions(final long[] dimensions) { - dimensions[0] = dim0(); - dimensions[1] = dim1(); - } - - @Override - public long dimension(final int d) { - if (d == 0) return dim0(); - if (d == 1) return dim1(); - throw new IllegalArgumentException("Invalid dimension: " + d); - } - - // -- IterableRealInterval methods -- - - @Override - public Cursor cursor() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - @Override - public Cursor localizingCursor() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - @Override - public long size() { - return (long) dim0() * dim1(); - } - - @Override - public DoubleType firstElement() { - return new DoubleType(table.get(0, 0)); - } - - @Override - public Object iterationOrder() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - // -- Iterable methods -- - - @Override - public Iterator iterator() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - // -- Img methods -- - - @Override - public ImgFactory factory() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - @Override - public Img copy() { - // TODO - throw new UnsupportedOperationException("Unimplemented"); - } - - // -- Helper methods -- - - private int dim0() { - return table.getColumnCount(); - } - - private int dim1() { - return table.getRowCount(); - } - - private int max0() { - return dim0() - 1; - } - - private int max1() { - return dim1() - 1; - } - -} diff --git a/src/main/java/net/imagej/table/ResultsTable.java b/src/main/java/net/imagej/table/ResultsTable.java deleted file mode 100644 index 2070d65..0000000 --- a/src/main/java/net/imagej/table/ResultsTable.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import net.imagej.ImgPlus; -import net.imglib2.type.numeric.real.DoubleType; - -/** - * A table of double-precision floating point values. - * - * @author Curtis Rueden - */ -public interface ResultsTable extends Table { - - /** Gets the value of the given table cell. */ - default double getValue(final int col, final int row) { - return get(col).getValue(row); - } - - /** Sets the value of the given table cell. */ - default void setValue(final int col, final int row, final double value) { - get(col).setValue(row, value); - } - - /** Wraps the results table in an ImgLib {@link net.imglib2.img.Img}. */ - ImgPlus img(); - -} diff --git a/src/main/java/net/imagej/table/TableLoader.java b/src/main/java/net/imagej/table/TableLoader.java deleted file mode 100644 index 0c1bc0e..0000000 --- a/src/main/java/net/imagej/table/TableLoader.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import java.io.BufferedInputStream; -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StreamTokenizer; -import java.net.URL; - -// note: adapted from Wayne Rasband's IJ1 TextReader class - -/** - * Loads a text file containing comma separated values into a - * {@link ResultsTable}. - * - * @author Barry DeZonia - * @author Wayne Rasband - */ -public class TableLoader { - - // -- instance variables -- - - private int rows, cols; - - // -- private legacy text file support methods -- - - /** - * Loads the values of a table stored in a text file as a ResultsTable. Given - * BufferedInputStream must be marked to hold entire contents in buffer. This - * method rewinds the buggered stream so it can read it twice. - * - * @param str The BufferedInputStream containing the data of the text table - * @return A ResultsTable containing the values (and headers) - * @throws IOException - */ - public ResultsTable valuesFromTextFile(BufferedInputStream str) - throws IOException - { - countRowsAndCols(str); - if (rows == 0) return null; - ResultsTable values = new DefaultResultsTable(cols, rows); - str.reset(); - read(str, values); - int firstRowNaNCount = 0; - for (int i = 0; i < cols; i++) { - if (Double.isNaN(values.getValue(i, 0))) firstRowNaNCount++; - } - if (firstRowNaNCount == cols) { // assume first row is header - // throw away first row of non-values - rows--; - ResultsTable oldValues = values; - values = new DefaultResultsTable(cols, rows); - for (int c = 0; c < cols; c++) { - String colHeader = oldValues.getColumnHeader(c); - values.setColumnHeader(c, colHeader); - } - for (int row = 0; row < rows; row++) { - for (int col = 0; col < cols; col++) { - double val = oldValues.getValue(col, row + 1); - values.setValue(col, row, val); - } - } - } - return values; - } - - /** - * Loads the values of a table stored in a text file as a ResultsTable. - * - * @param urlString The url (as a string) of the file containing the text - * table - * @return A ResultsTable containing the values (and headers) - * @throws IOException - */ - public ResultsTable valuesFromTextFile(String urlString) throws IOException { - return valuesFromTextFile(new URL(urlString)); - } - - /** - * Loads the values of a table stored in a text file as a ResultsTable. - * - * @param file The File containing the text table - * @return A ResultsTable containing the values (and headers) - * @throws IOException - */ - public ResultsTable valuesFromTextFile(File file) throws IOException { - FileInputStream fstr = new FileInputStream(file); - BufferedInputStream stream = new BufferedInputStream(fstr); - stream.mark((int) file.length()); - return valuesFromTextFile(stream); - } - - /** - * Loads the values of a table stored at a URL as a ResultsTable. - * - * @param url The URL location of the file containing the text table - * @return A ResultsTable containing the values (and headers) - * @throws IOException - */ - public ResultsTable valuesFromTextFile(URL url) throws IOException { - InputStream istr = url.openStream(); - BufferedInputStream stream = new BufferedInputStream(istr); - stream.mark(8000000); // about 8 megabytes: FIXME HACK - return valuesFromTextFile(stream); - } - - // -- private helpers - - - private void countRowsAndCols(InputStream str) throws IOException { - Reader r = new BufferedReader(new InputStreamReader(str)); - StreamTokenizer tok = new StreamTokenizer(r); - tok.resetSyntax(); - tok.wordChars(43, 43); - tok.wordChars(45, 126); - tok.whitespaceChars(0, 42); - tok.whitespaceChars(44, 44); - tok.whitespaceChars(127, 255); - tok.eolIsSignificant(true); - - int words = 0, wordsPrevLine = 0; - while (tok.nextToken() != StreamTokenizer.TT_EOF) { - switch (tok.ttype) { - case StreamTokenizer.TT_EOL: - rows++; - if (words == 0) rows--; // ignore empty lines - if (rows == 1 && words > 0) cols = words; - if (rows > 1 && words != 0 && words != wordsPrevLine) { - throw new IOException("Line " + rows + - " is not the same length as the first line."); - } - if (words != 0) wordsPrevLine = words; - words = 0; - break; - case StreamTokenizer.TT_WORD: - // System.out.println("read word " + tok.sval); - words++; - break; - } - } - if (words == cols) rows++; // last line does not end with EOL - } - - private void read(InputStream str, ResultsTable values) throws IOException { - Reader r = new BufferedReader(new InputStreamReader(str)); - StreamTokenizer tok = new StreamTokenizer(r); - tok.resetSyntax(); - tok.wordChars(43, 43); - tok.wordChars(45, 126); - tok.whitespaceChars(0, 42); - tok.whitespaceChars(44, 44); - tok.whitespaceChars(127, 255); - - int row = 0, col = 0; - while (tok.nextToken() != StreamTokenizer.TT_EOF) { - if (tok.ttype == StreamTokenizer.TT_WORD) { - double value; - try { - value = Double.parseDouble(tok.sval); - } - catch (NumberFormatException e) { - value = Double.NaN; - if (row == 0) values.setColumnHeader(col, tok.sval); - } - values.setValue(col, row, value); - col++; - if (col == cols) { - row++; - col = 0; - } - } - } - } -} diff --git a/src/main/java/net/imagej/table/TableService.java b/src/main/java/net/imagej/table/TableService.java deleted file mode 100644 index 22bc66b..0000000 --- a/src/main/java/net/imagej/table/TableService.java +++ /dev/null @@ -1,57 +0,0 @@ - -package net.imagej.table; - -import java.util.ArrayList; -import java.util.List; - -import net.imagej.Dataset; -import net.imagej.ImageJService; - -import org.scijava.service.Service; - -/** - * {@link Service} for working with {@link Table}s. - * - * @author Alison Walter - */ -public interface TableService extends ImageJService { - - public static final String TABLE_PROPERTY = "tables"; - - /** - * Retrieves the {@link Table}s attached to the given {@link Dataset}. - * - * @param img {@link Dataset} whose {@link Table}s are desired - * @return {@link Table}s associated with {@code img} - */ - List> getTables(final Dataset img); - - /** - * Attaches the given {@link Table} to the {@link Dataset} - * - * @param table {@link Table} to be attached - * @param img {@link Dataset} to attach the table to - */ - @SuppressWarnings("unchecked") - default void add(final Table table, final Dataset img) { - if (img.getProperties().get(TABLE_PROPERTY) != null) { - ((List>) img.getProperties().get(TABLE_PROPERTY)).add(table); - } - else { - final List> t = new ArrayList<>(); - t.add(table); - img.getProperties().put(TABLE_PROPERTY, t); - } - } - - /** - * Clears any {@link Table}s associated with the given {@link Dataset}. - * - * @param img the {@link Dataset} whose attached {@link Table}s will be - * cleared. - */ - default void clear(final Dataset img) { - img.getProperties().put(TABLE_PROPERTY, null); - } - -} diff --git a/src/test/java/net/imagej/table/DefaultResultsTableTest.java b/src/test/java/net/imagej/table/DefaultResultsTableTest.java deleted file mode 100644 index 6166583..0000000 --- a/src/test/java/net/imagej/table/DefaultResultsTableTest.java +++ /dev/null @@ -1,430 +0,0 @@ -/* - * #%L - * ImageJ software for multidimensional image processing and analysis. - * %% - * Copyright (C) 2009 - 2017 Board of Regents of the University of - * Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck - * Institute of Molecular Cell Biology and Genetics. - * %% - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * #L% - */ - -package net.imagej.table; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; - -import java.util.List; - -import org.junit.Test; - -/** - * Tests {@link DefaultResultsTable}. - * - * @author Curtis Rueden - * @author Alison Walter - */ -public class DefaultResultsTableTest { - - private static final String[] HEADERS = { "Year", "Age", "BA" }; - - // Paul Molitor - private static final double[][] DATA = { - {1978, 21, .273}, - {1979, 22, .322}, - {1980, 23, .304}, - {1981, 24, .267}, - {1982, 25, .302}, - {1983, 26, .270}, - {1984, 27, .217}, - {1985, 28, .297}, - {1986, 29, .281}, - {1987, 30, .353}, - {1988, 31, .312}, - {1989, 32, .315}, - {1990, 33, .285}, - {1991, 34, .325}, - {1992, 35, .320}, - {1993, 36, .332}, - {1994, 37, .341}, - {1995, 38, .270}, - {1996, 39, .341}, - {1997, 40, .305}, - {1998, 41, .281}, - }; - - @Test - public void testStructure() { - final ResultsTable table = createTable(); - assertEquals(3, table.getColumnCount()); - assertEquals(21, table.getRowCount()); - for (final DoubleColumn column : table) { - assertEquals(21, column.size()); - } - - assertEquals("Year", table.getColumnHeader(0)); - assertEquals("Age", table.getColumnHeader(1)); - assertEquals("BA", table.getColumnHeader(2)); - - for (int c = 0; c < table.getColumnCount(); c++) { - final DoubleColumn columnByHeader = table.get(HEADERS[c]); - final DoubleColumn columnByIndex = table.get(c); - assertSame(columnByHeader, columnByIndex); - assertEquals(DATA.length, columnByHeader.size()); - for (int r = 0; r < table.getRowCount(); r++) { - assertEquals(DATA[r][c], table.getValue(c, r), 0); - assertEquals(DATA[r][c], columnByHeader.getValue(r), 0); - } - } - } - - @Test - public void testGetColumnType() { - final ResultsTable table = createTable(); - final DoubleColumn col = table.get(0); - assertEquals(col.getType(), Double.class); - } - - @Test - public void testAppendColumn() { - final ResultsTable table = createTable(); - final double[] values = - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }; - - final DoubleColumn col = table.appendColumn("Header4"); - col.fill(values); - - // Test appending a column - assertEquals(table.getColumnCount(), 4); - assertEquals(table.get(3).getHeader(), "Header4"); - - checkTableModifiedColumn(table, values, 3); - } - - @Test - public void testRemoveColumn() { - final ResultsTable table = createTable(); - final DoubleColumn col = table.removeColumn(0); - - // Test removing a column - for (int i = 0; i < col.size(); i++) { - assertEquals(col.getValue(i), DATA[i][0], 0); - } - assertEquals(table.getColumnCount(), 2); - - checkTableModifiedColumn(table, null, 0); - } - - @Test - public void testInsertColumn() { - final ResultsTable table = createTable(); - final double[] values = - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }; - - final DoubleColumn col = table.insertColumn(1, "Header4"); - col.fill(values); - - assertEquals(table.getColumnCount(), 4); - assertEquals(table.get(1).getHeader(), "Header4"); - - checkTableModifiedColumn(table, values, 1); - } - - @Test - public void testAppendColumns() { - final ResultsTable table = createTable(); - final double[][] values = - { - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }, - { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, - -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, - -1.25, 17.25 } }; - - final String[] headers = { "Header4", "Header5" }; - final List col = table.appendColumns(headers); - col.get(0).fill(values[0]); - col.get(1).fill(values[1]); - - // Test appending a column - assertEquals(table.getColumnCount(), 5); - assertEquals(table.get(3).getHeader(), "Header4"); - assertEquals(table.get(4).getHeader(), "Header5"); - - checkTableModifiedColumns(table, values, 3, 4); - } - - @Test - public void testRemoveColumns() { - final ResultsTable table = createTable(); - - final List col = table.removeColumns(0, 2); - - // Test removing a column - for (int q = 0; q < col.size(); q++) { - for (int i = 0; i < col.get(0).size(); i++) { - assertEquals(col.get(q).getValue(i), DATA[i][q], 0); - } - } - assertEquals(table.getColumnCount(), 1); - - checkTableModifiedColumns(table, null, 0, 2); - } - - @Test - public void testInsertColumns() { - final ResultsTable table = createTable(); - final double[][] values = - { - { -0.25, 0.5, 0.625, -1.25, 0.0, 0.0325, 100.5, 13.25, 110.5, -2.25, - 4.625, -3.0, 100.0, 1209.25, -10.5, 16.25, -200.0, -0.0325, - 940385034958.5, -301284390284.25, 17.25 }, - { 0.5, 0.5, 0.25, 1.25, 0.0, 0.625, 100.5, 13.25, 11.5, -112.25, 4.625, - -3.5, 105.0, 19.625, -10.5, 16.25, 200.0325, -0.0325, 940385034958.5, - -1.25, 17.25 } }; - - final String[] headers = { "Header4", "Header5" }; - final List col = table.insertColumns(1, headers); - col.get(0).fill(values[0]); - col.get(1).fill(values[1]); - - assertEquals(table.getColumnCount(), 5); - assertEquals(table.get(1).getHeader(), "Header4"); - assertEquals(table.get(2).getHeader(), "Header5"); - - checkTableModifiedColumns(table, values, 1, 2); - } - - @Test - public void testAppendRow() { - final ResultsTable table = createTable(); - final double[] values = { 1999, 42, 0.0 }; - - // Test appending a row - table.appendRow(); - assertEquals(table.getRowCount(), 22); - for (int i = 0; i < values.length; i++) { - table.setValue(i, 21, values[i]); - assertEquals(table.getValue(i, 21), values[i], 0); - } - - checkTableModifiedRow(table, values, 21); - } - - @Test - public void testRemoveRow() { - final ResultsTable table = createTable(); - - table.removeRow(4); - - assertEquals(table.getRowCount(), 20); - for (int i = 0; i < table.getColumnCount(); i++) { - assertEquals(table.getValue(i, 4), DATA[5][i], 0); - } - - checkTableModifiedRow(table, null, 4); - } - - @Test - public void testInsertRow() { - final ResultsTable table = createTable(); - final double[] values = { 1999, 42, 0.0 }; - - table.insertRow(6); - - assertEquals(table.getRowCount(), 22); - for (int i = 0; i < table.getColumnCount(); i++) { - table.setValue(i, 6, values[i]); - } - - checkTableModifiedRow(table, values, 6); - } - - @Test - public void testAppendRows() { - final ResultsTable table = createTable(); - final double[][] values = { - { 1999, 42, 0.123 }, - { 2000, 43, 0.006 }, - { 2001, 44, 0.89 }, - { 2002, 45, 0.0 }, - }; - - // Test appending a row - table.appendRows(4); - assertEquals(table.getRowCount(), 25); - for (int r = 0; r < values.length; r++) { - for (int c = 0; c < values[0].length; c++) { - table.setValue(c, r + 21, values[r][c]); - assertEquals(table.getValue(c, r + 21), values[r][c], 0); - } - } - - checkTableModifiedRows(table, values, 21, 24); - } - - @Test - public void testRemoveRows() { - final ResultsTable table = createTable(); - table.removeRows(11, 6); - assertEquals(table.getRowCount(), 15); - - checkTableModifiedRows(table, null, 11, 16); - } - - @Test - public void testInsertRows() { - final ResultsTable table = createTable(); - final double[][] values = { - { 1999, 42, 0.123 }, - { 2000, 43, 0.006 }, - { 2001, 44, 0.89 }, - { 2002, 45, 0.0 }, - }; - - table.insertRows(3, 4); - - assertEquals(table.getRowCount(), 25); - for (int r = 0; r < values.length; r++) { - for (int c = 0; c < values[0].length; c++) { - table.setValue(c, r + 3, values[r][c]); - assertEquals(table.getValue(c, r + 3), values[r][c], 0); - } - } - - checkTableModifiedRows(table, values, 3, 6); - } - - // TODO - Add more tests. - - // -- Helper methods -- - - private ResultsTable createTable() { - final ResultsTable table = - new DefaultResultsTable(DATA[0].length, DATA.length); - - for (int c = 0; c < HEADERS.length; c++) { - table.setColumnHeader(c, HEADERS[c]); - } - - for (int r = 0; r < DATA.length; r++) { - for (int c = 0; c < DATA[r].length; c++) { - table.setValue(c, r, DATA[r][c]); - } - } - - return table; - } - - private void checkTableModifiedColumn(final ResultsTable table, - final double[] values, final int mod) - { - for (int r = 0; r < table.getRowCount(); r++) { - for (int c = 0; c < table.getColumnCount(); c++) { - if (c == mod && values != null) { - assertEquals(table.getValue(c, r), values[r], 0); - } - else if (c > mod && values != null) { - assertEquals(table.getValue(c, r), DATA[r][c - 1], 0); - } - else if (c >= mod && values == null) { - assertEquals(table.getValue(c, r), DATA[r][c + 1], 0); - } - else { - assertEquals(table.getValue(c, r), DATA[r][c], 0); - } - } - } - } - - private void checkTableModifiedRow(final ResultsTable table, - final double[] values, final int mod) - { - for (int r = 0; r < table.getRowCount(); r++) { - for (int c = 0; c < table.getColumnCount(); c++) { - if (r == mod && values != null) { - assertEquals(table.getValue(c, r), values[c], 0); - } - else if (r > mod && values != null) { - assertEquals(table.getValue(c, r), DATA[r - 1][c], 0); - } - else if (r >= mod && values == null) { - assertEquals(table.getValue(c, r), DATA[r + 1][c], 0); - } - else { - assertEquals(table.getValue(c, r), DATA[r][c], 0); - } - } - } - } - - private void checkTableModifiedColumns(final ResultsTable table, - final double[][] values, final int startMod, final int endMod) - { - for (int r = 0; r < table.getRowCount(); r++) { - for (int c = 0; c < table.getColumnCount(); c++) { - if (c >= startMod && c <= endMod && values != null) { - assertEquals(table.getValue(c, r), values[c - startMod][r], 0); - } - else if (c > endMod && values != null) { - assertEquals(table.getValue(c, r), DATA[r][c - values.length], 0); - } - else if (c >= startMod && values == null) { - assertEquals(table.getValue(c, r), DATA[r][c + (endMod - startMod)], - 0); - } - else { - assertEquals(table.getValue(c, r), DATA[r][c], 0); - } - } - } - } - - private void checkTableModifiedRows(final ResultsTable table, - final double[][] values, final int startMod, final int endMod) - { - for (int r = 0; r < table.getRowCount(); r++) { - for (int c = 0; c < table.getColumnCount(); c++) { - if (r >= startMod && r <= endMod && values != null) { - assertEquals(table.getValue(c, r), values[r - startMod][c], 0); - } - else if (r > endMod && values != null) { - assertEquals(table.getValue(c, r), DATA[r - values.length][c], 0); - } - else if (r >= startMod && values == null) { - assertEquals(table.getValue(c, r), - DATA[r + (endMod - startMod + 1)][c], 0); - } - else { - assertEquals(table.getValue(c, r), DATA[r][c], 0); - } - } - } - } - -} From 48cd88d475873585ea131c1ffe56b1e142bf1d77 Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Tue, 17 Jul 2018 12:45:13 +0200 Subject: [PATCH 41/42] Rename package net.imagej.table to org.scijava.table --- .../{net/imagej => org/scijava}/table/AbstractTable.java | 2 +- .../{net/imagej => org/scijava}/table/BoolColumn.java | 2 +- .../{net/imagej => org/scijava}/table/BoolTable.java | 2 +- .../{net/imagej => org/scijava}/table/ByteColumn.java | 2 +- .../{net/imagej => org/scijava}/table/ByteTable.java | 2 +- .../{net/imagej => org/scijava}/table/CharColumn.java | 2 +- .../{net/imagej => org/scijava}/table/CharTable.java | 2 +- .../java/{net/imagej => org/scijava}/table/Column.java | 2 +- .../imagej => org/scijava}/table/DefaultBoolTable.java | 2 +- .../imagej => org/scijava}/table/DefaultByteTable.java | 2 +- .../imagej => org/scijava}/table/DefaultCharTable.java | 2 +- .../{net/imagej => org/scijava}/table/DefaultColumn.java | 2 +- .../imagej => org/scijava}/table/DefaultFloatTable.java | 2 +- .../scijava}/table/DefaultGenericTable.java | 2 +- .../imagej => org/scijava}/table/DefaultIntTable.java | 2 +- .../imagej => org/scijava}/table/DefaultLongTable.java | 2 +- .../imagej => org/scijava}/table/DefaultShortTable.java | 2 +- .../{net/imagej => org/scijava}/table/DoubleColumn.java | 2 +- .../{net/imagej => org/scijava}/table/FloatColumn.java | 2 +- .../{net/imagej => org/scijava}/table/FloatTable.java | 2 +- .../{net/imagej => org/scijava}/table/GenericColumn.java | 2 +- .../{net/imagej => org/scijava}/table/GenericTable.java | 2 +- .../{net/imagej => org/scijava}/table/IntColumn.java | 2 +- .../java/{net/imagej => org/scijava}/table/IntTable.java | 2 +- .../{net/imagej => org/scijava}/table/LongColumn.java | 2 +- .../{net/imagej => org/scijava}/table/LongTable.java | 2 +- .../imagej => org/scijava}/table/PrimitiveColumn.java | 2 +- .../{net/imagej => org/scijava}/table/ShortColumn.java | 2 +- .../{net/imagej => org/scijava}/table/ShortTable.java | 2 +- .../java/{net/imagej => org/scijava}/table/Table.java | 2 +- .../{net/imagej => org/scijava}/table/TableDisplay.java | 2 +- .../scijava}/table/process/ResultsPostprocessor.java | 9 ++++----- .../scijava}/table/DefaultBoolTableTest.java | 2 +- .../scijava}/table/DefaultByteTableTest.java | 2 +- .../scijava}/table/DefaultCharTableTest.java | 2 +- .../scijava}/table/DefaultFloatTableTest.java | 2 +- .../scijava}/table/DefaultGenericTableTest.java | 2 +- .../scijava}/table/DefaultIntTableTest.java | 2 +- .../scijava}/table/DefaultLongTableTest.java | 2 +- .../scijava}/table/DefaultShortTableTest.java | 2 +- 40 files changed, 43 insertions(+), 44 deletions(-) rename src/main/java/{net/imagej => org/scijava}/table/AbstractTable.java (99%) rename src/main/java/{net/imagej => org/scijava}/table/BoolColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/BoolTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/ByteColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/ByteTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/CharColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/CharTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/Column.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultBoolTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultByteTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultCharTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultFloatTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultGenericTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultIntTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultLongTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DefaultShortTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/DoubleColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/FloatColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/FloatTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/GenericColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/GenericTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/IntColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/IntTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/LongColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/LongTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/PrimitiveColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/ShortColumn.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/ShortTable.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/Table.java (99%) rename src/main/java/{net/imagej => org/scijava}/table/TableDisplay.java (98%) rename src/main/java/{net/imagej => org/scijava}/table/process/ResultsPostprocessor.java (96%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultBoolTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultByteTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultCharTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultFloatTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultGenericTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultIntTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultLongTableTest.java (99%) rename src/test/java/{net/imagej => org/scijava}/table/DefaultShortTableTest.java (99%) diff --git a/src/main/java/net/imagej/table/AbstractTable.java b/src/main/java/org/scijava/table/AbstractTable.java similarity index 99% rename from src/main/java/net/imagej/table/AbstractTable.java rename to src/main/java/org/scijava/table/AbstractTable.java index 66bdcab..71a8108 100644 --- a/src/main/java/net/imagej/table/AbstractTable.java +++ b/src/main/java/org/scijava/table/AbstractTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import java.util.ArrayList; import java.util.Collection; diff --git a/src/main/java/net/imagej/table/BoolColumn.java b/src/main/java/org/scijava/table/BoolColumn.java similarity index 98% rename from src/main/java/net/imagej/table/BoolColumn.java rename to src/main/java/org/scijava/table/BoolColumn.java index 87c9411..9e4b9f9 100644 --- a/src/main/java/net/imagej/table/BoolColumn.java +++ b/src/main/java/org/scijava/table/BoolColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.BoolArray; diff --git a/src/main/java/net/imagej/table/BoolTable.java b/src/main/java/org/scijava/table/BoolTable.java similarity index 98% rename from src/main/java/net/imagej/table/BoolTable.java rename to src/main/java/org/scijava/table/BoolTable.java index a9f9653..5aaff33 100644 --- a/src/main/java/net/imagej/table/BoolTable.java +++ b/src/main/java/org/scijava/table/BoolTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of {@code boolean} values. diff --git a/src/main/java/net/imagej/table/ByteColumn.java b/src/main/java/org/scijava/table/ByteColumn.java similarity index 98% rename from src/main/java/net/imagej/table/ByteColumn.java rename to src/main/java/org/scijava/table/ByteColumn.java index dd4151b..9029eb2 100644 --- a/src/main/java/net/imagej/table/ByteColumn.java +++ b/src/main/java/org/scijava/table/ByteColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.ByteArray; diff --git a/src/main/java/net/imagej/table/ByteTable.java b/src/main/java/org/scijava/table/ByteTable.java similarity index 98% rename from src/main/java/net/imagej/table/ByteTable.java rename to src/main/java/org/scijava/table/ByteTable.java index 2132dc8..874bc13 100644 --- a/src/main/java/net/imagej/table/ByteTable.java +++ b/src/main/java/org/scijava/table/ByteTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of byte-precision integer values. diff --git a/src/main/java/net/imagej/table/CharColumn.java b/src/main/java/org/scijava/table/CharColumn.java similarity index 98% rename from src/main/java/net/imagej/table/CharColumn.java rename to src/main/java/org/scijava/table/CharColumn.java index feda1af..54bdff1 100644 --- a/src/main/java/net/imagej/table/CharColumn.java +++ b/src/main/java/org/scijava/table/CharColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.CharArray; diff --git a/src/main/java/net/imagej/table/CharTable.java b/src/main/java/org/scijava/table/CharTable.java similarity index 98% rename from src/main/java/net/imagej/table/CharTable.java rename to src/main/java/org/scijava/table/CharTable.java index bcb7ae2..d0aa64f 100644 --- a/src/main/java/net/imagej/table/CharTable.java +++ b/src/main/java/org/scijava/table/CharTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of {@code char} values. diff --git a/src/main/java/net/imagej/table/Column.java b/src/main/java/org/scijava/table/Column.java similarity index 98% rename from src/main/java/net/imagej/table/Column.java rename to src/main/java/org/scijava/table/Column.java index 9b97606..7c20616 100644 --- a/src/main/java/net/imagej/table/Column.java +++ b/src/main/java/org/scijava/table/Column.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import java.util.List; diff --git a/src/main/java/net/imagej/table/DefaultBoolTable.java b/src/main/java/org/scijava/table/DefaultBoolTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultBoolTable.java rename to src/main/java/org/scijava/table/DefaultBoolTable.java index 9a144ba..4d5dd5b 100644 --- a/src/main/java/net/imagej/table/DefaultBoolTable.java +++ b/src/main/java/org/scijava/table/DefaultBoolTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link BoolTable}. diff --git a/src/main/java/net/imagej/table/DefaultByteTable.java b/src/main/java/org/scijava/table/DefaultByteTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultByteTable.java rename to src/main/java/org/scijava/table/DefaultByteTable.java index 47130be..957fe51 100644 --- a/src/main/java/net/imagej/table/DefaultByteTable.java +++ b/src/main/java/org/scijava/table/DefaultByteTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link ByteTable}. diff --git a/src/main/java/net/imagej/table/DefaultCharTable.java b/src/main/java/org/scijava/table/DefaultCharTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultCharTable.java rename to src/main/java/org/scijava/table/DefaultCharTable.java index 9d44160..347a014 100644 --- a/src/main/java/net/imagej/table/DefaultCharTable.java +++ b/src/main/java/org/scijava/table/DefaultCharTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link CharTable}. diff --git a/src/main/java/net/imagej/table/DefaultColumn.java b/src/main/java/org/scijava/table/DefaultColumn.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultColumn.java rename to src/main/java/org/scijava/table/DefaultColumn.java index 8e7fdc4..7acaa1f 100644 --- a/src/main/java/net/imagej/table/DefaultColumn.java +++ b/src/main/java/org/scijava/table/DefaultColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.ObjectArray; diff --git a/src/main/java/net/imagej/table/DefaultFloatTable.java b/src/main/java/org/scijava/table/DefaultFloatTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultFloatTable.java rename to src/main/java/org/scijava/table/DefaultFloatTable.java index 33ac607..8226342 100644 --- a/src/main/java/net/imagej/table/DefaultFloatTable.java +++ b/src/main/java/org/scijava/table/DefaultFloatTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link FloatTable}. diff --git a/src/main/java/net/imagej/table/DefaultGenericTable.java b/src/main/java/org/scijava/table/DefaultGenericTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultGenericTable.java rename to src/main/java/org/scijava/table/DefaultGenericTable.java index 649c062..d59f196 100644 --- a/src/main/java/net/imagej/table/DefaultGenericTable.java +++ b/src/main/java/org/scijava/table/DefaultGenericTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link GenericTable}. diff --git a/src/main/java/net/imagej/table/DefaultIntTable.java b/src/main/java/org/scijava/table/DefaultIntTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultIntTable.java rename to src/main/java/org/scijava/table/DefaultIntTable.java index 069b3e4..42e73d7 100644 --- a/src/main/java/net/imagej/table/DefaultIntTable.java +++ b/src/main/java/org/scijava/table/DefaultIntTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link IntTable}. diff --git a/src/main/java/net/imagej/table/DefaultLongTable.java b/src/main/java/org/scijava/table/DefaultLongTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultLongTable.java rename to src/main/java/org/scijava/table/DefaultLongTable.java index 226efbb..aae584c 100644 --- a/src/main/java/net/imagej/table/DefaultLongTable.java +++ b/src/main/java/org/scijava/table/DefaultLongTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link LongTable}. diff --git a/src/main/java/net/imagej/table/DefaultShortTable.java b/src/main/java/org/scijava/table/DefaultShortTable.java similarity index 98% rename from src/main/java/net/imagej/table/DefaultShortTable.java rename to src/main/java/org/scijava/table/DefaultShortTable.java index 59a66bd..605ce4a 100644 --- a/src/main/java/net/imagej/table/DefaultShortTable.java +++ b/src/main/java/org/scijava/table/DefaultShortTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * Default implementation of {@link ShortTable}. diff --git a/src/main/java/net/imagej/table/DoubleColumn.java b/src/main/java/org/scijava/table/DoubleColumn.java similarity index 98% rename from src/main/java/net/imagej/table/DoubleColumn.java rename to src/main/java/org/scijava/table/DoubleColumn.java index 27cfa7b..0740129 100644 --- a/src/main/java/net/imagej/table/DoubleColumn.java +++ b/src/main/java/org/scijava/table/DoubleColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.DoubleArray; diff --git a/src/main/java/net/imagej/table/FloatColumn.java b/src/main/java/org/scijava/table/FloatColumn.java similarity index 98% rename from src/main/java/net/imagej/table/FloatColumn.java rename to src/main/java/org/scijava/table/FloatColumn.java index 0b8caaa..9665635 100644 --- a/src/main/java/net/imagej/table/FloatColumn.java +++ b/src/main/java/org/scijava/table/FloatColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.FloatArray; diff --git a/src/main/java/net/imagej/table/FloatTable.java b/src/main/java/org/scijava/table/FloatTable.java similarity index 98% rename from src/main/java/net/imagej/table/FloatTable.java rename to src/main/java/org/scijava/table/FloatTable.java index 07a5f2b..ef10a82 100644 --- a/src/main/java/net/imagej/table/FloatTable.java +++ b/src/main/java/org/scijava/table/FloatTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of float-precision floating point values. diff --git a/src/main/java/net/imagej/table/GenericColumn.java b/src/main/java/org/scijava/table/GenericColumn.java similarity index 98% rename from src/main/java/net/imagej/table/GenericColumn.java rename to src/main/java/org/scijava/table/GenericColumn.java index a6fe4a9..87f3837 100644 --- a/src/main/java/net/imagej/table/GenericColumn.java +++ b/src/main/java/org/scijava/table/GenericColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A column that can consist of any {@link Object}s. diff --git a/src/main/java/net/imagej/table/GenericTable.java b/src/main/java/org/scijava/table/GenericTable.java similarity index 98% rename from src/main/java/net/imagej/table/GenericTable.java rename to src/main/java/org/scijava/table/GenericTable.java index c36305e..7e57b6f 100644 --- a/src/main/java/net/imagej/table/GenericTable.java +++ b/src/main/java/org/scijava/table/GenericTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A flexible table capable of storing any values as {@link Object}s. diff --git a/src/main/java/net/imagej/table/IntColumn.java b/src/main/java/org/scijava/table/IntColumn.java similarity index 98% rename from src/main/java/net/imagej/table/IntColumn.java rename to src/main/java/org/scijava/table/IntColumn.java index 8c1f0f2..2cab406 100644 --- a/src/main/java/net/imagej/table/IntColumn.java +++ b/src/main/java/org/scijava/table/IntColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.IntArray; diff --git a/src/main/java/net/imagej/table/IntTable.java b/src/main/java/org/scijava/table/IntTable.java similarity index 98% rename from src/main/java/net/imagej/table/IntTable.java rename to src/main/java/org/scijava/table/IntTable.java index 8141f01..8c55a28 100644 --- a/src/main/java/net/imagej/table/IntTable.java +++ b/src/main/java/org/scijava/table/IntTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of int-precision integer values. diff --git a/src/main/java/net/imagej/table/LongColumn.java b/src/main/java/org/scijava/table/LongColumn.java similarity index 98% rename from src/main/java/net/imagej/table/LongColumn.java rename to src/main/java/org/scijava/table/LongColumn.java index 680a0c7..d118ee5 100644 --- a/src/main/java/net/imagej/table/LongColumn.java +++ b/src/main/java/org/scijava/table/LongColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.LongArray; diff --git a/src/main/java/net/imagej/table/LongTable.java b/src/main/java/org/scijava/table/LongTable.java similarity index 98% rename from src/main/java/net/imagej/table/LongTable.java rename to src/main/java/org/scijava/table/LongTable.java index b6e4d8c..33e2538 100644 --- a/src/main/java/net/imagej/table/LongTable.java +++ b/src/main/java/org/scijava/table/LongTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of long-precision integer values. diff --git a/src/main/java/net/imagej/table/PrimitiveColumn.java b/src/main/java/org/scijava/table/PrimitiveColumn.java similarity index 98% rename from src/main/java/net/imagej/table/PrimitiveColumn.java rename to src/main/java/org/scijava/table/PrimitiveColumn.java index 51ae021..fdcb643 100644 --- a/src/main/java/net/imagej/table/PrimitiveColumn.java +++ b/src/main/java/org/scijava/table/PrimitiveColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.PrimitiveArray; diff --git a/src/main/java/net/imagej/table/ShortColumn.java b/src/main/java/org/scijava/table/ShortColumn.java similarity index 98% rename from src/main/java/net/imagej/table/ShortColumn.java rename to src/main/java/org/scijava/table/ShortColumn.java index f31d155..de9275e 100644 --- a/src/main/java/net/imagej/table/ShortColumn.java +++ b/src/main/java/org/scijava/table/ShortColumn.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.util.ShortArray; diff --git a/src/main/java/net/imagej/table/ShortTable.java b/src/main/java/org/scijava/table/ShortTable.java similarity index 98% rename from src/main/java/net/imagej/table/ShortTable.java rename to src/main/java/org/scijava/table/ShortTable.java index 380d646..9be554d 100644 --- a/src/main/java/net/imagej/table/ShortTable.java +++ b/src/main/java/org/scijava/table/ShortTable.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; /** * A table of short-precision integer values. diff --git a/src/main/java/net/imagej/table/Table.java b/src/main/java/org/scijava/table/Table.java similarity index 99% rename from src/main/java/net/imagej/table/Table.java rename to src/main/java/org/scijava/table/Table.java index cbbf136..59c4aa0 100644 --- a/src/main/java/net/imagej/table/Table.java +++ b/src/main/java/org/scijava/table/Table.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import java.util.Collection; import java.util.Iterator; diff --git a/src/main/java/net/imagej/table/TableDisplay.java b/src/main/java/org/scijava/table/TableDisplay.java similarity index 98% rename from src/main/java/net/imagej/table/TableDisplay.java rename to src/main/java/org/scijava/table/TableDisplay.java index 09e9fcd..fed40f1 100644 --- a/src/main/java/net/imagej/table/TableDisplay.java +++ b/src/main/java/org/scijava/table/TableDisplay.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import org.scijava.display.Display; diff --git a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java b/src/main/java/org/scijava/table/process/ResultsPostprocessor.java similarity index 96% rename from src/main/java/net/imagej/table/process/ResultsPostprocessor.java rename to src/main/java/org/scijava/table/process/ResultsPostprocessor.java index 6d8fcd0..efec9d4 100644 --- a/src/main/java/net/imagej/table/process/ResultsPostprocessor.java +++ b/src/main/java/org/scijava/table/process/ResultsPostprocessor.java @@ -29,14 +29,10 @@ * #L% */ -package net.imagej.table.process; +package org.scijava.table.process; import java.util.ArrayList; -import net.imagej.table.DefaultColumn; -import net.imagej.table.DefaultGenericTable; -import net.imagej.table.GenericTable; - import org.scijava.Priority; import org.scijava.module.Module; import org.scijava.module.ModuleItem; @@ -44,6 +40,9 @@ import org.scijava.module.process.PostprocessorPlugin; import org.scijava.plugin.Parameter; import org.scijava.plugin.Plugin; +import org.scijava.table.DefaultColumn; +import org.scijava.table.DefaultGenericTable; +import org.scijava.table.GenericTable; import org.scijava.ui.UIService; import org.scijava.util.ClassUtils; diff --git a/src/test/java/net/imagej/table/DefaultBoolTableTest.java b/src/test/java/org/scijava/table/DefaultBoolTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultBoolTableTest.java rename to src/test/java/org/scijava/table/DefaultBoolTableTest.java index 919cfa7..24d5eb3 100644 --- a/src/test/java/net/imagej/table/DefaultBoolTableTest.java +++ b/src/test/java/org/scijava/table/DefaultBoolTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultByteTableTest.java b/src/test/java/org/scijava/table/DefaultByteTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultByteTableTest.java rename to src/test/java/org/scijava/table/DefaultByteTableTest.java index 1c35690..ea843c7 100644 --- a/src/test/java/net/imagej/table/DefaultByteTableTest.java +++ b/src/test/java/org/scijava/table/DefaultByteTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultCharTableTest.java b/src/test/java/org/scijava/table/DefaultCharTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultCharTableTest.java rename to src/test/java/org/scijava/table/DefaultCharTableTest.java index 11d7add..d3d3ef9 100644 --- a/src/test/java/net/imagej/table/DefaultCharTableTest.java +++ b/src/test/java/org/scijava/table/DefaultCharTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultFloatTableTest.java b/src/test/java/org/scijava/table/DefaultFloatTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultFloatTableTest.java rename to src/test/java/org/scijava/table/DefaultFloatTableTest.java index 3cb7ee0..5ffd968 100644 --- a/src/test/java/net/imagej/table/DefaultFloatTableTest.java +++ b/src/test/java/org/scijava/table/DefaultFloatTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultGenericTableTest.java b/src/test/java/org/scijava/table/DefaultGenericTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultGenericTableTest.java rename to src/test/java/org/scijava/table/DefaultGenericTableTest.java index fffa075..1852d1f 100644 --- a/src/test/java/net/imagej/table/DefaultGenericTableTest.java +++ b/src/test/java/org/scijava/table/DefaultGenericTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/net/imagej/table/DefaultIntTableTest.java b/src/test/java/org/scijava/table/DefaultIntTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultIntTableTest.java rename to src/test/java/org/scijava/table/DefaultIntTableTest.java index 8f7cb24..c7be403 100644 --- a/src/test/java/net/imagej/table/DefaultIntTableTest.java +++ b/src/test/java/org/scijava/table/DefaultIntTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultLongTableTest.java b/src/test/java/org/scijava/table/DefaultLongTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultLongTableTest.java rename to src/test/java/org/scijava/table/DefaultLongTableTest.java index 5ae87c1..705958a 100644 --- a/src/test/java/net/imagej/table/DefaultLongTableTest.java +++ b/src/test/java/org/scijava/table/DefaultLongTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; diff --git a/src/test/java/net/imagej/table/DefaultShortTableTest.java b/src/test/java/org/scijava/table/DefaultShortTableTest.java similarity index 99% rename from src/test/java/net/imagej/table/DefaultShortTableTest.java rename to src/test/java/org/scijava/table/DefaultShortTableTest.java index e5af4aa..af93fb5 100644 --- a/src/test/java/net/imagej/table/DefaultShortTableTest.java +++ b/src/test/java/org/scijava/table/DefaultShortTableTest.java @@ -29,7 +29,7 @@ * #L% */ -package net.imagej.table; +package org.scijava.table; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; From 0f80ce4fa06187bdc70721565ed72b79b7970f94 Mon Sep 17 00:00:00 2001 From: Jan Eglinger Date: Tue, 17 Jul 2018 14:13:26 +0200 Subject: [PATCH 42/42] Replace usage of deprecated ClassUtils methods --- .../scijava/table/process/ResultsPostprocessor.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/scijava/table/process/ResultsPostprocessor.java b/src/main/java/org/scijava/table/process/ResultsPostprocessor.java index efec9d4..5987657 100644 --- a/src/main/java/org/scijava/table/process/ResultsPostprocessor.java +++ b/src/main/java/org/scijava/table/process/ResultsPostprocessor.java @@ -44,7 +44,7 @@ import org.scijava.table.DefaultGenericTable; import org.scijava.table.GenericTable; import org.scijava.ui.UIService; -import org.scijava.util.ClassUtils; +import org.scijava.util.Types; /** * A postprocessor which aggregates simple output values into a single table, @@ -53,7 +53,7 @@ * @author Curtis Rueden */ @Plugin(type = PostprocessorPlugin.class, - priority = Priority.VERY_LOW_PRIORITY + 1) + priority = Priority.VERY_LOW + 1) public class ResultsPostprocessor extends AbstractPostprocessorPlugin { @Parameter(required = false) @@ -79,7 +79,7 @@ public void process(final Module module) { }); if (outputs.isEmpty()) return; // no compatible outputs - if (outputs.size() == 1 && ClassUtils.isText(outputs.get(0).getType())) { + if (outputs.size() == 1 && Types.isText(outputs.get(0).getType())) { // sole compatible output is a string; let the TextDisplay handle it return; } @@ -117,9 +117,9 @@ private boolean isSimple(final Module m, final ModuleItem item) { } private boolean isSimpleType(final Class type) { - return ClassUtils.isText(type) || // - ClassUtils.isNumber(type) || // - ClassUtils.isBoolean(type); + return Types.isText(type) || // + Types.isNumber(type) || // + Types.isBoolean(type); } private boolean isSimpleValue(final Object o) {