Skip to content

Commit 7f9991b

Browse files
athakoraverikitsch
authored andcommitted
samples: fix checkstyle violations (#285)
1 parent 85b824f commit 7f9991b

13 files changed

+163
-182
lines changed

datalabeling/snippets/src/main/java/com/example/datalabeling/CreateAnnotationSpecSet.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ static void createAnnotationSpecSet(String projectId) throws IOException {
4747
}
4848
// [START datalabeling_create_annotation_spec_set_beta]
4949

50-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
51-
.newBuilder()
52-
// [END datalabeling_create_annotation_spec_set_beta]
53-
.setEndpoint(endpoint)
54-
// [START datalabeling_create_annotation_spec_set_beta]
55-
.build();
50+
DataLabelingServiceSettings settings =
51+
DataLabelingServiceSettings.newBuilder()
52+
// [END datalabeling_create_annotation_spec_set_beta]
53+
.setEndpoint(endpoint)
54+
// [START datalabeling_create_annotation_spec_set_beta]
55+
.build();
5656
try (DataLabelingServiceClient dataLabelingServiceClient =
57-
DataLabelingServiceClient.create(settings)) {
57+
DataLabelingServiceClient.create(settings)) {
5858
ProjectName projectName = ProjectName.of(projectId);
5959

6060
List<AnnotationSpec> annotationSpecs = new ArrayList<>();

datalabeling/snippets/src/main/java/com/example/datalabeling/CreateDataset.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ static void createDataset(String projectId, String datasetName) throws IOExcepti
3838
}
3939
// [START datalabeling_create_dataset_beta]
4040

41-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
42-
.newBuilder()
43-
// [END datalabeling_create_dataset_beta]
44-
.setEndpoint(endpoint)
45-
// [START datalabeling_create_dataset_beta]
46-
.build();
41+
DataLabelingServiceSettings settings =
42+
DataLabelingServiceSettings.newBuilder()
43+
// [END datalabeling_create_dataset_beta]
44+
.setEndpoint(endpoint)
45+
// [START datalabeling_create_dataset_beta]
46+
.build();
4747
try (DataLabelingServiceClient dataLabelingServiceClient =
48-
DataLabelingServiceClient.create(settings)) {
48+
DataLabelingServiceClient.create(settings)) {
4949
ProjectName projectName = ProjectName.of(projectId);
5050

5151
Dataset dataset =

datalabeling/snippets/src/main/java/com/example/datalabeling/CreateInstruction.java

+20-20
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,32 @@ static void createInstruction(String projectId, String pdfUri) throws IOExceptio
4343
}
4444
// [START datalabeling_create_instruction_beta]
4545

46-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
47-
.newBuilder()
48-
// [END datalabeling_create_instruction_beta]
49-
.setEndpoint(endpoint)
50-
// [START datalabeling_create_instruction_beta]
51-
.build();
46+
DataLabelingServiceSettings settings =
47+
DataLabelingServiceSettings.newBuilder()
48+
// [END datalabeling_create_instruction_beta]
49+
.setEndpoint(endpoint)
50+
// [START datalabeling_create_instruction_beta]
51+
.build();
5252
try (DataLabelingServiceClient dataLabelingServiceClient =
53-
DataLabelingServiceClient.create(settings)) {
53+
DataLabelingServiceClient.create(settings)) {
5454
ProjectName projectName = ProjectName.of(projectId);
5555

5656
// There are two types of instructions: CSV (CsvInstruction) or PDF (PdfInstruction)
57-
PdfInstruction pdfInstruction = PdfInstruction.newBuilder()
58-
.setGcsFileUri(pdfUri)
59-
.build();
57+
PdfInstruction pdfInstruction = PdfInstruction.newBuilder().setGcsFileUri(pdfUri).build();
6058

61-
Instruction instruction = Instruction.newBuilder()
62-
.setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME")
63-
.setDescription("YOUR_DESCRIPTION")
64-
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
65-
.setPdfInstruction(pdfInstruction) // .setCsvInstruction() or .setPdfInstruction()
66-
.build();
59+
Instruction instruction =
60+
Instruction.newBuilder()
61+
.setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME")
62+
.setDescription("YOUR_DESCRIPTION")
63+
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
64+
.setPdfInstruction(pdfInstruction) // .setCsvInstruction() or .setPdfInstruction()
65+
.build();
6766

68-
CreateInstructionRequest createInstructionRequest = CreateInstructionRequest.newBuilder()
69-
.setInstruction(instruction)
70-
.setParent(projectName.toString())
71-
.build();
67+
CreateInstructionRequest createInstructionRequest =
68+
CreateInstructionRequest.newBuilder()
69+
.setInstruction(instruction)
70+
.setParent(projectName.toString())
71+
.build();
7272

7373
OperationFuture<Instruction, CreateInstructionMetadata> operation =
7474
dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);

datalabeling/snippets/src/main/java/com/example/datalabeling/ExportData.java

+17-19
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,26 @@ static void exportData(String datasetName, String annotatedDatasetName, String g
5151
}
5252
// [START datalabeling_export_data_beta]
5353

54-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
55-
.newBuilder()
56-
// [END datalabeling_export_data_beta]
57-
.setEndpoint(endpoint)
58-
// [START datalabeling_export_data_beta]
59-
.build();
54+
DataLabelingServiceSettings settings =
55+
DataLabelingServiceSettings.newBuilder()
56+
// [END datalabeling_export_data_beta]
57+
.setEndpoint(endpoint)
58+
// [START datalabeling_export_data_beta]
59+
.build();
6060
try (DataLabelingServiceClient dataLabelingServiceClient =
61-
DataLabelingServiceClient.create(settings)) {
62-
GcsDestination gcsDestination = GcsDestination.newBuilder()
63-
.setOutputUri(gcsOutputUri)
64-
.setMimeType("text/csv")
65-
.build();
61+
DataLabelingServiceClient.create(settings)) {
62+
GcsDestination gcsDestination =
63+
GcsDestination.newBuilder().setOutputUri(gcsOutputUri).setMimeType("text/csv").build();
6664

67-
OutputConfig outputConfig = OutputConfig.newBuilder()
68-
.setGcsDestination(gcsDestination)
69-
.build();
65+
OutputConfig outputConfig =
66+
OutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
7067

71-
ExportDataRequest exportDataRequest = ExportDataRequest.newBuilder()
72-
.setName(datasetName)
73-
.setOutputConfig(outputConfig)
74-
.setAnnotatedDataset(annotatedDatasetName)
75-
.build();
68+
ExportDataRequest exportDataRequest =
69+
ExportDataRequest.newBuilder()
70+
.setName(datasetName)
71+
.setOutputConfig(outputConfig)
72+
.setAnnotatedDataset(annotatedDatasetName)
73+
.build();
7674

7775
OperationFuture<ExportDataOperationResponse, ExportDataOperationMetadata> operation =
7876
dataLabelingServiceClient.exportDataAsync(exportDataRequest);

datalabeling/snippets/src/main/java/com/example/datalabeling/ImportData.java

+16-19
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,25 @@ static void importData(String datasetName, String gcsSourceUri) throws IOExcepti
4444
}
4545
// [START datalabeling_import_data_beta]
4646

47-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
48-
.newBuilder()
49-
// [END datalabeling_import_data_beta]
50-
.setEndpoint(endpoint)
51-
// [START datalabeling_import_data_beta]
52-
.build();
47+
DataLabelingServiceSettings settings =
48+
DataLabelingServiceSettings.newBuilder()
49+
// [END datalabeling_import_data_beta]
50+
.setEndpoint(endpoint)
51+
// [START datalabeling_import_data_beta]
52+
.build();
5353
try (DataLabelingServiceClient dataLabelingServiceClient =
54-
DataLabelingServiceClient.create(settings)) {
55-
GcsSource gcsSource = GcsSource.newBuilder()
56-
.setInputUri(gcsSourceUri)
57-
.setMimeType("text/csv")
58-
.build();
54+
DataLabelingServiceClient.create(settings)) {
55+
GcsSource gcsSource =
56+
GcsSource.newBuilder().setInputUri(gcsSourceUri).setMimeType("text/csv").build();
5957

60-
InputConfig inputConfig = InputConfig.newBuilder()
61-
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
62-
.setGcsSource(gcsSource)
63-
.build();
58+
InputConfig inputConfig =
59+
InputConfig.newBuilder()
60+
.setDataType(DataType.IMAGE) // DataTypes: AUDIO, IMAGE, VIDEO, TEXT
61+
.setGcsSource(gcsSource)
62+
.build();
6463

65-
ImportDataRequest importDataRequest = ImportDataRequest.newBuilder()
66-
.setName(datasetName)
67-
.setInputConfig(inputConfig)
68-
.build();
64+
ImportDataRequest importDataRequest =
65+
ImportDataRequest.newBuilder().setName(datasetName).setInputConfig(inputConfig).build();
6966

7067
OperationFuture<ImportDataOperationResponse, ImportDataOperationMetadata> operation =
7168
dataLabelingServiceClient.importDataAsync(importDataRequest);

datalabeling/snippets/src/main/java/com/example/datalabeling/LabelImage.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class LabelImage {
3636
static void labelImage(
3737
String formattedInstructionName,
3838
String formattedAnnotationSpecSetName,
39-
String formattedDatasetName) throws IOException {
39+
String formattedDatasetName)
40+
throws IOException {
4041
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
4142
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
4243
// String formattedAnnotationSpecSetName =
@@ -52,14 +53,14 @@ static void labelImage(
5253
}
5354
// [START datalabeling_label_image_beta]
5455

55-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
56-
.newBuilder()
57-
// [END datalabeling_label_image_beta]
58-
.setEndpoint(endpoint)
59-
// [START datalabeling_label_image_beta]
60-
.build();
56+
DataLabelingServiceSettings settings =
57+
DataLabelingServiceSettings.newBuilder()
58+
// [END datalabeling_label_image_beta]
59+
.setEndpoint(endpoint)
60+
// [START datalabeling_label_image_beta]
61+
.build();
6162
try (DataLabelingServiceClient dataLabelingServiceClient =
62-
DataLabelingServiceClient.create(settings)) {
63+
DataLabelingServiceClient.create(settings)) {
6364
HumanAnnotationConfig humanAnnotationConfig =
6465
HumanAnnotationConfig.newBuilder()
6566
.setAnnotatedDatasetDisplayName("annotated_displayname")

datalabeling/snippets/src/main/java/com/example/datalabeling/LabelText.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class LabelText {
3636
static void labelText(
3737
String formattedInstructionName,
3838
String formattedAnnotationSpecSetName,
39-
String formattedDatasetName) throws IOException {
39+
String formattedDatasetName)
40+
throws IOException {
4041
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
4142
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
4243
// String formattedAnnotationSpecSetName =
@@ -52,14 +53,14 @@ static void labelText(
5253
}
5354
// [START datalabeling_label_text_beta]
5455

55-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
56-
.newBuilder()
57-
// [END datalabeling_label_text_beta]
58-
.setEndpoint(endpoint)
59-
// [START datalabeling_label_text_beta]
60-
.build();
56+
DataLabelingServiceSettings settings =
57+
DataLabelingServiceSettings.newBuilder()
58+
// [END datalabeling_label_text_beta]
59+
.setEndpoint(endpoint)
60+
// [START datalabeling_label_text_beta]
61+
.build();
6162
try (DataLabelingServiceClient dataLabelingServiceClient =
62-
DataLabelingServiceClient.create(settings)) {
63+
DataLabelingServiceClient.create(settings)) {
6364
HumanAnnotationConfig humanAnnotationConfig =
6465
HumanAnnotationConfig.newBuilder()
6566
.setAnnotatedDatasetDisplayName("annotated_displayname")

datalabeling/snippets/src/main/java/com/example/datalabeling/LabelVideo.java

+35-28
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@
3333
class LabelVideo {
3434

3535
// Start a Video Labeling Task
36-
static void labelVideo(String formattedInstructionName, String formattedAnnotationSpecSetName,
37-
String formattedDatasetName) throws IOException {
36+
static void labelVideo(
37+
String formattedInstructionName,
38+
String formattedAnnotationSpecSetName,
39+
String formattedDatasetName)
40+
throws IOException {
3841
// String formattedInstructionName = DataLabelingServiceClient.formatInstructionName(
3942
// "YOUR_PROJECT_ID", "YOUR_INSTRUCTION_UUID");
4043
// String formattedAnnotationSpecSetName =
@@ -50,36 +53,40 @@ static void labelVideo(String formattedInstructionName, String formattedAnnotati
5053
}
5154
// [START datalabeling_label_video_beta]
5255

53-
DataLabelingServiceSettings settings = DataLabelingServiceSettings
54-
.newBuilder()
55-
// [END datalabeling_label_video_beta]
56-
.setEndpoint(endpoint)
57-
// [START datalabeling_label_video_beta]
58-
.build();
56+
DataLabelingServiceSettings settings =
57+
DataLabelingServiceSettings.newBuilder()
58+
// [END datalabeling_label_video_beta]
59+
.setEndpoint(endpoint)
60+
// [START datalabeling_label_video_beta]
61+
.build();
5962
try (DataLabelingServiceClient dataLabelingServiceClient =
60-
DataLabelingServiceClient.create(settings)) {
61-
HumanAnnotationConfig humanAnnotationConfig = HumanAnnotationConfig.newBuilder()
62-
.setAnnotatedDatasetDisplayName("annotated_displayname")
63-
.setAnnotatedDatasetDescription("annotated_description")
64-
.setInstruction(formattedInstructionName)
65-
.build();
63+
DataLabelingServiceClient.create(settings)) {
64+
HumanAnnotationConfig humanAnnotationConfig =
65+
HumanAnnotationConfig.newBuilder()
66+
.setAnnotatedDatasetDisplayName("annotated_displayname")
67+
.setAnnotatedDatasetDescription("annotated_description")
68+
.setInstruction(formattedInstructionName)
69+
.build();
6670

67-
AnnotationSpecSetConfig annotationSpecSetConfig = AnnotationSpecSetConfig.newBuilder()
68-
.setAnnotationSpecSet(formattedAnnotationSpecSetName)
69-
.setAllowMultiLabel(true)
70-
.build();
71+
AnnotationSpecSetConfig annotationSpecSetConfig =
72+
AnnotationSpecSetConfig.newBuilder()
73+
.setAnnotationSpecSet(formattedAnnotationSpecSetName)
74+
.setAllowMultiLabel(true)
75+
.build();
7176

72-
VideoClassificationConfig videoClassificationConfig = VideoClassificationConfig.newBuilder()
73-
.setApplyShotDetection(true)
74-
.addAnnotationSpecSetConfigs(annotationSpecSetConfig)
75-
.build();
77+
VideoClassificationConfig videoClassificationConfig =
78+
VideoClassificationConfig.newBuilder()
79+
.setApplyShotDetection(true)
80+
.addAnnotationSpecSetConfigs(annotationSpecSetConfig)
81+
.build();
7682

77-
LabelVideoRequest labelVideoRequest = LabelVideoRequest.newBuilder()
78-
.setParent(formattedDatasetName)
79-
.setBasicConfig(humanAnnotationConfig)
80-
.setVideoClassificationConfig(videoClassificationConfig)
81-
.setFeature(Feature.CLASSIFICATION)
82-
.build();
83+
LabelVideoRequest labelVideoRequest =
84+
LabelVideoRequest.newBuilder()
85+
.setParent(formattedDatasetName)
86+
.setBasicConfig(humanAnnotationConfig)
87+
.setVideoClassificationConfig(videoClassificationConfig)
88+
.setFeature(Feature.CLASSIFICATION)
89+
.build();
8390

8491
OperationFuture<AnnotatedDataset, LabelOperationMetadata> operation =
8592
dataLabelingServiceClient.labelVideoAsync(labelVideoRequest);

datalabeling/snippets/src/test/java/com/example/datalabeling/CreateAnnotationSpecSetIT.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@
3434
import org.junit.runner.RunWith;
3535
import org.junit.runners.JUnit4;
3636

37-
/**
38-
* Integration (system) tests for {@link CreateAnnotationSpecSet}.
39-
*/
37+
/** Integration (system) tests for {@link CreateAnnotationSpecSet}. */
4038
@RunWith(JUnit4.class)
4139
@Ignore("b/146064330")
4240
@SuppressWarnings("checkstyle:abbreviationaswordinname")
@@ -60,12 +58,11 @@ public void tearDown() {
6058
// Delete the Annotation Spec Sheet
6159
try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create()) {
6260
ProjectName projectName = ProjectName.of(PROJECT_ID);
63-
ListAnnotationSpecSetsRequest listRequest = ListAnnotationSpecSetsRequest.newBuilder()
64-
.setParent(projectName.toString())
65-
.build();
61+
ListAnnotationSpecSetsRequest listRequest =
62+
ListAnnotationSpecSetsRequest.newBuilder().setParent(projectName.toString()).build();
6663

67-
ListAnnotationSpecSetsPagedResponse response = dataLabelingServiceClient
68-
.listAnnotationSpecSets(listRequest);
64+
ListAnnotationSpecSetsPagedResponse response =
65+
dataLabelingServiceClient.listAnnotationSpecSets(listRequest);
6966

7067
for (AnnotationSpecSet annotationSpecSet : response.getPage().iterateAll()) {
7168
if (annotationSpecSet.getDisplayName().equals("YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME")) {
@@ -83,8 +80,8 @@ public void testCreateAnnotationSpecSet() throws IOException {
8380

8481
String output = bout.toString();
8582

86-
assertThat(output, CoreMatchers.containsString(
87-
"DisplayName: YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME"));
83+
assertThat(
84+
output, CoreMatchers.containsString("DisplayName: YOUR_ANNOTATION_SPEC_SET_DISPLAY_NAME"));
8885
assertThat(output, CoreMatchers.containsString("Description: YOUR_DESCRIPTION"));
8986
assertThat(output, CoreMatchers.containsString("Annotation Count: 2"));
9087
}

0 commit comments

Comments
 (0)