io.annot8.common.data.bounds.MultiCellBounds Maven / Gradle / Ivy
Show all versions of annot8-common-data Show documentation
/* Annot8 (annot8.io) - Licensed under Apache-2.0. */
package io.annot8.common.data.bounds;
import io.annot8.api.data.Content;
import io.annot8.common.data.content.Row;
import io.annot8.common.data.content.TableContent;
import jakarta.json.bind.annotation.JsonbCreator;
import jakarta.json.bind.annotation.JsonbProperty;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
/**
* Bounds to represent multiple cells within a table row
*
* This bounds implementation will only return instances of MultiCellData with getData
*/
public class MultiCellBounds extends AbstractCellBounds {
private final int[] cells;
private final int row;
@JsonbCreator
public MultiCellBounds(@JsonbProperty("row") int row, @JsonbProperty("cells") int[] cells) {
this.row = row;
this.cells = cells;
}
public int getRow() {
return row;
}
public int[] getCells() {
return cells;
}
@Override
public , R> Optional getData(C content, Class requiredClass) {
if (requiredClass.equals(MultiCellData.class)) {
if (!isValid(content)) {
return Optional.empty();
}
TableContent tableContent = (TableContent) content;
Optional rowOptional = tableContent.getData().getRow(this.row);
if (rowOptional.isPresent()) {
Row r = rowOptional.get();
Map values = new HashMap<>();
Map headers = new HashMap<>();
for (int i : cells) {
Optional