Skip to content

Commit b3473ce

Browse files
committed
style(examples): Standardize formatting
1 parent bbb3cfc commit b3473ce

File tree

5 files changed

+165
-169
lines changed

5 files changed

+165
-169
lines changed

examples/src/main/java/com/ibm/watson/developer_cloud/assistant/v1/tone_analyzer_integration/AssistantToneAnalyzerIntegrationExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static void main(String[] args) throws Exception {
3434
assistantService.setUsernameAndPassword("<username>", "<password>");
3535

3636
// instantiate the tone analyzer service
37-
ToneAnalyzer toneService = new ToneAnalyzer("2017-09-21);
37+
ToneAnalyzer toneService = new ToneAnalyzer("2017-09-21");
3838
toneService.setUsernameAndPassword("<username>", "<password>");
3939

4040
// workspace id

examples/src/main/java/com/ibm/watson/developer_cloud/discovery/v1/DiscoveryQueryExample.java

Lines changed: 137 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -45,148 +45,148 @@
4545
* End-to-end example for querying Discovery.
4646
*/
4747
public class DiscoveryQueryExample {
48-
private static final String DEFAULT_CONFIG_NAME = "Default Configuration";
49-
50-
public static void main(String[] args) {
51-
Discovery discovery = new Discovery("2017-11-07");
52-
discovery.setEndPoint("https://gateway.watsonplatform.net/discovery/api");
53-
discovery.setUsernameAndPassword("<username>", "<password");
54-
String environmentId = null;
55-
String configurationId = null;
56-
String collectionId = null;
57-
String documentId = null;
58-
59-
//See if an environment already exists
60-
System.out.println("Check if environment exists");
61-
ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
62-
ListEnvironmentsResponse listResponse = discovery.listEnvironments(listOptions).execute();
63-
for (Environment environment : listResponse.getEnvironments()) {
64-
//look for an existing environment that isn't read only
65-
if (!environment.isReadOnly()) {
66-
environmentId = environment.getEnvironmentId();
67-
System.out.println("Found existing environment ID: " + environmentId);
68-
break;
69-
}
70-
}
48+
private static final String DEFAULT_CONFIG_NAME = "Default Configuration";
49+
50+
public static void main(String[] args) {
51+
Discovery discovery = new Discovery("2017-11-07");
52+
discovery.setEndPoint("https://gateway.watsonplatform.net/discovery/api");
53+
discovery.setUsernameAndPassword("<username>", "<password");
54+
String environmentId = null;
55+
String configurationId = null;
56+
String collectionId = null;
57+
String documentId = null;
58+
59+
//See if an environment already exists
60+
System.out.println("Check if environment exists");
61+
ListEnvironmentsOptions listOptions = new ListEnvironmentsOptions.Builder().build();
62+
ListEnvironmentsResponse listResponse = discovery.listEnvironments(listOptions).execute();
63+
for (Environment environment : listResponse.getEnvironments()) {
64+
//look for an existing environment that isn't read only
65+
if (!environment.isReadOnly()) {
66+
environmentId = environment.getEnvironmentId();
67+
System.out.println("Found existing environment ID: " + environmentId);
68+
break;
69+
}
70+
}
7171

72-
if (environmentId == null) {
73-
System.out.println("No environment found, creating new one...");
74-
//no environment found, create a new one (assuming we are a FREE plan)
75-
String environmentName = "watson_developer_cloud_test_environment";
76-
CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder()
77-
.name(environmentName)
78-
.size(0L) /* FREE */
79-
.build();
80-
Environment createResponse = discovery.createEnvironment(createOptions).execute();
81-
environmentId = createResponse.getEnvironmentId();
82-
System.out.println("Created new environment ID: " + environmentId);
83-
84-
//wait for environment to be ready
85-
System.out.println("Waiting for environment to be ready...");
86-
boolean environmentReady = false;
87-
while (!environmentReady) {
88-
GetEnvironmentOptions getEnvironmentOptions = new GetEnvironmentOptions.Builder(environmentId).build();
89-
Environment getEnvironmentResponse = discovery.getEnvironment(getEnvironmentOptions).execute();
90-
environmentReady = getEnvironmentResponse.getStatus().equals(Environment.Status.ACTIVE);
91-
try {
92-
if (!environmentReady) {
93-
Thread.sleep(500);
94-
}
95-
} catch (InterruptedException e) {
96-
throw new RuntimeException("Interrupted", e);
97-
}
98-
}
99-
System.out.println("Environment Ready!");
72+
if (environmentId == null) {
73+
System.out.println("No environment found, creating new one...");
74+
//no environment found, create a new one (assuming we are a FREE plan)
75+
String environmentName = "watson_developer_cloud_test_environment";
76+
CreateEnvironmentOptions createOptions = new CreateEnvironmentOptions.Builder()
77+
.name(environmentName)
78+
.size(0L) /* FREE */
79+
.build();
80+
Environment createResponse = discovery.createEnvironment(createOptions).execute();
81+
environmentId = createResponse.getEnvironmentId();
82+
System.out.println("Created new environment ID: " + environmentId);
83+
84+
//wait for environment to be ready
85+
System.out.println("Waiting for environment to be ready...");
86+
boolean environmentReady = false;
87+
while (!environmentReady) {
88+
GetEnvironmentOptions getEnvironmentOptions = new GetEnvironmentOptions.Builder(environmentId).build();
89+
Environment getEnvironmentResponse = discovery.getEnvironment(getEnvironmentOptions).execute();
90+
environmentReady = getEnvironmentResponse.getStatus().equals(Environment.Status.ACTIVE);
91+
try {
92+
if (!environmentReady) {
93+
Thread.sleep(500);
94+
}
95+
} catch (InterruptedException e) {
96+
throw new RuntimeException("Interrupted", e);
10097
}
98+
}
99+
System.out.println("Environment Ready!");
100+
}
101101

102-
//find the default configuration
103-
System.out.println("Finding the default configuration");
104-
ListConfigurationsOptions listConfigsOptions = new ListConfigurationsOptions.Builder(environmentId).build();
105-
ListConfigurationsResponse listConfigsResponse = discovery.listConfigurations(listConfigsOptions).execute();
106-
for (Configuration configuration : listConfigsResponse.getConfigurations()) {
107-
if (configuration.getName().equals(DEFAULT_CONFIG_NAME)) {
108-
configurationId = configuration.getConfigurationId();
109-
System.out.println("Found default configuration ID: " + configurationId);
110-
break;
111-
}
112-
}
102+
//find the default configuration
103+
System.out.println("Finding the default configuration");
104+
ListConfigurationsOptions listConfigsOptions = new ListConfigurationsOptions.Builder(environmentId).build();
105+
ListConfigurationsResponse listConfigsResponse = discovery.listConfigurations(listConfigsOptions).execute();
106+
for (Configuration configuration : listConfigsResponse.getConfigurations()) {
107+
if (configuration.getName().equals(DEFAULT_CONFIG_NAME)) {
108+
configurationId = configuration.getConfigurationId();
109+
System.out.println("Found default configuration ID: " + configurationId);
110+
break;
111+
}
112+
}
113113

114-
//create a new collection
115-
System.out.println("Creating a new collection...");
116-
String collectionName = "my_watson_developer_cloud_collection";
117-
CreateCollectionOptions createCollectionOptions =
118-
new CreateCollectionOptions.Builder(environmentId, collectionName)
119-
.configurationId(configurationId)
120-
.build();
121-
Collection collection = discovery.createCollection(createCollectionOptions).execute();
122-
collectionId = collection.getCollectionId();
123-
System.out.println("Created a collection ID: " + collectionId);
124-
125-
//wait for the collection to be "available"
126-
System.out.println("Waiting for collection to be ready...");
127-
boolean collectionReady = false;
128-
while (!collectionReady) {
129-
GetCollectionOptions getCollectionOptions =
130-
new GetCollectionOptions.Builder(environmentId, collectionId).build();
131-
Collection getCollectionResponse = discovery.getCollection(getCollectionOptions).execute();
132-
collectionReady = getCollectionResponse.getStatus().equals(Collection.Status.ACTIVE);
133-
try {
134-
if (!collectionReady) {
135-
Thread.sleep(500);
136-
}
137-
} catch (InterruptedException e) {
138-
throw new RuntimeException("Interrupted", e);
139-
}
114+
//create a new collection
115+
System.out.println("Creating a new collection...");
116+
String collectionName = "my_watson_developer_cloud_collection";
117+
CreateCollectionOptions createCollectionOptions =
118+
new CreateCollectionOptions.Builder(environmentId, collectionName)
119+
.configurationId(configurationId)
120+
.build();
121+
Collection collection = discovery.createCollection(createCollectionOptions).execute();
122+
collectionId = collection.getCollectionId();
123+
System.out.println("Created a collection ID: " + collectionId);
124+
125+
//wait for the collection to be "available"
126+
System.out.println("Waiting for collection to be ready...");
127+
boolean collectionReady = false;
128+
while (!collectionReady) {
129+
GetCollectionOptions getCollectionOptions =
130+
new GetCollectionOptions.Builder(environmentId, collectionId).build();
131+
Collection getCollectionResponse = discovery.getCollection(getCollectionOptions).execute();
132+
collectionReady = getCollectionResponse.getStatus().equals(Collection.Status.ACTIVE);
133+
try {
134+
if (!collectionReady) {
135+
Thread.sleep(500);
140136
}
141-
System.out.println("Collection Ready!");
142-
143-
//add a document
144-
System.out.println("Creating a new document...");
145-
String documentJson = "{\"field\":\"value\"}";
146-
InputStream documentStream = new ByteArrayInputStream(documentJson.getBytes());
147-
148-
AddDocumentOptions.Builder createDocumentBuilder =
149-
new AddDocumentOptions.Builder(environmentId, collectionId);
150-
createDocumentBuilder.file(documentStream).fileMediaType(HttpMediaType.APPLICATION_JSON);
151-
DocumentAccepted createDocumentResponse = discovery.addDocument(createDocumentBuilder.build()).execute();
152-
documentId = createDocumentResponse.getDocumentId();
153-
System.out.println("Created a document ID: " + documentId);
154-
155-
//wait for document to be ready
156-
System.out.println("Waiting for document to be ready...");
157-
boolean documentReady = false;
158-
while (!documentReady) {
159-
GetDocumentStatusOptions getDocumentStatusOptions =
160-
new GetDocumentStatusOptions.Builder(environmentId, collectionId, documentId).build();
161-
DocumentStatus getDocumentResponse = discovery.getDocument(getDocumentStatusOptions).execute();
162-
documentReady = !getDocumentResponse.getStatus().equals(DocumentStatus.Status.PROCESSING);
163-
try {
164-
if (!documentReady) {
165-
Thread.sleep(500);
166-
}
167-
} catch (InterruptedException e) {
168-
throw new RuntimeException("Interrupted");
169-
}
137+
} catch (InterruptedException e) {
138+
throw new RuntimeException("Interrupted", e);
139+
}
140+
}
141+
System.out.println("Collection Ready!");
142+
143+
//add a document
144+
System.out.println("Creating a new document...");
145+
String documentJson = "{\"field\":\"value\"}";
146+
InputStream documentStream = new ByteArrayInputStream(documentJson.getBytes());
147+
148+
AddDocumentOptions.Builder createDocumentBuilder =
149+
new AddDocumentOptions.Builder(environmentId, collectionId);
150+
createDocumentBuilder.file(documentStream).fileMediaType(HttpMediaType.APPLICATION_JSON);
151+
DocumentAccepted createDocumentResponse = discovery.addDocument(createDocumentBuilder.build()).execute();
152+
documentId = createDocumentResponse.getDocumentId();
153+
System.out.println("Created a document ID: " + documentId);
154+
155+
//wait for document to be ready
156+
System.out.println("Waiting for document to be ready...");
157+
boolean documentReady = false;
158+
while (!documentReady) {
159+
GetDocumentStatusOptions getDocumentStatusOptions =
160+
new GetDocumentStatusOptions.Builder(environmentId, collectionId, documentId).build();
161+
DocumentStatus getDocumentResponse = discovery.getDocument(getDocumentStatusOptions).execute();
162+
documentReady = !getDocumentResponse.getStatus().equals(DocumentStatus.Status.PROCESSING);
163+
try {
164+
if (!documentReady) {
165+
Thread.sleep(500);
170166
}
171-
System.out.println("Document Ready!");
172-
173-
//query document
174-
System.out.println("Querying the collection...");
175-
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
176-
queryBuilder.query("field:value");
177-
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
178-
179-
//print out the results
180-
System.out.println("Query Results:");
181-
System.out.println(queryResponse);
182-
183-
//cleanup the collection created
184-
System.out.println("Deleting the collection...");
185-
DeleteCollectionOptions deleteOptions =
186-
new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
187-
discovery.deleteCollection(deleteOptions).execute();
188-
System.out.println("Collection deleted!");
189-
190-
System.out.println("Discovery example finished");
167+
} catch (InterruptedException e) {
168+
throw new RuntimeException("Interrupted");
169+
}
191170
}
171+
System.out.println("Document Ready!");
172+
173+
//query document
174+
System.out.println("Querying the collection...");
175+
QueryOptions.Builder queryBuilder = new QueryOptions.Builder(environmentId, collectionId);
176+
queryBuilder.query("field:value");
177+
QueryResponse queryResponse = discovery.query(queryBuilder.build()).execute();
178+
179+
//print out the results
180+
System.out.println("Query Results:");
181+
System.out.println(queryResponse);
182+
183+
//cleanup the collection created
184+
System.out.println("Deleting the collection...");
185+
DeleteCollectionOptions deleteOptions =
186+
new DeleteCollectionOptions.Builder(environmentId, collectionId).build();
187+
discovery.deleteCollection(deleteOptions).execute();
188+
System.out.println("Collection deleted!");
189+
190+
System.out.println("Discovery example finished");
191+
}
192192
}

examples/src/main/java/com/ibm/watson/developer_cloud/text_to_speech/v1/TextToSpeechExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
public class TextToSpeechExample {
1818

19-
2019
public static void main(String[] args) {
2120
TextToSpeech service = new TextToSpeech();
2221
service.setUsernameAndPassword("<username>", "<password>");

examples/src/main/java/com/ibm/watson/developer_cloud/tone_analyzer/v3/ToneAnalyzerChatExample.java

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,33 @@
2121

2222
public class ToneAnalyzerExample {
2323

24-
25-
public static void main(String[] args) {
26-
ToneAnalyzer service = new ToneAnalyzer("2017-09-21");
27-
service.setUsernameAndPassword("<username>", "<password>");
28-
29-
String[] texts = {
30-
"My charger isn't working.",
31-
"Thanks for reaching out. Can you give me some more detail about the issue?",
32-
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
33-
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
34-
+ "Which is ridiculous, it's brand new.",
35-
"I'm sorry you're having issues with charging. What kind of charger are you using?"
36-
};
37-
38-
List<Utterance> utterances = new ArrayList<>();
39-
for (int i = 0; i < texts.length; i++) {
40-
Utterance utterance = new Utterance.Builder()
41-
.text(texts[i])
42-
.user(users[i])
43-
.build();
44-
utterances.add(utterance);
45-
}
46-
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder()
47-
.utterances(utterances)
24+
public static void main(String[] args) {
25+
ToneAnalyzer service = new ToneAnalyzer("2017-09-21");
26+
service.setUsernameAndPassword("<username>", "<password>");
27+
28+
String[] texts = {
29+
"My charger isn't working.",
30+
"Thanks for reaching out. Can you give me some more detail about the issue?",
31+
"I put my charger in my tablet to charge it up last night and it keeps saying it isn't"
32+
+ " charging. The charging icon comes on, but it stays on even when I take the charger out. "
33+
+ "Which is ridiculous, it's brand new.",
34+
"I'm sorry you're having issues with charging. What kind of charger are you using?"
35+
};
36+
37+
List<Utterance> utterances = new ArrayList<>();
38+
for (int i = 0; i < texts.length; i++) {
39+
Utterance utterance = new Utterance.Builder()
40+
.text(texts[i])
41+
.user(users[i])
4842
.build();
49-
50-
// Call the service
51-
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
52-
System.out.println(utterancesTone);
53-
43+
utterances.add(utterance);
5444
}
45+
ToneChatOptions toneChatOptions = new ToneChatOptions.Builder()
46+
.utterances(utterances)
47+
.build();
48+
49+
// Call the service
50+
UtteranceAnalyses utterancesTone = service.toneChat(toneChatOptions).execute();
51+
System.out.println(utterancesTone);
52+
}
5553
}

examples/src/main/java/com/ibm/watson/developer_cloud/visual_recognition/v3/VisualRecognitionExample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,5 @@ public static void main(String[] args) {
6161
.build();
6262
Classifier updatedFoo = service.updateClassifier(updateOptions).execute();
6363
System.out.println(updatedFoo);
64-
6564
}
6665
}

0 commit comments

Comments
 (0)