Skip to content

Commit 7d670c7

Browse files
authored
Merge pull request #17 from scijava/use-location
2 parents 57e5472 + e45f633 commit 7d670c7

File tree

7 files changed

+57
-57
lines changed

7 files changed

+57
-57
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Wisconsin-Madison, and Friedrich Miescher Institute for Biomedical Research.</li
102102

103103
<!-- NB: Deploy releases to the SciJava Maven repository. -->
104104
<releaseProfiles>deploy-to-scijava</releaseProfiles>
105+
<scijava-common.version>2.84.0</scijava-common.version>
105106
</properties>
106107

107108
<dependencies>

src/main/java/org/scijava/table/io/ColumnTableIOOptions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ ColumnTableIOOptions formatter(Function<Object, String> formatter) {
4747
return setValue(formatterKey, formatter);
4848
}
4949

50-
ColumnTableIOOptions parser(Function<String, Object> parser) {
50+
ColumnTableIOOptions parser(Function<String, ?> parser) {
5151
return setValue(parserKey, parser);
5252
}
5353

@@ -57,7 +57,7 @@ public Function<Object, String> formatter() {
5757
return getValueOrDefault(formatterKey, String::valueOf);
5858
}
5959

60-
public Function<String, Object> parser() {
60+
public Function<String, ?> parser() {
6161
return getValueOrDefault(parserKey, String::valueOf);
6262
}
6363
}

src/main/java/org/scijava/table/io/DefaultTableIOService.java

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,41 @@
3131
package org.scijava.table.io;
3232

3333
import java.io.IOException;
34+
import java.net.URISyntaxException;
3435

36+
import org.scijava.io.AbstractTypedIOService;
3537
import org.scijava.io.IOPlugin;
3638
import org.scijava.io.IOService;
39+
import org.scijava.io.location.Location;
3740
import org.scijava.plugin.Parameter;
3841
import org.scijava.plugin.Plugin;
39-
import org.scijava.service.AbstractService;
4042
import org.scijava.service.Service;
4143
import org.scijava.table.Table;
4244

4345
@Plugin(type = Service.class)
44-
public class DefaultTableIOService extends AbstractService implements
46+
public class DefaultTableIOService extends AbstractTypedIOService<Table<?, ?>> implements
4547
TableIOService
4648
{
4749

48-
@Parameter
49-
private IOService ioService;
50-
5150
@Override
52-
public boolean canOpen(String source) {
53-
IOPlugin<?> opener = ioService.getOpener(source);
51+
public boolean canOpen(Location source) {
52+
IOPlugin<?> opener = ioService().getOpener(source);
5453
if (opener == null) return false;
5554
return Table.class.isAssignableFrom(opener.getDataType());
5655
}
5756

5857
@Override
59-
public boolean canSave(Table<?, ?> table, String destination) {
60-
IOPlugin<Table<?, ?>> saver = ioService.getSaver(table, destination);
61-
if (saver == null) return false;
62-
return saver.supportsSave(destination);
63-
}
64-
65-
@Override
66-
public Table<?, ?> open(String source) throws IOException {
67-
IOPlugin<?> opener = ioService.getOpener(source);
68-
if (opener != null && Table.class.isAssignableFrom(opener.getDataType())) {
69-
return (Table<?, ?>) opener.open(source);
58+
public Table<?, ?> open(String source, TableIOOptions options) throws IOException {
59+
try {
60+
return open(locationService().resolve(source), options);
61+
} catch (URISyntaxException e) {
62+
throw new IOException(e);
7063
}
71-
throw new UnsupportedOperationException("No compatible opener found.");
7264
}
7365

7466
@Override
75-
public Table<?, ?> open(String source, TableIOOptions options) throws IOException {
76-
IOPlugin<?> opener = ioService.getOpener(source);
67+
public Table<?, ?> open(Location source, TableIOOptions options) throws IOException {
68+
IOPlugin<?> opener = ioService().getOpener(source);
7769
if (opener != null && Table.class.isAssignableFrom(opener.getDataType())
7870
&& TableIOPlugin.class.isAssignableFrom(opener.getClass())) {
7971
return ((TableIOPlugin)opener).open(source, options);
@@ -82,24 +74,23 @@ public boolean canSave(Table<?, ?> table, String destination) {
8274
}
8375

8476
@Override
85-
public void save(Table<?, ?> table, String destination) throws IOException {
86-
IOPlugin<Table<?, ?>> saver = ioService.getSaver(table, destination);
87-
if (saver != null) {
88-
saver.save(table, destination);
89-
}
90-
else {
91-
throw new UnsupportedOperationException("No compatible saver found.");
77+
public void save(Table<?, ?> table, String destination, TableIOOptions options) throws IOException {
78+
try {
79+
save(table, locationService().resolve(destination), options);
80+
} catch (URISyntaxException e) {
81+
throw new IOException(e);
9282
}
9383
}
9484

9585
@Override
96-
public void save(Table<?, ?> table, String destination, TableIOOptions options) throws IOException {
97-
IOPlugin<Table> saver = ioService.getSaver(table, destination);
86+
public void save(Table<?, ?> table, Location destination, TableIOOptions options) throws IOException {
87+
IOPlugin<Table> saver = ioService().getSaver(table, destination);
9888
if (saver != null && TableIOPlugin.class.isAssignableFrom(saver.getClass())) {
9989
((TableIOPlugin)saver).save(table, destination, options);
10090
}
10191
else {
10292
throw new UnsupportedOperationException("No compatible saver found.");
10393
}
10494
}
95+
10596
}

src/main/java/org/scijava/table/io/TableIOOptions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public TableIOOptions guessParser(boolean guessParser) {
135135
/**
136136
* @param parser Parser to use when converting table entries into data objects.
137137
*/
138-
public TableIOOptions parser(Function<String, Object> parser) {
138+
public TableIOOptions parser(Function<String, ?> parser) {
139139
guessParser(false);
140140
return setValue(parserKey, parser);
141141
}
@@ -188,7 +188,7 @@ public TableIOOptions columnFormatter(int column, Function<Object, String> forma
188188
return this;
189189
}
190190

191-
private Function<String, Object> getParser(Class<?> type) {
191+
private Function<String, ?> getParser(Class<?> type) {
192192
if(type.equals(String.class)) return String::valueOf;
193193
if(type.equals(Double.class)) return Double::valueOf;
194194
if(type.equals(Float.class)) return Float::valueOf;
@@ -266,7 +266,7 @@ public boolean guessParser() {
266266
/**
267267
* @return Parser to use when converting table entries into data objects.
268268
*/
269-
public Function<String, Object> parser() {
269+
public Function<String, ?> parser() {
270270
return getValueOrDefault(parserKey, String::valueOf);
271271
}
272272

src/main/java/org/scijava/table/io/TableIOPlugin.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
package org.scijava.table.io;
3232

33-
import org.scijava.io.AbstractIOPlugin;
33+
import org.scijava.io.IOPlugin;
34+
import org.scijava.io.location.Location;
3435
import org.scijava.table.Table;
3536

3637
import java.io.IOException;
@@ -40,32 +41,30 @@
4041
*
4142
* @author Deborah Schmidt
4243
*/
43-
public class TableIOPlugin extends AbstractIOPlugin<Table> {
44+
public interface TableIOPlugin extends IOPlugin<Table> {
4445

4546
@Override
46-
public Table<?, ?> open(String source) throws IOException {
47+
default Table<?, ?> open(Location source) throws IOException {
4748
return open(source, new TableIOOptions());
4849
}
4950

5051
/** Opens data from the given source. */
51-
@SuppressWarnings("unused")
52-
public Table<?, ?> open(final String source, final TableIOOptions options) throws IOException {
52+
default Table<?, ?> open(final Location source, final TableIOOptions options) throws IOException {
5353
throw new UnsupportedOperationException();
5454
}
5555

5656
@Override
57-
public void save(Table data, String destination) throws IOException {
57+
default void save(Table data, Location destination) throws IOException {
5858
save(data, destination, new TableIOOptions());
5959
}
6060

6161
/** Saves the given data to the specified destination. */
62-
@SuppressWarnings("unused")
63-
public void save(final Table<?, ?> data, final String destination, final TableIOOptions options) throws IOException {
62+
default void save(final Table<?, ?> data, final Location destination, final TableIOOptions options) throws IOException {
6463
throw new UnsupportedOperationException();
6564
}
6665

6766
@Override
68-
public Class<Table> getDataType() {
67+
default Class<Table> getDataType() {
6968
return Table.class;
7069
}
7170
}

src/main/java/org/scijava/table/io/TableIOService.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,25 @@
3232

3333
import java.io.IOException;
3434

35+
import org.scijava.io.IOService;
36+
import org.scijava.io.TypedIOService;
37+
import org.scijava.io.location.Location;
3538
import org.scijava.service.SciJavaService;
3639
import org.scijava.table.Table;
3740

38-
public interface TableIOService extends SciJavaService {
41+
public interface TableIOService extends TypedIOService<Table<?, ?>> {
3942

40-
boolean canOpen(String source);
41-
42-
boolean canSave(Table<?, ?> table, String destination);
43-
44-
Table<?, ?> open(String source) throws IOException;
43+
@Override
44+
default Table<?, ?> open(Location source) throws IOException {
45+
return open(source, TableIOOptions.options());
46+
}
4547
Table<?, ?> open(String source, TableIOOptions options) throws IOException;
48+
Table<?, ?> open(Location source, TableIOOptions options) throws IOException;
4649

47-
void save(Table<?, ?> table, String destination) throws IOException;
50+
@Override
51+
default void save(Table<?, ?> table, Location destination) throws IOException {
52+
save(table, destination, TableIOOptions.options());
53+
}
4854
void save(Table<?, ?> table, String destination, TableIOOptions options) throws IOException;
55+
void save(Table<?, ?> table, Location destination, TableIOOptions options) throws IOException;
4956
}

src/test/java/org/scijava/table/io/TableIOServiceTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
import org.junit.Before;
3535
import org.junit.Test;
3636
import org.scijava.Context;
37+
import org.scijava.io.AbstractIOPlugin;
3738
import org.scijava.io.IOPlugin;
39+
import org.scijava.io.location.Location;
3840
import org.scijava.plugin.PluginInfo;
3941
import org.scijava.plugin.PluginService;
4042
import org.scijava.table.DefaultGenericTable;
@@ -107,24 +109,24 @@ public void testTableIOServiceWithOptions() {
107109
}
108110

109111
@SuppressWarnings("rawtypes")
110-
public static class FakeTableIOPlugin extends TableIOPlugin {
112+
public static class FakeTableIOPlugin extends AbstractIOPlugin<Table> implements TableIOPlugin {
111113

112114
@Override
113-
public boolean supportsOpen(String loc) {
114-
return loc.endsWith("fakeTable");
115+
public boolean supportsOpen(Location loc) {
116+
return loc.getName().endsWith("fakeTable");
115117
}
116118

117119
@Override
118-
public boolean supportsSave(String loc) {
119-
return loc.endsWith("fakeTable");
120+
public boolean supportsSave(Location loc) {
121+
return loc.getName().endsWith("fakeTable");
120122
}
121123

122124
/**
123125
* This method creates a fake table for the purpose of testing the propagation of options.
124126
* It creates a row and a column with header names based on the {@param options}.
125127
*/
126128
@Override
127-
public Table open(String loc, TableIOOptions options) {
129+
public Table open(Location loc, TableIOOptions options) {
128130
DefaultGenericTable table = new DefaultGenericTable();
129131
if(options.values.readColumnHeaders()) {
130132
table.appendColumn(String.valueOf(options.values.columnDelimiter()));

0 commit comments

Comments
 (0)