Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/main/java/org/scijava/table/DefaultDoubleTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* #%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 org.scijava.table;

/**
* Default implementation of {@link DoubleTable}.
*
* @author Jan Eglinger
*/
public class DefaultDoubleTable extends AbstractTable<DoubleColumn, Double>
implements DoubleTable
{

/** Creates an empty results table. */
public DefaultDoubleTable() {
super();
}

/** Creates a results table with the given row and column dimensions. */
public DefaultDoubleTable(final int columnCount, final int rowCount) {
super(columnCount, rowCount);
}

// -- Internal methods --

@Override
protected DoubleColumn createColumn(final String header) {
return new DoubleColumn(header);
}

}
124 changes: 124 additions & 0 deletions src/main/java/org/scijava/table/DefaultTableDisplay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* #%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 org.scijava.table;

import org.scijava.display.AbstractDisplay;
import org.scijava.display.Display;
import org.scijava.plugin.Plugin;

/**
* Default display for {@link Table}s, including {@link DoubleTable}s.
*
* @author Curtis Rueden
*/
@Plugin(type = Display.class)
public class DefaultTableDisplay extends AbstractDisplay<Table<?, ?>> 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 GenericTable wrapArrayAsTable(final double[][] array) {
final GenericTable table = new DefaultGenericTable();
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 DoubleTable)) continue;
final DoubleTable resultsTable = (DoubleTable) 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;
}

}
51 changes: 51 additions & 0 deletions src/main/java/org/scijava/table/DoubleTable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* #%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 org.scijava.table;

/**
* A table of double-precision floating point values.
*
* @author Jan Eglinger
*/
public interface DoubleTable extends Table<DoubleColumn, Double> {

/** 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);
}

}
Loading