fix(metadata): replace iterator calls with getFirst() (#1305)
This commit is contained in:
@@ -113,7 +113,7 @@ public class KomgaController {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
Long firstBookId = Long.parseLong(books.getContent().get(0).getId());
|
||||
Long firstBookId = Long.parseLong(books.getContent().getFirst().getId());
|
||||
Resource coverImage = bookService.getBookThumbnail(firstBookId);
|
||||
return ResponseEntity.ok()
|
||||
.header("Content-Type", "image/jpeg")
|
||||
|
||||
@@ -32,7 +32,7 @@ public class KomgaMapper {
|
||||
.id(library.getId().toString())
|
||||
.name(library.getName())
|
||||
.root(library.getLibraryPaths() != null && !library.getLibraryPaths().isEmpty()
|
||||
? library.getLibraryPaths().get(0).getPath()
|
||||
? library.getLibraryPaths().getFirst().getPath()
|
||||
: "")
|
||||
.unavailable(false)
|
||||
.build();
|
||||
@@ -71,7 +71,7 @@ public class KomgaMapper {
|
||||
return null;
|
||||
}
|
||||
|
||||
BookEntity firstBook = books.get(0);
|
||||
BookEntity firstBook = books.getFirst();
|
||||
String seriesId = generateSeriesId(firstBook);
|
||||
|
||||
// Aggregate metadata from all books
|
||||
@@ -154,7 +154,7 @@ public class KomgaMapper {
|
||||
}
|
||||
|
||||
private KomgaSeriesMetadataDto aggregateSeriesMetadata(String seriesName, List<BookEntity> books) {
|
||||
BookEntity firstBook = books.get(0);
|
||||
BookEntity firstBook = books.getFirst();
|
||||
BookMetadataEntity firstMetadata = firstBook.getMetadata();
|
||||
|
||||
List<String> genres = new ArrayList<>();
|
||||
@@ -208,7 +208,7 @@ public class KomgaMapper {
|
||||
String releaseDate = null;
|
||||
String summary = null;
|
||||
|
||||
BookEntity firstBook = books.get(0);
|
||||
BookEntity firstBook = books.getFirst();
|
||||
for (BookEntity book : books) {
|
||||
BookMetadataEntity metadata = book.getMetadata();
|
||||
if (metadata != null) {
|
||||
|
||||
@@ -164,7 +164,7 @@ public class BookDownloadService {
|
||||
|
||||
// If only one file and it's not folder-based, download it directly
|
||||
if (allFiles.size() == 1) {
|
||||
BookFileEntity singleFile = allFiles.get(0);
|
||||
BookFileEntity singleFile = allFiles.getFirst();
|
||||
Path filePath = FileUtils.requirePathWithinBase(singleFile.getFullFilePath(), libraryRoot);
|
||||
|
||||
if (!Files.exists(filePath)) {
|
||||
|
||||
@@ -134,7 +134,7 @@ public class KomgaService {
|
||||
}
|
||||
|
||||
if (!seriesBooks.isEmpty()) {
|
||||
Long libId = seriesBooks.get(0).getLibrary().getId();
|
||||
Long libId = seriesBooks.getFirst().getLibrary().getId();
|
||||
KomgaSeriesDto seriesDto = komgaMapper.toKomgaSeriesDto(seriesName, libId, seriesBooks);
|
||||
if (seriesDto != null) {
|
||||
content.add(seriesDto);
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ public abstract class MobiBaseMetadataExtractor implements FileMetadataExtractor
|
||||
return null;
|
||||
}
|
||||
|
||||
PalmDBRecord record0 = palmDB.records.get(0);
|
||||
PalmDBRecord record0 = palmDB.records.getFirst();
|
||||
raf.seek(record0.offset);
|
||||
|
||||
MobiHeader header = new MobiHeader();
|
||||
|
||||
@@ -289,7 +289,7 @@ public class GoogleParser implements BookParser {
|
||||
Float seriesNumber = null;
|
||||
|
||||
if (seriesInfo.getVolumeSeries() != null && !seriesInfo.getVolumeSeries().isEmpty()) {
|
||||
Integer orderNum = seriesInfo.getVolumeSeries().get(0).getOrderNumber();
|
||||
Integer orderNum = seriesInfo.getVolumeSeries().getFirst().getOrderNumber();
|
||||
if (orderNum != null) {
|
||||
seriesNumber = orderNum.floatValue();
|
||||
}
|
||||
|
||||
@@ -601,7 +601,7 @@ public class OpdsBookService {
|
||||
private String getFirstAuthor(Book book) {
|
||||
if (book.getMetadata() != null && book.getMetadata().getAuthors() != null
|
||||
&& !book.getMetadata().getAuthors().isEmpty()) {
|
||||
return book.getMetadata().getAuthors().iterator().next();
|
||||
return book.getMetadata().getAuthors().getFirst();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ public class AudioMetadataService {
|
||||
if (metadata != null) {
|
||||
builder.title(metadata.getTitle());
|
||||
if (metadata.getAuthors() != null && !metadata.getAuthors().isEmpty()) {
|
||||
builder.author(metadata.getAuthors().iterator().next().getName());
|
||||
builder.author(metadata.getAuthors().getFirst().getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ public class AudioMetadataService {
|
||||
title = bookTitle;
|
||||
}
|
||||
if (metadata.getAuthors() != null && !metadata.getAuthors().isEmpty()) {
|
||||
author = metadata.getAuthors().iterator().next().getName();
|
||||
author = metadata.getAuthors().getFirst().getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -286,7 +286,7 @@ public class EpubReaderService {
|
||||
|
||||
List<Author> authors = md.getAuthors();
|
||||
if (authors != null && !authors.isEmpty()) {
|
||||
Author first = authors.get(0);
|
||||
Author first = authors.getFirst();
|
||||
String name = first.getFirstname();
|
||||
if (first.getLastname() != null && !first.getLastname().isEmpty()) {
|
||||
name = (name != null && !name.isEmpty()) ? name + " " + first.getLastname() : first.getLastname();
|
||||
@@ -298,13 +298,13 @@ public class EpubReaderService {
|
||||
if (language != null && !language.isEmpty()) metadata.put("language", language);
|
||||
|
||||
List<String> publishers = md.getPublishers();
|
||||
if (publishers != null && !publishers.isEmpty()) metadata.put("publisher", publishers.get(0));
|
||||
if (publishers != null && !publishers.isEmpty()) metadata.put("publisher", publishers.getFirst());
|
||||
|
||||
List<Identifier> identifiers = md.getIdentifiers();
|
||||
if (identifiers != null && !identifiers.isEmpty()) metadata.put("identifier", identifiers.get(0).getValue());
|
||||
if (identifiers != null && !identifiers.isEmpty()) metadata.put("identifier", identifiers.getFirst().getValue());
|
||||
|
||||
List<String> descriptions = md.getDescriptions();
|
||||
if (descriptions != null && !descriptions.isEmpty()) metadata.put("description", descriptions.get(0));
|
||||
if (descriptions != null && !descriptions.isEmpty()) metadata.put("description", descriptions.getFirst());
|
||||
|
||||
// EPUB3 rendition properties
|
||||
if (md.getRenditionLayout() != null) metadata.put("rendition:layout", md.getRenditionLayout());
|
||||
|
||||
@@ -202,7 +202,7 @@ public class FileUploadService {
|
||||
throw new IllegalStateException("Cannot upload file to physical book: library has no paths configured");
|
||||
}
|
||||
// Use the first library path for physical books
|
||||
return book.getLibrary().getLibraryPaths().iterator().next();
|
||||
return book.getLibrary().getLibraryPaths().getFirst();
|
||||
}
|
||||
|
||||
private BookFileEntity createAdditionalFileEntityWithSubPath(BookEntity book, String fileName, String fileSubPath, boolean isBook, BookFileType bookType, long fileSize, String fileHash, String description) {
|
||||
|
||||
@@ -170,8 +170,8 @@ public class BookFileGroupingUtils {
|
||||
continue;
|
||||
}
|
||||
|
||||
String fileSubPath = filesInFolder.get(0).getFileSubPath();
|
||||
Long libraryPathId = filesInFolder.get(0).getLibraryPathEntity().getId();
|
||||
String fileSubPath = filesInFolder.getFirst().getFileSubPath();
|
||||
Long libraryPathId = filesInFolder.getFirst().getLibraryPathEntity().getId();
|
||||
|
||||
// Root-level files: use exact grouping
|
||||
if (fileSubPath == null || fileSubPath.isEmpty()) {
|
||||
@@ -362,7 +362,7 @@ public class BookFileGroupingUtils {
|
||||
Map<String, List<LibraryFile>> result = new LinkedHashMap<>();
|
||||
|
||||
if (files.size() == 1) {
|
||||
LibraryFile file = files.get(0);
|
||||
LibraryFile file = files.getFirst();
|
||||
String key = libraryPathId + ":" + fileSubPath + ":single:" + extractGroupingKey(file.getFileName());
|
||||
result.put(key, new ArrayList<>(List.of(file)));
|
||||
return result;
|
||||
@@ -413,7 +413,7 @@ public class BookFileGroupingUtils {
|
||||
List<LibraryFile> clusterFiles = cluster.getValue();
|
||||
// Use the first file's key as the group key
|
||||
String groupKey = libraryPathId + ":" + fileSubPath + ":cluster:" +
|
||||
extractGroupingKey(clusterFiles.get(0).getFileName());
|
||||
extractGroupingKey(clusterFiles.getFirst().getFileName());
|
||||
result.put(groupKey, clusterFiles);
|
||||
|
||||
if (clusterFiles.size() > 1) {
|
||||
|
||||
Reference in New Issue
Block a user