Skip to content

Commit

Permalink
style: format code with Google Java Format
Browse files Browse the repository at this point in the history
This commit fixes the style issues introduced in 4de99c1 according to the output
from Google Java Format.

Details: #127
  • Loading branch information
deepsource-autofix[bot] authored Jun 13, 2024
1 parent 4de99c1 commit 8e3e4d0
Showing 1 changed file with 73 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public class SearchView extends StandardLayout implements HasUrlParameter<String
/**
* Constructs a SearchView object.
*
* @param sourceService the {@link SourceService} used for retrieving manga sources
* @param searchService the {@link SearchService} used for performing search operations
* @param sourceService the {@link SourceService} used for retrieving manga sources
* @param searchService the {@link SearchService} used for performing search operations
* @param settingsService the {@link SettingsService} used for accessing search settings
*/
public SearchView(SourceService sourceService, SearchService searchService,
SettingsService settingsService) {
public SearchView(
SourceService sourceService, SearchService searchService, SettingsService settingsService) {
super("Search");

this.sourceService = sourceService;
Expand Down Expand Up @@ -107,50 +107,51 @@ public SearchView(SourceService sourceService, SearchService searchService,
}

/**
* Retrieves the "Import from MAL" button. This button is used to navigate to the
* {@link MALView}.
* Retrieves the "Import from MAL" button. This button is used to navigate to the {@link MALView}.
*
* @return the button that navigates to the {@link MALView}
*/
@NotNull
private Button getMalImportBtn() {
Button malImportBtn = new Button("Import from MAL", VaadinIcon.DOWNLOAD.create());

malImportBtn.addClickListener(e -> {
UI ui = getUI().orElse(UI.getCurrent());
malImportBtn.addClickListener(
e -> {
UI ui = getUI().orElse(UI.getCurrent());

if (ui == null) {
return;
}
if (ui == null) {
return;
}

ui.navigate(MALView.class);
});
ui.navigate(MALView.class);
});
return malImportBtn;
}

/**
* Retrieves the "Import from AniList" button. This button is used to navigate to the
* {@link AniListView}.
* Retrieves the "Import from AniList" button. This button is used to navigate to the {@link
* AniListView}.
*
* @return The button that navigates to the {@link AniListView}
*/
@NotNull
private Button getALImportBtn() {
Button importBtn = new Button("Import from AniList", VaadinIcon.DOWNLOAD.create());
importBtn.addClickListener(e -> {
UI ui = UI.getCurrent();
importBtn.addClickListener(
e -> {
UI ui = UI.getCurrent();

if (ui == null) {
if (getUI().isEmpty()) {
log.error("UI is not present");
return;
}
if (ui == null) {
if (getUI().isEmpty()) {
log.error("UI is not present");
return;
}

ui = getUI().get();
}
ui = getUI().get();
}

ui.navigate(AniListView.class);
});
ui.navigate(AniListView.class);
});
return importBtn;
}

Expand All @@ -170,12 +171,13 @@ private ComboBox<String> createLanguageComboBox(SourceService sourceService) {
}
}

langFilter.addValueChangeListener(e -> {
if (!e.isFromClient()) {
return;
}
runSearch(searchField);
});
langFilter.addValueChangeListener(
e -> {
if (!e.isFromClient()) {
return;
}
runSearch(searchField);
});

return langFilter;
}
Expand Down Expand Up @@ -206,28 +208,34 @@ private void runSearch(SuperTextField searchField) {

CompletableFuture<?> future = CompletableFuture.runAsync(() -> search(searchField.getValue()));

future.thenRun(() -> {
var ui = getUI();

if (ui.isEmpty()) {
log.error("UI is not present");
return;
}

if (!ui.get().isAttached()) {
log.debug("UI is not attached anymore");
return;
}

ui.get().access(() -> {
searchField.setSuffixComponent(null);
searchField.setReadOnly(false);
langFilter.setReadOnly(false);
});
}).exceptionally(ex -> {
log.error("Error searching", ex);
return null;
});
future
.thenRun(
() -> {
var ui = getUI();

if (ui.isEmpty()) {
log.error("UI is not present");
return;
}

if (!ui.get().isAttached()) {
log.debug("UI is not attached anymore");
return;
}

ui.get()
.access(
() -> {
searchField.setSuffixComponent(null);
searchField.setReadOnly(false);
langFilter.setReadOnly(false);
});
})
.exceptionally(
ex -> {
log.error("Error searching", ex);
return null;
});
}

private Div getLoadingDiv() {
Expand All @@ -247,17 +255,18 @@ private Div getLoadingDiv() {

public void search(String query) {
var sources = sourceService.getSources();
var langGroupedSources = sources.stream()
.sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName()))
.collect(Collectors.groupingBy(Source::getLang));
var langGroupedSources =
sources.stream()
.sorted((a, b) -> a.getDisplayName().compareToIgnoreCase(b.getDisplayName()))
.collect(Collectors.groupingBy(Source::getLang));

searchSources(query, langGroupedSources);
}

/**
* Adds a search result to the user interface.
*
* @param source the source of the search result
* @param source the source of the search result
* @param mangaList the list of manga from the search result
* @return true if the search result was successfully added, otherwise false
*/
Expand Down Expand Up @@ -321,7 +330,7 @@ private Div createSearchResultDiv(Source source, List<Manga> mangaList) {
/**
* Searches for manga in the specified sources
*
* @param query the search query
* @param query the search query
* @param langGroupedSources the sources grouped by language
*/
private void searchSources(String query, Map<String, List<Source>> langGroupedSources) {
Expand All @@ -337,10 +346,11 @@ private void searchSources(String query, Map<String, List<Source>> langGroupedSo

List<Callable<Void>> searchTasks = new ArrayList<>();
for (var source : langSources) {
Callable<Void> runnable = () -> {
searchSource(query, source);
return null;
};
Callable<Void> runnable =
() -> {
searchSource(query, source);
return null;
};
searchTasks.add(runnable);
}

Expand Down

0 comments on commit 8e3e4d0

Please sign in to comment.