Skip to content

Commit

Permalink
Merge pull request #6 from JordanMartinez/minorCodeCleanup
Browse files Browse the repository at this point in the history
Minor code cleanup.
  • Loading branch information
TomasMikula committed Feb 16, 2016
2 parents e02f152 + 6032f10 commit 97f0608
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/main/java/org/fxmisc/livedirs/DirWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class DirWatcher {

public DirWatcher(Executor eventThreadExecutor) throws IOException {
this.watcher = FileSystems.getDefault().newWatchService();
this.ioThread = new Thread(() -> loop(), "DirWatchIO");
this.ioThread = new Thread(this::loop, "DirWatchIO");
this.eventThreadExecutor = eventThreadExecutor;
this.ioThread.start();
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public static PathNode getTree(Path root) throws IOException {
try(Stream<Path> dirStream = Files.list(root)) {
childPaths = dirStream
.sorted(PATH_COMPARATOR)
.toArray(i -> new Path[i]);
.toArray(Path[]::new);
}
List<PathNode> children = new ArrayList<>(childPaths.length);
for(Path p: childPaths) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fxmisc/livedirs/LiveDirs.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public LiveDirs(I externalInitiator, Executor clientThreadExecutor) throws IOExc
this.model = new LiveDirsModel<>(externalInitiator);
this.io = new LiveDirsIO<>(dirWatcher, model, clientThreadExecutor);

this.dirWatcher.signalledKeys().subscribe(key -> processKey(key));
this.dirWatcher.signalledKeys().subscribe(this::processKey);
this.errors = EventStreams.merge(dirWatcher.errors(), model.errors(), localErrors);
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/org/fxmisc/livedirs/LiveDirsIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CompletionStage<Void> createFile(Path file, I initiator) {
model.addFile(file, initiator, lastModified);
created.complete(null);
},
error -> created.completeExceptionally(error));
created::completeExceptionally);
return wrap(created);
}

Expand All @@ -40,7 +40,7 @@ public CompletionStage<Void> createDirectory(Path dir, I initiator) {
}
created.complete(null);
},
error -> created.completeExceptionally(error));
created::completeExceptionally);
return wrap(created);
}

Expand All @@ -52,7 +52,7 @@ public CompletionStage<Void> saveTextFile(Path file, String content, Charset cha
model.updateModificationTime(file, lastModified, initiator);
saved.complete(null);
},
error -> saved.completeExceptionally(error));
saved::completeExceptionally);
return wrap(saved);
}

Expand All @@ -64,7 +64,7 @@ public CompletionStage<Void> saveBinaryFile(Path file, byte[] content, I initiat
model.updateModificationTime(file, lastModified, initiator);
saved.complete(null);
},
error -> saved.completeExceptionally(error));
saved::completeExceptionally);
return wrap(saved);
}

Expand All @@ -76,7 +76,7 @@ public CompletionStage<Void> delete(Path file, I initiator) {
model.delete(file, initiator);
deleted.complete(null);
},
error -> deleted.completeExceptionally(error));
deleted::completeExceptionally);
return wrap(deleted);
}

Expand All @@ -88,25 +88,25 @@ public CompletionStage<Void> deleteTree(Path root, I initiator) {
model.delete(root, initiator);
deleted.complete(null);
},
error -> deleted.completeExceptionally(error));
deleted::completeExceptionally);
return wrap(deleted);
}

@Override
public CompletionStage<String> loadTextFile(Path file, Charset charset) {
CompletableFuture<String> loaded = new CompletableFuture<>();
dirWatcher.loadTextFile(file, charset,
content -> loaded.complete(content),
error -> loaded.completeExceptionally(error));
loaded::complete,
loaded::completeExceptionally);
return wrap(loaded);
}

@Override
public CompletionStage<byte[]> loadBinaryFile(Path file) {
CompletableFuture<byte[]> loaded = new CompletableFuture<>();
dirWatcher.loadBinaryFile(file,
content -> loaded.complete(content),
error -> loaded.completeExceptionally(error));
loaded::complete,
loaded::completeExceptionally);
return wrap(loaded);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/fxmisc/livedirs/LiveDirsModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private Stream<TopLevelDirItem<I>> topLevelAncestorStream(Path path) {

private List<TopLevelDirItem<I>> getTopLevelAncestors(Path path) {
return Arrays.asList(topLevelAncestorStream(path)
.toArray(i -> new TopLevelDirItem[i]));
.<TopLevelDirItem<I>>toArray(TopLevelDirItem[]::new));
}

private List<TopLevelDirItem<I>> getTopLevelAncestorsNonEmpty(Path path) {
Expand Down

0 comments on commit 97f0608

Please sign in to comment.