Skip to content

Commit 8e3bf8f

Browse files
awalter17imagejan
authored andcommitted
Add TableService
1 parent 28ebe30 commit 8e3bf8f

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
package net.imagej.table;
3+
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
7+
import net.imagej.Dataset;
8+
import net.imagej.ImageJService;
9+
10+
import org.scijava.service.Service;
11+
12+
/**
13+
* {@link Service} for working with {@link Table}s.
14+
*
15+
* @author Alison Walter
16+
*/
17+
public interface TableService extends ImageJService {
18+
19+
public static final String TABLE_PROPERTY = "tables";
20+
21+
/**
22+
* Retrieves the {@link Table}s attached to the given {@link Dataset}.
23+
*
24+
* @param img {@link Dataset} whose {@link Table}s are desired
25+
* @return {@link Table}s associated with {@code img}
26+
*/
27+
List<Table<?, ?>> getTables(final Dataset img);
28+
29+
/**
30+
* Attaches the given {@link Table} to the {@link Dataset}
31+
*
32+
* @param table {@link Table} to be attached
33+
* @param img {@link Dataset} to attach the table to
34+
*/
35+
@SuppressWarnings("unchecked")
36+
default void add(final Table<?, ?> table, final Dataset img) {
37+
if (img.getProperties().get(TABLE_PROPERTY) != null) {
38+
((List<Table<?, ?>>) img.getProperties().get(TABLE_PROPERTY)).add(table);
39+
}
40+
else {
41+
final List<Table<?, ?>> t = new ArrayList<>();
42+
t.add(table);
43+
img.getProperties().put(TABLE_PROPERTY, t);
44+
}
45+
}
46+
47+
/**
48+
* Clears any {@link Table}s associated with the given {@link Dataset}.
49+
*
50+
* @param img the {@link Dataset} whose attached {@link Table}s will be
51+
* cleared.
52+
*/
53+
default void clear(final Dataset img) {
54+
img.getProperties().put(TABLE_PROPERTY, null);
55+
}
56+
57+
}

0 commit comments

Comments
 (0)