public void start(ProgressListener progressListener) {
cancelled = false;
this.progressListener = progressListener;
- fileScanner = new FileScanner(project);
- fileScanner.addFileScannerListener(this);
+ fileScanner = new FileScanner(project, this);
fileScanner.startInBackground();
}
}
}
long totalSize = 0;
- FileScanner fileScanner = new FileScanner(project);
final CountDownLatch completionLatch = new CountDownLatch(1);
- fileScanner.addFileScannerListener(new FileScannerListener() {
+ FileScanner fileScanner = new FileScanner(project, new FileScannerListener() {
@Override
public void fileScannerFinished(FileScanner fileScanner) {
} else {
projectInsertListeners.fireProjectInsertFinished(project, false, null);
}
- fileScanner.removeFileScannerListener(this);
}
/**
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
private final static Logger logger = Logger.getLogger(FileScanner.class.getName());
/** The list of listeners. */
- private final List<FileScannerListener> fileScannerListeners = new ArrayList<FileScannerListener>();
+ private final FileScannerListener fileScannerListener;
/** The project to scan. */
private final Project project;
* @param project
* The project whose files to scan
*/
- public FileScanner(Project project) {
+ public FileScanner(Project project, FileScannerListener fileScannerListener) {
this.project = project;
- }
-
- /**
- * Adds the given listener to the list of listeners.
- *
- * @param fileScannerListener
- * The listener to add
- */
- public void addFileScannerListener(FileScannerListener fileScannerListener) {
- fileScannerListeners.add(fileScannerListener);
- }
-
- /**
- * Removes the given listener from the list of listeners.
- *
- * @param fileScannerListener
- * The listener to remove
- */
- public void removeFileScannerListener(FileScannerListener fileScannerListener) {
- fileScannerListeners.remove(fileScannerListener);
- }
-
- /**
- * Notifies all listeners that the file scan finished.
- */
- protected void fireFileScannerFinished() {
- for (FileScannerListener fileScannerListener : new ArrayList<FileScannerListener>(fileScannerListeners)) {
- fileScannerListener.fileScannerFinished(this);
- }
+ this.fileScannerListener = Objects.requireNonNull(fileScannerListener);
}
/**
} catch (IOException ioe1) {
error = true;
}
- fireFileScannerFinished();
+ fileScannerListener.fileScannerFinished(this);
}
/**