X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.utils%2Fsrc%2Forg%2Fsimantics%2Futils%2FFileService.java;h=ab3d249d3bd95e157dcdb6af12caa87dba737353;hb=7ae35034910a88da49082b2aacffc4a4d3b53583;hp=f272437e86a2f0a652c8ce0d4aae547e412626c6;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git
diff --git a/bundles/org.simantics.utils/src/org/simantics/utils/FileService.java b/bundles/org.simantics.utils/src/org/simantics/utils/FileService.java
index f272437e8..ab3d249d3 100644
--- a/bundles/org.simantics.utils/src/org/simantics/utils/FileService.java
+++ b/bundles/org.simantics.utils/src/org/simantics/utils/FileService.java
@@ -1,36 +1,73 @@
-package org.simantics.utils;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * @author Tuukka Lehtonen
- */
-public interface FileService {
-
- public static interface DeleteOption {}
-
- public static class EffortOption implements DeleteOption {
- public final int maxTries;
-
- private EffortOption(int maxTries) {
- this.maxTries = maxTries;
- }
-
- public static EffortOption maxTries(int maxTries) {
- return new EffortOption(maxTries);
- }
- }
-
- /**
- * Schedules a file to be deleted at some point in the future when the
- * system allows it to be deleted if ever.
- *
- * @param file
- * @return an operation handle for tracking the progress of the deletion or
- * null
if there's a deletion operation scheduled for
- * the provided file in the queue or the file does not exist.
- */
- IOperation scheduleDeleteIfExists(File file, DeleteOption... options);
-
-}
+package org.simantics.utils;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public interface FileService {
+
+ public static interface DeleteOption {}
+
+ public static class EffortOption implements DeleteOption {
+ public final int maxTries;
+
+ private EffortOption(int maxTries) {
+ this.maxTries = maxTries;
+ }
+
+ public static EffortOption maxTries(int maxTries) {
+ return new EffortOption(maxTries);
+ }
+ }
+
+ @FunctionalInterface
+ public static interface FileOperation {
+ IOperation perform(File file);
+
+ default void perform(File... files) {
+ for (File f : files)
+ perform(f);
+ }
+ }
+
+ public static class DeleteOperation implements FileOperation {
+ private final FileService service;
+ private final DeleteOption[] options;
+
+ public DeleteOperation(FileService service, DeleteOption... options) {
+ this.service = service;
+ this.options = options;
+ }
+
+ @Override
+ public IOperation perform(File file) {
+ return service.scheduleDeleteIfExists(file, options);
+ }
+ }
+
+ /**
+ * Schedules a file to be deleted at some point in the future when the
+ * system allows it to be deleted if ever.
+ *
+ * @param file
+ * @return an operation handle for tracking the progress of the deletion or
+ * null
if there's a deletion operation scheduled for
+ * the provided file in the queue or the file does not exist.
+ */
+ IOperation scheduleDeleteIfExists(File file, DeleteOption... options);
+
+ /**
+ * @param options
+ * the deletion options to be used by the returned FileOperation
+ * @return a FileOperation that runs
+ * {@link #scheduleDeleteIfExists(File, DeleteOption...)} for any
+ * files given to it
+ * @since 1.28.0
+ */
+ default FileOperation deleteOperation(DeleteOption... options) {
+ return new DeleteOperation(this, options);
+ }
+
+}