Description
Most popular situations, when we need DataHandle, are processing files and byte arrays, implemented in the classes FileHandle and BytesHandle. Unfortunately, the only correct way to create the necessary objects is using SciHava context technique:
context.getService(DataHandleService.class).create(location)
But initializing context sub-system requires time and special code. I would be very desirable to avoid Context class in these very simple situation.
I've found necessary solution as a pair of simple functions:
@SuppressWarnings("rawtypes, unchecked")
public static DataHandle<Location> getFileHandle(FileLocation fileLocation) {
Objects.requireNonNull(fileLocation, "Null fileLocation");
FileHandle fileHandle = new FileHandle();
fileHandle.set(fileLocation);
return (DataHandle) fileHandle;
}
@SuppressWarnings("rawtypes, unchecked")
public static DataHandle<Location> getBytesHandle(BytesLocation bytesLocation) {
Objects.requireNonNull(bytesLocation, "Null bytesLocation");
BytesHandle bytesHandle = new BytesHandle();
bytesHandle.set(bytesLocation);
return (DataHandle) bytesHandle;
}
Could you provide such convenient methods inside FileLocation/ByteLocation classes?
Besides, you see that it turned out to be necessary to use @SupressWarning to make necessary DataHandle<Location>
. Maybe you should rework generics in your module to provide ability to return DataHandle<Location>
without compiler warnings? Or, at least, please make the methods getFileHandle/getBytesHandle with @SupressWarning a part of your own classes, to avoid your users to write unsafe code.
It is a duplicate of the issue scifio/scifio#508 - it seems here is more suitable place. So you may close that issue in SCIFIO project.