Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code quality - drop while(true) #526

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ public void initializeApp() {
Arrays.asList(htmlPane, slidePane, liveReloadPane).forEach(viewPanel -> VBox.getVgrow(viewPanel));

threadService.runTaskLater(() -> {
// Main loop for the app
while (true) {
try {
renderLoop();
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/com/kodedu/service/impl/DirectoryServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -362,19 +362,13 @@ public Path findPathInWorkdirOrLookup(Path uri) {
if (optional.isPresent()) {
Path currentParent = optional.get();

while (true) {

if (Objects.nonNull(currentParent)) {
Path candidate = currentParent.resolve(uri);
if (Files.exists(candidate)) {
return candidate;
} else {
currentParent = currentParent.getParent();
}
} else {
break;
while (Objects.nonNull(currentParent)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be replaced by

for (Path currentParent = optional.get(); Objects.nonNull(currentParent); currentParent = currentParent.getParent())

Path candidate = currentParent.resolve(uri);
if (Files.exists(candidate)) {
return candidate;
}

currentParent = currentParent.getParent();
}

}
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/com/kodedu/service/impl/FileWatchServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ private void watchPathChanges() {
reCreateWatchService();
}

// This should keep running to keep track of files changes
// Must be implemented as an active check due to the way Java handles listening to file changes
while (true) {

if (Objects.isNull(watcher)) {
Expand All @@ -118,6 +120,7 @@ private void watchPathChanges() {
}

List<WatchEvent<?>> watchEvents = watchKey.pollEvents();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pollEvents is not blocking, might want to add a sleep somewhere in here or use a self-scheduling method instead of a loop

watchKey.reset();

boolean updateFsView = false;
for (WatchEvent<?> event : watchEvents) {
Expand All @@ -137,14 +140,9 @@ private void watchPathChanges() {
}
}
}
watchKey.reset();
} else if (kind == ENTRY_MODIFY && event.count() > 1) {
watchKey.reset();
} else {
} else if (kind != ENTRY_MODIFY || (kind == ENTRY_MODIFY && event.count() == 0)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME: should be && event.count() <= 1

updateFsView = true;
watchKey.reset();
}

}

if (updateFsView) {
Expand All @@ -159,7 +157,6 @@ private void watchPathChanges() {
}
fileBrowseService.refreshPathToTree(path, changedPath);
}

}

}
Expand Down
71 changes: 26 additions & 45 deletions src/main/java/com/kodedu/service/ui/impl/FileBrowseServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,26 @@ public void searchUpAndSelect(String text) {

ListIterator<TreeItem<Item>> listIterator = foundItems.listIterator();

while (true) {

if (Objects.isNull(searchFoundItem)) {
if (listIterator.hasNext()) {
searchFoundItem = listIterator.next();
}
break;
}

if (Objects.isNull(searchFoundItem)) {
if (listIterator.hasNext()) {
TreeItem<Item> next = listIterator.next();
if (next.getValue().equals(searchFoundItem.getValue())) {
if (listIterator.hasNext()) {
TreeItem<Item> nexted = listIterator.next();
searchFoundItem = listIterator.next();
}
}
while (listIterator.hasNext()) {
TreeItem<Item> next = listIterator.next();
if (next.getValue().equals(searchFoundItem.getValue())) {
if (listIterator.hasNext()) {
TreeItem<Item> nexted = listIterator.next();

if (next == nexted) {
if (listIterator.hasNext()) {
nexted = listIterator.next();
}
if (next == nexted) {
if (listIterator.hasNext()) {
nexted = listIterator.next();
}

searchFoundItem = nexted;
break;
}

searchFoundItem = nexted;
break;
}
} else {
break;
}

}
Expand All @@ -332,34 +325,23 @@ public void searchDownAndSelect(String text) {

ListIterator<TreeItem<Item>> listIterator = foundItems.listIterator();

while (true) {

if (Objects.isNull(searchFoundItem)) {
if (listIterator.hasPrevious()) {
searchFoundItem = listIterator.previous();
}

break;
if (Objects.isNull(searchFoundItem)) {
if (listIterator.hasNext()) {
searchFoundItem = listIterator.next();
}
} else {

if (listIterator.hasNext()) {
while (listIterator.hasNext()) {
TreeItem<Item> next = listIterator.next();
if (next.getValue().equals(searchFoundItem.getValue())) {
if (listIterator.hasPrevious()) {
TreeItem<Item> previous = listIterator.previous();
if (next == previous) {
if (listIterator.hasPrevious()) {
previous = listIterator.previous();
}
}
searchFoundItem = previous;
break;
if (next.getValue().equals(searchFoundItem.getValue()) && listIterator.hasPrevious()) {
TreeItem<Item> previous = listIterator.previous();
if (next == previous && listIterator.hasPrevious()) {
previous = listIterator.previous();
}
searchFoundItem = previous;
break;
}
} else {
break;
}

}

focusFoundItem(searchFoundItem);
Expand Down Expand Up @@ -439,7 +421,6 @@ public void searchAndSelect(String text) {

ListIterator<TreeItem<Item>> listIterator = foundItems.listIterator();


if (Objects.isNull(searchFoundItem)) {
if (listIterator.hasNext()) {
searchFoundItem = listIterator.next();
Expand Down