1818import java .util .ArrayList ;
1919import java .util .List ;
2020import java .util .Map ;
21+ import java .util .Objects ;
2122import java .util .Optional ;
2223import java .util .StringTokenizer ;
2324import java .util .UUID ;
2425import java .util .concurrent .atomic .AtomicReference ;
26+ import java .util .function .Predicate ;
2527import java .util .stream .Collectors ;
2628import java .util .stream .Stream ;
2729
@@ -144,16 +146,16 @@ public Optional<Book> findBookByUuid(String uuidStr) {
144146
145147 public List <Book > findBooksByTitleAuthor (String titleAuthor ) {
146148 return Optional .ofNullable (titleAuthor ).stream ().filter (myStr -> myStr .trim ().length () > 2 )
147- .map (myStr -> myStr . toLowerCase () )
149+ .map (String :: toLowerCase )
148150 .flatMap (myStr -> Stream .of (this .bookRepository .findByTitleAuthorWithChapters (myStr )))
149- .flatMap (myList -> myList . stream () ).toList ();
151+ .flatMap (List :: stream ).toList ();
150152 }
151153
152154 @ Async
153155 public void addBookSummaries (Book book ) {
154156 var myChapters = book .getChapters ().stream ().map (myChapter -> this .addChapterSummary (myChapter )).toList ();
155157 // LOGGER.info(myChapters.getLast().getSummary());
156- var summaries = myChapters .stream ().map (myChapter -> myChapter . getChapterText () )
158+ var summaries = myChapters .stream ().map (Chapter :: getChapterText )
157159 .reduce ((acc , myChapter ) -> acc + "\n " + myChapter );
158160 book .setSummary (this .chatClient
159161 .call (new SystemPromptTemplate (this .bookPrompt ).createMessage (Map .of ("text" , summaries )).getContent ()));
@@ -173,7 +175,7 @@ private Chapter addChapterSummary(Chapter myChapter) {
173175
174176 private Chapter createChapter (Book book , String heading , AtomicReference <List <String >> atomicRef ) {
175177 var result = new Chapter ();
176- result .setTitle (atomicRef .get ().stream ().filter (myLine -> ! myLine . isBlank ( )).findFirst ().orElse ("" ));
178+ result .setTitle (atomicRef .get ().stream ().filter (Predicate . not ( String :: isBlank )).findFirst ().orElse ("" ));
177179 result .setBook (book );
178180 var chapterText = atomicRef .get ().stream ().takeWhile (myLine -> !myLine .contains (heading ))
179181 .collect (Collectors .joining (System .lineSeparator ()));
@@ -251,8 +253,9 @@ public AiDocumentResult queryDocuments(SearchDto searchDto) {
251253 private Message getSystemMessage (List <org .springframework .ai .document .Document > similarDocuments , int tokenLimit ,
252254 String prompt ) {
253255 String documentStr = this .cutStringToTokenLimit (
254- similarDocuments .stream ().map (entry -> entry .getContent ())
255- .filter (myStr -> myStr != null && !myStr .isBlank ()).collect (Collectors .joining ("\n " )),
256+ similarDocuments .stream ().map (entry -> entry .getContent ())
257+ .filter (Predicate .not (Objects ::isNull ))
258+ .filter (Predicate .not (String ::isBlank )).collect (Collectors .joining ("\n " )),
256259 tokenLimit );
257260 SystemPromptTemplate systemPromptTemplate = this .activeProfile .contains ("ollama" )
258261 ? new SystemPromptTemplate (this .ollamaPrompt )
0 commit comments