Skip to content

Commit

Permalink
Fix IntelliJ suggested style issues in clients and tests (Azure#320)
Browse files Browse the repository at this point in the history
(1) Removed unused throw, import. (2) Replaced Arrays.asList() with Collections.singletonList(). (3) Replaced lambda statement with lambda expression. (4) Removed curly braces for one-liner. (5) Replaced Arrays.asList().stream() with Arrays.stream(). (6)Replaced lambda with method reference. (7) Improved list initialization.
  • Loading branch information
chenmliu authored Dec 4, 2019
1 parent 44fa742 commit 5e07302
Show file tree
Hide file tree
Showing 42 changed files with 401 additions and 572 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.azure.search.models.SearchResult;
import com.azure.search.models.SuggestOptions;
import com.azure.search.models.SuggestResult;

import reactor.core.publisher.Mono;

import java.util.List;
Expand Down Expand Up @@ -72,7 +71,6 @@ public DocumentIndexResult uploadDocuments(Iterable<?> documents) {
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing the document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> uploadDocumentsWithResponse(Iterable<?> documents, Context context) {
return asyncClient.uploadDocumentsWithResponse(documents, context).block();
}
Expand All @@ -94,7 +92,6 @@ public DocumentIndexResult mergeDocuments(Iterable<?> documents) {
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing the document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> mergeDocumentsWithResponse(Iterable<?> documents, Context context) {
return asyncClient.mergeDocumentsWithResponse(documents, context).block();
}
Expand All @@ -118,7 +115,6 @@ public DocumentIndexResult mergeOrUploadDocuments(Iterable<?> documents) {
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing a document index result
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> mergeOrUploadDocumentsWithResponse(Iterable<?> documents, Context context) {
return asyncClient.mergeOrUploadDocumentsWithResponse(documents, context).block();
}
Expand All @@ -140,7 +136,6 @@ public DocumentIndexResult deleteDocuments(Iterable<?> documents) {
* @param context additional context that is passed through the Http pipeline during the service call
* @return response containing a document index result.
*/
@SuppressWarnings("unchecked")
public Response<DocumentIndexResult> deleteDocumentsWithResponse(Iterable<?> documents, Context context) {
return asyncClient.deleteDocumentsWithResponse(documents, context).block();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.azure.search.models.TokenInfo;
import org.apache.commons.lang3.StringUtils;
import reactor.core.publisher.Mono;

import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1396,5 +1397,4 @@ private static String deserializeHeaders(HttpHeaders headers) {
entry.getKey() + "," + entry.getValue()
).collect(Collectors.joining(","));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class CreateIndexExample {
* From the Azure portal, get your Azure Cognitive Search service name and API key and
* populate ADMIN_KEY and SEARCH_SERVICE_NAME.
*/
public static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
public static final String SEARCH_SERVICE_NAME = "<Your Search Service Name>";
private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
private static final String SEARCH_SERVICE_NAME = "<Your Search Service Name>";

public static void main(String[] args) {
String endpoint = String.format("https://%s.%s", SEARCH_SERVICE_NAME, "search.windows.net"); // search.windows.net is the default DNS SUFFIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public class DataSourceExample {
*/
private static final String ENDPOINT = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ENDPOINT");
private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
public static final String TABLE_STORAGE_CONNECTION_STRING = "<Your Table Storage connection string>";
public static final String COSMOS_DB_CONNECTION_STRING = "<Your Cosmos DB connection string>";
public static final String BLOB_STORAGE_CONNECTION_STRING = "<Your Blob Storage connection string>";
public static final String SQL_CONNECTION_STRING = "<Your SQL connection string>";
private static final String TABLE_STORAGE_CONNECTION_STRING = "<Your Table Storage connection string>";
private static final String COSMOS_DB_CONNECTION_STRING = "<Your Cosmos DB connection string>";
private static final String BLOB_STORAGE_CONNECTION_STRING = "<Your Blob Storage connection string>";
private static final String SQL_CONNECTION_STRING = "<Your SQL connection string>";

public static void main(String[] args) {
SearchServiceClient client = new SearchServiceClientBuilder()
Expand All @@ -43,7 +43,7 @@ public static void main(String[] args) {
* Store the names of the created data sources so that we can delete them later
* without affecting other resources.
* */
Collection<String> names = new HashSet<String>();
Collection<String> names = new HashSet<>();

names.add(createSqlDataSource(client));
names.add(createCosmosDBDataSource(client));
Expand Down Expand Up @@ -101,9 +101,8 @@ private static String createDataSource(
client.createOrUpdateDataSource(dataSource);
} catch (Exception ex) {
System.err.println(ex.toString());
} finally {
return dataSource.getName();
}
return dataSource.getName();
}

private static String createTableStorageDataSource(SearchServiceClient client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public class IndexAndServiceStatisticsExample {
* From the Azure portal, get your Azure Cognitive Search service name and API key and
* populate ADMIN_KEY and SEARCH_SERVICE_NAME.
*/
public static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
public static final String SEARCH_SERVICE_NAME = "<Your Search Service Name>";
private static final String ADMIN_KEY = Configuration.getGlobalConfiguration().get("AZURE_COGNITIVE_SEARCH_ADMIN_KEY");
private static final String SEARCH_SERVICE_NAME = "<Your Search Service Name>";

public static void main(String[] args) {
SearchServiceClient client = createClient();
Expand Down Expand Up @@ -110,10 +110,9 @@ static void getIndexStatistics(SearchServiceClient client) {
System.out.println("document Count:" + documentCount);
System.out.println("storage Size:" + storageSize);

/** Output:
* document Count:0
* storage Size:0
*/
// Output:
// document Count:0
// storage Size:0
}

/**
Expand Down Expand Up @@ -412,9 +411,9 @@ static Index createTestIndex() {
.setCorsOptions(new CorsOptions()
.setAllowedOrigins("http://tempuri.org", "http://localhost:80")
.setMaxAgeInSeconds(60L))
.setSuggesters(Arrays.asList(new Suggester()
.setSuggesters(Collections.singletonList(new Suggester()
.setName("FancySuggester")
.setSourceFields(Arrays.asList("HotelName"))));
.setSourceFields(Collections.singletonList("HotelName"))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,13 @@ private static void searchResultsFacetsFromPage(SearchIndexAsyncClient searchCli
Map<String, List<FacetResult>> facetResults = results
.byPage()
.take(1)
.map(page -> page.getFacets()).blockLast();
.map(SearchPagedResponse::getFacets).blockLast();

facetResults.forEach((k, v) -> {
v.forEach(result -> {
System.out.println(k + " :");
System.out.println(" count: " + result.getCount());
result.getDocument().forEach((f, d) -> {
System.out.println(" " + f + " : " + d);
});
result.getDocument().forEach((f, d) -> System.out.println(" " + f + " : " + d));
});
});
}
Expand All @@ -82,18 +80,18 @@ private static void searchResultsFacetsFromStream(SearchIndexAsyncClient searchC

Stream<Map<String, List<FacetResult>>> facetsMapStream = results
.byPage()
.map(page -> page.getFacets())
.map(SearchPagedResponse::getFacets)
.toStream();

facetsMapStream.forEach(result -> {
facetsMapStream.forEach(result ->
result.forEach((k, v) -> v.forEach(facetResult -> {
System.out.println(k + " :");
System.out.println(" count: " + facetResult.getCount());
facetResult.getDocument().forEach((f, d) -> {
System.out.println(" " + f + " : " + d);
});
}));
});
facetResult.getDocument().forEach((f, d) ->
System.out.println(" " + f + " : " + d)
);
}))
);
}

private static void searchResultsCoverageFromPage(SearchIndexAsyncClient searchClient) {
Expand All @@ -106,7 +104,7 @@ private static void searchResultsCoverageFromPage(SearchIndexAsyncClient searchC
System.out.println("Coverage = " + results
.byPage()
.take(1)
.map(page -> page.getCoverage()).blockLast());
.map(SearchPagedResponse::getCoverage).blockLast());
}

private static void searchResultsCoverage(SearchIndexAsyncClient searchClient) {
Expand All @@ -118,7 +116,7 @@ private static void searchResultsCoverage(SearchIndexAsyncClient searchClient) {

System.out.println("Coverage = " + results
.byPage()
.map(page -> page.getCoverage()).blockLast());
.map(SearchPagedResponse::getCoverage).blockLast());
}

private static void searchResultsCountFromPage(SearchIndexAsyncClient searchClient) {
Expand All @@ -131,7 +129,7 @@ private static void searchResultsCountFromPage(SearchIndexAsyncClient searchClie

System.out.println("Count = " + results.byPage()
.take(1)
.map(page -> page.getCount()).blockLast());
.map(SearchPagedResponse::getCount).blockLast());
}

private static void searchResultsCountFromStream(SearchIndexAsyncClient searchClient) {
Expand All @@ -142,7 +140,7 @@ private static void searchResultsCountFromStream(SearchIndexAsyncClient searchCl
new SearchOptions().setIncludeTotalResultCount(true),
new RequestOptions());

Stream<Long> countStream = results.byPage().map(page -> page.getCount()).toStream();
Stream<Long> countStream = results.byPage().map(SearchPagedResponse::getCount).toStream();
countStream.forEach(System.out::println);

}
Expand All @@ -154,9 +152,9 @@ private static void searchResultAsStreamOfPagedResponse(SearchIndexAsyncClient s

streamResponse.collect(Collectors.toList()).forEach(searchPagedResponse -> {
List<SearchResult> results = searchPagedResponse.getItems();
results.forEach(result -> {
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)));
});
results.forEach(result ->
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)))
);
});
}

Expand All @@ -165,9 +163,9 @@ private static void searchResultsAsList(SearchIndexAsyncClient searchClient) {
List<SearchResult> searchResults = searchClient.search("*")
.log()
.doOnSubscribe(ignoredVal -> System.out.println("Subscribed to paged flux processing items"))
.doOnNext(result -> {
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)));
})
.doOnNext(result ->
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)))
)
.doOnComplete(() -> System.out.println("Completed processing"))
.collectList().block();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ private static void searchResultsFacets(SearchIndexClient searchClient) {
PagedIterableBase<SearchResult, SearchPagedResponse> results = searchClient.search("*",
new SearchOptions().setFacets("Rooms/BaseRate,values:5|8|10"), new RequestOptions(), Context.NONE);

results.iterableByPage().forEach(page -> {
results.iterableByPage().forEach(page ->
page.getFacets().forEach((k, v) -> {
v.forEach(result -> {
System.out.println(k + " :");
System.out.println(" count: " + result.getCount());
result.getDocument().forEach((f, d) -> {
System.out.println(" " + f + " : " + d);
});
result.getDocument().forEach((f, d) ->
System.out.println(" " + f + " : " + d)
);
});
});
});
})
);
}

private static void searchResultsFacetsFromStream(SearchIndexClient searchClient) {
Expand All @@ -73,17 +73,17 @@ private static void searchResultsFacetsFromStream(SearchIndexClient searchClient
new SearchOptions().setFacets("Rooms/BaseRate,values:5|8|10"), new RequestOptions(), Context.NONE);

Stream<SearchPagedResponse> searchPagedResponseStream = results.streamByPage();
searchPagedResponseStream.forEach(page -> {
searchPagedResponseStream.forEach(page ->
page.getFacets().forEach((k, v) -> {
v.forEach(result -> {
System.out.println(k + " :");
System.out.println(" count: " + result.getCount());
result.getDocument().forEach((f, d) -> {
System.out.println(" " + f + " : " + d);
});
result.getDocument().forEach((f, d) ->
System.out.println(" " + f + " : " + d)
);
});
});
});
})
);
}

private static void searchResultsCoverageFromStream(SearchIndexClient searchClient) {
Expand All @@ -92,9 +92,9 @@ private static void searchResultsCoverageFromStream(SearchIndexClient searchClie
PagedIterableBase<SearchResult, SearchPagedResponse> results = searchClient.search("*",
new SearchOptions().setMinimumCoverage(73.5), new RequestOptions(), Context.NONE);

results.streamByPage().forEach(searchPagedResponse -> {
System.out.println("Coverage = " + searchPagedResponse.getCoverage());
});
results.streamByPage().forEach(searchPagedResponse ->
System.out.println("Coverage = " + searchPagedResponse.getCoverage())
);
}

private static void searchResultsCoverage(SearchIndexClient searchClient) {
Expand All @@ -103,9 +103,9 @@ private static void searchResultsCoverage(SearchIndexClient searchClient) {
PagedIterableBase<SearchResult, SearchPagedResponse> results = searchClient.search("*",
new SearchOptions().setMinimumCoverage(73.5), new RequestOptions(), Context.NONE);

results.iterableByPage().forEach(page -> {
System.out.println("Coverage = " + page.getCoverage());
});
results.iterableByPage().forEach(page ->
System.out.println("Coverage = " + page.getCoverage())
);
}

private static void searchResultsCountFromPage(SearchIndexClient searchClient) {
Expand All @@ -116,9 +116,9 @@ private static void searchResultsCountFromPage(SearchIndexClient searchClient) {
new SearchOptions().setIncludeTotalResultCount(true), new RequestOptions(), Context.NONE);

Iterable<SearchPagedResponse> searchPagedResponses = results.iterableByPage();
searchPagedResponses.forEach(page -> {
System.out.println("Count = " + page.getCount());
});
searchPagedResponses.forEach(page ->
System.out.println("Count = " + page.getCount())
);
}

private static void searchResultsCountFromStream(SearchIndexClient searchClient) {
Expand All @@ -129,24 +129,25 @@ private static void searchResultsCountFromStream(SearchIndexClient searchClient)
new SearchOptions().setIncludeTotalResultCount(true), new RequestOptions(), Context.NONE);

Stream<SearchPagedResponse> searchPagedResponseStream = results.streamByPage();
searchPagedResponseStream.forEach(page -> {
System.out.println("Count = " + page.getCount());
});
searchPagedResponseStream.forEach(page ->
System.out.println("Count = " + page.getCount())
);

}

private static void searchResultAsStream(SearchIndexClient searchClient) {
// Converting search results to stream
PagedIterableBase<SearchResult, SearchPagedResponse> results = searchClient.search("*");
Stream<SearchResult> resultStream = results.stream();
resultStream.forEach(result -> {
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)));
});
resultStream.forEach(result ->
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)))
);
}

private static void searchResultsAsPagedIterable(SearchIndexClient searchClient) {
PagedIterableBase<SearchResult, SearchPagedResponse> results = searchClient.search("*");
results.forEach(result -> {
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)));
});
results.forEach(result ->
result.getDocument().forEach((field, value) -> System.out.println((field + ":" + value)))
);
}
}
Loading

0 comments on commit 5e07302

Please sign in to comment.