/******************************************************************************************************************* * * Executes an operation. The original image is lost and replaced by results. * * @param operation the operation to perform * @return the operation (as a convenience in case it carries * results) * ******************************************************************************************************************/ @Nonnull public final <T extends Operation> T execute (final @Nonnull T operation) { long time = System.currentTimeMillis(); Object image = internalExecute(operation); imageModelHolder.get().setImage(image); latestOperationTime = System.currentTimeMillis() - time; return operation; }
/******************************************************************************************************************* * * Executes an operation. The original image is untouched as the results are * placed in a brand new instance of EditableImage. * * @param operation the operation to perform * @return the result * ******************************************************************************************************************/ @Nonnull public final EditableImage execute2 (final @Nonnull Operation operation) { try { long time = System.currentTimeMillis(); Object image = internalExecute(operation); Class modelClass = imageModelHolder.get().getClass(); Constructor constructor = modelClass.getConstructor(Object.class); ImageModel newModel = (ImageModel)constructor.newInstance(image); EditableImage result = new EditableImage(newModel); result.attributeMapByName = new HashMap<String, Object>(attributeMapByName); result.latestOperationTime = System.currentTimeMillis() - time; return result; } catch (Exception e) { throw new RuntimeException(e); } }
/******************************************************************************************************************* * * Creates a new EditableImage as specified by the parameter * * @param createOp the way the image should be created * @return the image * ******************************************************************************************************************/ @Nonnull public static EditableImage create (final @Nonnull AbstractCreateOp createOp) { final EditableImage editableImage = new EditableImage(null); final Object image = editableImage.internalExecute(createOp); final ImageModel imageModel = Lookup.getDefault().lookup(ImplementationFactoryRegistry.class).createImageModel(image); editableImage.imageModelHolder = ImageModelHolder.wrap(imageModel); return editableImage; }