use of com.google.cloud.devtools.containeranalysis.v1alpha1.PagedResponseWrappers.ListNoteOccurrencesPagedResponse in project java-docs-samples by GoogleCloudPlatform.
the class Samples method getOccurrencesForNote.
// [END discovery_info]
// [START occurrences_for_note]
/**
* Retrieves all the occurrences associated with a specified note
*
* @param noteId the note's unique identifier
* @param projectId the project's unique identifier
* @return number of occurrences found
* @throws Exception on errors while closing the client
*/
public static int getOccurrencesForNote(String noteId, String projectId) throws Exception {
try (ContainerAnalysisClient client = ContainerAnalysisClient.create()) {
final String parentNoteName = client.formatNoteName(projectId, noteId);
int i = 0;
ListNoteOccurrencesPagedResponse response = client.listNoteOccurrences(parentNoteName);
for (Occurrence o : response.iterateAll()) {
// print and count each occurrence found
System.out.println(o.getName());
i = i + 1;
}
return i;
}
}
Aggregations