diff --git a/src/main/java/fr/igred/omero/annotations/TableWrapper.java b/src/main/java/fr/igred/omero/annotations/TableWrapper.java index a445f64b..2526262c 100644 --- a/src/main/java/fr/igred/omero/annotations/TableWrapper.java +++ b/src/main/java/fr/igred/omero/annotations/TableWrapper.java @@ -43,6 +43,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; @@ -394,18 +395,18 @@ private static ROIData[] createROIColumn(ResultsTable results, safeParseLong(r.getProperty(roiIdProperty)))) .filter(p -> p.getKey() != null) .filter(p -> p.getValue() != null) - .collect(toMap(SimpleEntry::getKey, - p -> id2roi.get(p.getValue()), - (x1, x2) -> x1)); + .collect(HashMap::new, + (m, v) -> m.put(v.getKey(), id2roi.get(v.getValue())), + HashMap::putAll); Map shape2roi = ijRois.stream() .map(r -> new SimpleEntry<>(r.getName(), safeParseLong(r.getProperty(roiIdProperty)))) .filter(p -> p.getKey() != null) .filter(p -> p.getValue() != null) - .collect(toMap(SimpleEntry::getKey, - p -> id2roi.get(p.getValue()), - (x1, x2) -> x1)); + .collect(HashMap::new, + (m, v) -> m.put(v.getKey(), id2roi.get(v.getValue())), + HashMap::putAll); String colToDelete = ""; if (results.columnExists(roiIdProperty)) { Variable[] roiCol = results.getColumnAsVariables(roiIdProperty); @@ -440,6 +441,20 @@ private static ROIData[] createROIColumn(ResultsTable results, } + /** + * Checks if the new columns match the existing ones. + * + * @param nColumns The number of columns in the current Results Table. + * @param offset The offset in the current Results Table. + */ + private boolean checkColumns(int nColumns, int offset) { + boolean match = offset + nColumns == columnCount; + if (offset > 0 && !columns[0].getType().equals(ImageData.class)) match = false; + if (offset > 1 && !columns[1].getType().equals(ROIData.class)) match = false; + return match; + } + + /** * Sets the information about a given column. * @@ -522,8 +537,8 @@ public void addRows(Client client, ResultsTable results, Long imageId, List rois = new ArrayList<>(2); + rois.add(new ROIWrapper()); + rois.add(new ROIWrapper()); + + rois.get(0).setImage(image); + rois.get(1).setImage(image); + + for (int i = 0; i < 4; i++) { + RectangleWrapper rectangle = new RectangleWrapper(); + rectangle.setText(String.valueOf(10 + i % 2)); + rectangle.setCoordinates(i * 2, i * 2, 10, 10); + rectangle.setZ(i); + rectangle.setT(0); + rectangle.setC(0); + + if (i % 2 == 1) rois.get(0).addShape(rectangle); + else rois.get(1).addShape(rectangle); + } + + List newROIs = image.saveROIs(client, rois); + List ijRois = ROIWrapper.toImageJ(newROIs); + + String label1 = image.getName() + ":" + newROIs.get(0).getShapes().get(0).getText() + ":4"; + String label2 = image.getName() + ":" + newROIs.get(1).getShapes().get(0).getText() + ":10"; + + ResultsTable results1 = createOneRowResultsTable(label1, volume1, unit1); + ResultsTable results2 = createOneRowResultsTable(label2, volume2, unit2); + + TableWrapper table = new TableWrapper(client, results1, IMAGE1.id, ijRois); + + assertThrows(IllegalArgumentException.class, + () -> table.addRows(client, results2, null, ijRois)); + } + } \ No newline at end of file