Skip to content

Commit 205a65d

Browse files
docs: simplify readme examples and fix use of properties/accessors
1 parent c813500 commit 205a65d

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ class Example {
196196
// document_handle property contains the document handle that may be used to
197197
// later retrieve the document from the server, or contact DeepL support.
198198
DocumentHandle handle = exception.getHandle();
199-
System.out.write(String.format(
199+
System.out.printf(
200200
"Error after uploading %s, document handle: id: %s key: %s",
201201
exception.getMessage(),
202202
handle.getDocumentId(),
203-
handle.getDocumentKey()));
203+
handle.getDocumentKey());
204204
}
205205
}
206206
}
@@ -247,15 +247,15 @@ class Example {
247247
if (usage.anyLimitReached()) {
248248
System.out.println("Translation limit reached.");
249249
}
250-
if (usage.character != null) {
251-
System.out.println(String.format("Character usage: %d of %d",
252-
usage.character.count,
253-
usage.character.count));
250+
if (usage.getCharacter() != null) {
251+
System.out.printf("Character usage: %d of %d%n",
252+
usage.getCharacter().getCount(),
253+
usage.getCharacter().getLimit());
254254
}
255-
if (usage.document != null) {
256-
System.out.println(String.format("Document usage: %d of %d",
257-
usage.document.count,
258-
usage.document.limit));
255+
if (usage.getDocument() != null) {
256+
System.out.printf("Document usage: %d of %d%n",
257+
usage.getDocument().getCount(),
258+
usage.getDocument().getLimit());
259259
}
260260
}
261261
}
@@ -274,29 +274,28 @@ optional `formality` parameter.
274274

275275
```java
276276
class Example {
277-
public void getLanguagesExample() throws Exception {
278-
Language[] sourceLanguages = translator.getSourceLanguages();
279-
Language[] targetLanguages = translator.getTargetLanguages();
277+
public void getLanguagesExample() throws Exception {
278+
List<Language> sourceLanguages = translator.getSourceLanguages();
279+
List<Language> targetLanguages = translator.getTargetLanguages();
280280
System.out.println("Source languages:");
281281
for (Language language : sourceLanguages) {
282-
System.out.println(String.format("%s (%s)",
283-
language.name,
284-
language.code)); // Example: "German (de)"
285-
282+
System.out.printf("%s (%s)%n",
283+
language.getName(),
284+
language.getCode()); // Example: "German (de)"
286285
}
287286

288287
System.out.println("Target languages:");
289288
for (Language language : targetLanguages) {
290-
if (language.supportsFormality) {
291-
System.out.println(String.format("%s (%s) supports formality",
292-
language.name,
293-
language.code)); // Example: "Italian (it) supports formality"
294-
295-
} else {
296-
System.out.println(String.format("%s (%s)",
297-
language.name,
298-
language.code)); // Example: "Lithuanian (lt)"
299-
}
289+
if (language.getSupportsFormality()) {
290+
System.out.printf("%s (%s) supports formality%n",
291+
language.getName(),
292+
language.getCode()); // Example: "Italian (it) supports formality"
293+
294+
} else {
295+
System.out.printf("%s (%s)%n",
296+
language.getName(),
297+
language.getCode()); // Example: "Lithuanian (lt)"
298+
}
300299
}
301300
}
302301
}

0 commit comments

Comments
 (0)