Search in sources :

Example 1 with DefaultColumn

use of net.imagej.table.DefaultColumn in project imagej-omero by imagej.

the class UploadTableTest method testByteArrayTable.

@Test
public void testByteArrayTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final GenericTable table = new DefaultGenericTable();
    final DefaultColumn<ByteArray> ij0 = new DefaultColumn<>(ByteArray.class);
    final DefaultColumn<ByteArray> ij1 = new DefaultColumn<>(ByteArray.class);
    ij0.add(new ByteArray(new byte[] { -128, 127 }));
    ij0.add(new ByteArray(new byte[] { 0, 10 }));
    ij1.add(new ByteArray(new byte[] { 112, 42 }));
    ij1.add(new ByteArray(new byte[] { -13, -84 }));
    table.add(ij0);
    table.add(ij1);
    // Create expectations
    setUpMethodCalls();
    final long id = service.uploadTable(credentials, "table", table, 0);
    assertEquals(id, -1);
    // NB: Can only capture in a Verifications block
    new Verifications() {

        {
            TableData td;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
            tableEquals(table, td, Long[].class);
        }
    };
}
Also used : DefaultGenericTable(net.imagej.table.DefaultGenericTable) DefaultColumn(net.imagej.table.DefaultColumn) GenericTable(net.imagej.table.GenericTable) DefaultGenericTable(net.imagej.table.DefaultGenericTable) ByteArray(org.scijava.util.ByteArray) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Example 2 with DefaultColumn

use of net.imagej.table.DefaultColumn in project imagej-omero by imagej.

the class DownloadTableTest method downloadMixedTable.

@Test
@SuppressWarnings("unchecked")
public void downloadMixedTable() throws PermissionDeniedException, CannotCreateSessionException, ServerError, DSOutOfServiceException, ExecutionException, DSAccessException {
    // / Setup OMERO data structures
    final TableDataColumn[] tdc = new TableDataColumn[] { new TableDataColumn("Header 1", 0, String.class), new TableDataColumn("Header 2", 1, Boolean.class), new TableDataColumn("Header 3", 2, Double[].class), new TableDataColumn("Header 4", 3, Long.class) };
    final Object[][] data = new Object[4][];
    data[0] = new String[] { "abc", "123", "hi!" };
    data[1] = new Boolean[] { false, true, false };
    data[2] = new Double[][] { { 0.125, 3879123.5, -93.25 }, { 0d, -123353.03125, -5.5 }, { 100.25, 0.125, -9000.5 } };
    data[3] = new Long[] { -9028131908l, 0l, 12l };
    final TableData table = new TableData(tdc, data);
    table.setNumberOfRows(3);
    // Create expectations
    setUpMethodCalls(table);
    final Table<?, ?> imageJTable = ((DefaultOMEROService) service).downloadTable(credentials, 0);
    // Tests
    assertTrue(GenericTable.class.isInstance(imageJTable));
    assertTrue(DefaultColumn.class.isInstance(imageJTable.get(0)));
    assertTrue(imageJTable.get(0).getType() == String.class);
    assertTrue(BoolColumn.class.isInstance(imageJTable.get(1)));
    assertTrue(DefaultColumn.class.isInstance(imageJTable.get(2)));
    assertTrue(imageJTable.get(2).getType() == DoubleArray.class);
    assertTrue(LongColumn.class.isInstance(imageJTable.get(3)));
    assertEquals(imageJTable.getColumnCount(), 4);
    assertEquals(imageJTable.getRowCount(), 3);
    assertEquals(imageJTable.getColumnHeader(0), "Header 1");
    assertEquals(imageJTable.getColumnHeader(1), "Header 2");
    assertEquals(imageJTable.getColumnHeader(2), "Header 3");
    assertEquals(imageJTable.getColumnHeader(3), "Header 4");
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[0][r], ((DefaultColumn<String>) imageJTable.get(0)).get(r));
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[1][r], ((BoolColumn) imageJTable.get(1)).getValue(r));
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertArrayEquals((Double[]) data[2][r], ((DefaultColumn<DoubleArray>) imageJTable.get(2)).get(r).toArray());
    for (int r = 0; r < imageJTable.getRowCount(); r++) assertEquals(data[3][r], ((LongColumn) imageJTable.get(3)).getValue(r));
}
Also used : BoolColumn(net.imagej.table.BoolColumn) DefaultColumn(net.imagej.table.DefaultColumn) GenericTable(net.imagej.table.GenericTable) LongColumn(net.imagej.table.LongColumn) TableDataColumn(omero.gateway.model.TableDataColumn) TableData(omero.gateway.model.TableData) DoubleArray(org.scijava.util.DoubleArray) Test(org.junit.Test)

Example 3 with DefaultColumn

use of net.imagej.table.DefaultColumn in project imagej-omero by imagej.

the class TableUtils method populateArrayColumn.

// -- Helper methods --
@SuppressWarnings("unchecked")
private static void populateArrayColumn(final DefaultColumn<?> col, final Object[] data) {
    if (col.getType().equals(FloatArray.class)) {
        for (int i = 0; i < data.length; i++) {
            final Float[] f = (Float[]) data[i];
            ((DefaultColumn<FloatArray>) col).add(i, new FloatArray(ArrayUtils.toPrimitive(f)));
        }
    } else if (col.getType().equals(LongArray.class)) {
        for (int i = 0; i < data.length; i++) {
            final Long[] f = (Long[]) data[i];
            ((DefaultColumn<LongArray>) col).add(i, new LongArray(ArrayUtils.toPrimitive(f)));
        }
    } else if (col.getType().equals(DoubleArray.class)) {
        for (int i = 0; i < data.length; i++) {
            final Double[] f = (Double[]) data[i];
            ((DefaultColumn<DoubleArray>) col).add(i, new DoubleArray(ArrayUtils.toPrimitive(f)));
        }
    }
}
Also used : LongArray(org.scijava.util.LongArray) FloatArray(org.scijava.util.FloatArray) DefaultColumn(net.imagej.table.DefaultColumn) DoubleArray(org.scijava.util.DoubleArray)

Example 4 with DefaultColumn

use of net.imagej.table.DefaultColumn in project imagej-omero by imagej.

the class UploadTableTest method testDoubleArrayTable.

@Test
public void testDoubleArrayTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final GenericTable table = new DefaultGenericTable();
    final DefaultColumn<DoubleArray> ij0 = new DefaultColumn<>(DoubleArray.class, "H1");
    final DefaultColumn<DoubleArray> ij1 = new DefaultColumn<>(DoubleArray.class, "H2");
    ij0.add(new DoubleArray(new double[] { 0.5, 0.25, 0.125 }));
    ij1.add(new DoubleArray(new double[] { -0.125, -0.0625, 0.03125 }));
    table.add(ij0);
    table.add(ij1);
    // Create expectations
    setUpMethodCalls();
    final long id = service.uploadTable(credentials, "table", table, 0);
    assertEquals(id, -1);
    // NB: Can only capture in a Verifications block
    new Verifications() {

        {
            TableData td;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
            tableEquals(table, td, Double[].class);
        }
    };
}
Also used : DefaultGenericTable(net.imagej.table.DefaultGenericTable) DefaultColumn(net.imagej.table.DefaultColumn) GenericTable(net.imagej.table.GenericTable) DefaultGenericTable(net.imagej.table.DefaultGenericTable) Verifications(mockit.Verifications) TableData(omero.gateway.model.TableData) DoubleArray(org.scijava.util.DoubleArray) Test(org.junit.Test)

Example 5 with DefaultColumn

use of net.imagej.table.DefaultColumn in project imagej-omero by imagej.

the class UploadTableTest method testMixedTable.

@Test
public void testMixedTable() throws ServerError, PermissionDeniedException, CannotCreateSessionException, ExecutionException, DSOutOfServiceException, DSAccessException {
    final GenericTable table = new DefaultGenericTable();
    final BoolColumn ijc0 = new BoolColumn("h0");
    final DoubleColumn ijc1 = new DoubleColumn("h1");
    final DefaultColumn<String> ijc2 = new DefaultColumn<>(String.class, "h2");
    final DefaultColumn<IntArray> ijc3 = new DefaultColumn<>(IntArray.class, "h3");
    final OMERORefColumn ijc4 = new OMERORefColumn("h4", OMERORef.ROI);
    ijc0.fill(new boolean[] { true, false });
    ijc1.fill(new double[] { 0.03125, -2134.5 });
    ijc2.add("abc");
    ijc2.add("123");
    ijc3.add(new IntArray(new int[] { 9012, 1294 }));
    ijc3.add(new IntArray(new int[] { -4123, -9 }));
    ijc4.fill(new long[] { 2314, 1234 });
    ijc4.setOriginalData(new Object[] { new ROIData(new RoiI(2314, true)), new ROIData(new RoiI(1234, true)) });
    table.add(ijc0);
    table.add(ijc1);
    table.add(ijc2);
    table.add(ijc3);
    table.add(ijc4);
    // Create expectations
    setUpMethodCalls();
    final long id = service.uploadTable(credentials, "table", table, 0);
    assertEquals(id, -1);
    // NB: Can only capture in a Verifications block
    new Verifications() {

        {
            TableData td;
            tablesFacility.addTable((SecurityContext) any, (ImageData) any, anyString, td = withCapture());
            tableEquals(table, td, Boolean.class, Double.class, String.class, Long[].class, ROIData.class);
        }
    };
}
Also used : DefaultGenericTable(net.imagej.table.DefaultGenericTable) BoolColumn(net.imagej.table.BoolColumn) DefaultColumn(net.imagej.table.DefaultColumn) ROIData(omero.gateway.model.ROIData) GenericTable(net.imagej.table.GenericTable) DefaultGenericTable(net.imagej.table.DefaultGenericTable) Verifications(mockit.Verifications) DoubleColumn(net.imagej.table.DoubleColumn) IntArray(org.scijava.util.IntArray) RoiI(omero.model.RoiI) TableData(omero.gateway.model.TableData) Test(org.junit.Test)

Aggregations

DefaultColumn (net.imagej.table.DefaultColumn)7 GenericTable (net.imagej.table.GenericTable)6 TableData (omero.gateway.model.TableData)6 Test (org.junit.Test)6 Verifications (mockit.Verifications)3 DefaultGenericTable (net.imagej.table.DefaultGenericTable)3 TableDataColumn (omero.gateway.model.TableDataColumn)3 DoubleArray (org.scijava.util.DoubleArray)3 BoolColumn (net.imagej.table.BoolColumn)2 LongArray (org.scijava.util.LongArray)2 DoubleColumn (net.imagej.table.DoubleColumn)1 LongColumn (net.imagej.table.LongColumn)1 ROIData (omero.gateway.model.ROIData)1 RoiI (omero.model.RoiI)1 ByteArray (org.scijava.util.ByteArray)1 FloatArray (org.scijava.util.FloatArray)1 IntArray (org.scijava.util.IntArray)1