1717import java .util .List ;
1818import java .util .concurrent .CompletableFuture ;
1919import java .util .concurrent .Executor ;
20+ import java .util .function .Supplier ;
2021
2122public class SuggestionsProvider {
2223
2324 private static final String LOGTAG = SuggestionsProvider .class .getSimpleName ();
2425
25- public class DefaultSuggestionsComparator implements Comparator {
26+ public static class DefaultSuggestionsComparator implements Comparator < SuggestionItem > {
2627
27- public int compare (Object obj1 , Object obj2 ) {
28- SuggestionItem suggestion1 = (SuggestionItem )obj1 ;
29- SuggestionItem suggestion2 = (SuggestionItem )obj2 ;
30- if (suggestion1 .type == Type .SUGGESTION && suggestion2 .type == Type .SUGGESTION ) {
28+ public int compare (SuggestionItem obj1 , SuggestionItem obj2 ) {
29+ if (obj1 .type == Type .SUGGESTION && obj2 .type == Type .SUGGESTION ) {
3130 return 0 ;
3231
33- } else if (suggestion1 .type == suggestion2 .type ) {
34- if (suggestion1 .type == Type .HISTORY ) {
35- if (suggestion1 .score != suggestion2 .score ) {
36- return suggestion1 .score - suggestion2 .score ;
32+ } else if (obj1 .type == obj2 .type ) {
33+ if (obj1 .type == Type .HISTORY ) {
34+ if (obj1 .score != obj2 .score ) {
35+ return obj1 .score - obj2 .score ;
3736 }
3837 }
3938
40- return suggestion1 .url .compareTo (suggestion2 .url );
39+ return obj1 .url .compareTo (obj2 .url );
4140
4241 } else {
43- return suggestion1 .type .ordinal () - suggestion2 .type .ordinal ();
42+ return obj1 .type .ordinal () - obj2 .type .ordinal ();
4443 }
4544 }
4645 }
4746
4847 private SearchEngineWrapper mSearchEngineWrapper ;
4948 private String mText ;
5049 private String mFilterText ;
51- private Comparator mComparator ;
50+ private Comparator < SuggestionItem > mComparator ;
5251 private Executor mUIThreadExecutor ;
5352
5453 public SuggestionsProvider (Context context ) {
@@ -74,15 +73,15 @@ public void setFilterText(String text) {
7473
7574 public void setText (String text ) { mText = text ; }
7675
77- public void setComparator (Comparator comparator ) {
76+ public void setComparator (Comparator < SuggestionItem > comparator ) {
7877 mComparator = comparator ;
7978 }
8079
8180 private CompletableFuture <List <SuggestionItem >> getBookmarkSuggestions (@ NonNull List <SuggestionItem > items ) {
82- CompletableFuture future = new CompletableFuture ();
81+ CompletableFuture < List < SuggestionItem >> future = new CompletableFuture <> ();
8382 SessionStore .get ().getBookmarkStore ().searchBookmarks (mFilterText , 100 ).thenAcceptAsync ((bookmarks ) -> {
8483 bookmarks .stream ()
85- .filter ((b ) -> !b .getUrl ().startsWith ("place:" ) &&
84+ .filter ((b ) -> b . getUrl () != null && !b .getUrl ().startsWith ("place:" ) &&
8685 !b .getUrl ().startsWith ("about:reader" ))
8786 .forEach (b -> items .add (SuggestionItem .create (
8887 b .getTitle (),
@@ -107,7 +106,7 @@ private CompletableFuture<List<SuggestionItem>> getBookmarkSuggestions(@NonNull
107106 }
108107
109108 private CompletableFuture <List <SuggestionItem >> getHistorySuggestions (@ NonNull final List <SuggestionItem > items ) {
110- CompletableFuture future = new CompletableFuture ();
109+ CompletableFuture < List < SuggestionItem >> future = new CompletableFuture <> ();
111110 SessionStore .get ().getHistoryStore ().getSuggestions (mFilterText , 100 ).thenAcceptAsync ((history ) -> {
112111 history .forEach (h -> items .add (SuggestionItem .create (
113112 h .getTitle (),
@@ -132,7 +131,7 @@ private CompletableFuture<List<SuggestionItem>> getHistorySuggestions(@NonNull f
132131 }
133132
134133 private CompletableFuture <List <SuggestionItem >> getSearchEngineSuggestions (@ NonNull final List <SuggestionItem > items ) {
135- CompletableFuture future = new CompletableFuture ();
134+ CompletableFuture < List < SuggestionItem >> future = new CompletableFuture <> ();
136135
137136 // Completion from browser-domains
138137 if (!mText .equals (mFilterText )) {
@@ -182,7 +181,7 @@ private CompletableFuture<List<SuggestionItem>> getSearchEngineSuggestions(@NonN
182181 }
183182
184183 public CompletableFuture <List <SuggestionItem >> getSuggestions () {
185- return CompletableFuture .supplyAsync (() -> new ArrayList <SuggestionItem >() )
184+ return CompletableFuture .supplyAsync ((Supplier < ArrayList <SuggestionItem >>) ArrayList :: new )
186185 .thenComposeAsync (this ::getSearchEngineSuggestions )
187186 .thenComposeAsync (this ::getBookmarkSuggestions )
188187 .thenComposeAsync (this ::getHistorySuggestions );
0 commit comments