Skip to content

Commit 0421912

Browse files
committed
Rename setters/getters/builders for Translate classes to meet proto conventions
1 parent 4142a84 commit 0421912

21 files changed

Lines changed: 157 additions & 71 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,14 +601,14 @@ import com.google.cloud.translate.Translation;
601601
Translate translate = TranslateOptions.defaultInstance().service();
602602
603603
Detection detection = translate.detect("Hola");
604-
String detectedLanguage = detection.language();
604+
String detectedLanguage = detection.getLanguage();
605605
606606
Translation translation = translate.translate(
607607
"World",
608608
TranslateOption.sourceLanguage("en"),
609609
TranslateOption.targetLanguage(detectedLanguage));
610610
611-
System.out.printf("Hola %s%n", translation.translatedText());
611+
System.out.printf("Hola %s%n", translation.getTranslatedText());
612612
```
613613
614614
Troubleshooting

TESTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ key.
285285
that uses the `RemoteTranslateHelper` to list supported languages.
286286
```java
287287
RemoteTranslateHelper translateHelper = RemoteTranslateHelper.create(PROJECT_ID, API_KEY);
288-
Translate translate = translateHelper.options().service();
288+
Translate translate = translateHelper.getOptions().service();
289289
List<Language> languages = translate.listSupportedLanguages();
290290
```
291291

google-cloud-examples/src/main/java/com/google/cloud/examples/translate/snippets/DetectLanguageAndTranslate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ public static void main(String... args) {
4141

4242
// Detect the language of some text
4343
Detection detection = translate.detect("Hola");
44-
String detectedLanguage = detection.language();
44+
String detectedLanguage = detection.getLanguage();
4545

4646
// Translate some text
4747
Translation translation = translate.translate(
4848
"World",
4949
TranslateOption.sourceLanguage("en"),
5050
TranslateOption.targetLanguage(detectedLanguage));
5151

52-
System.out.printf("Hola %s%n", translation.translatedText());
52+
System.out.printf("Hola %s%n", translation.getTranslatedText());
5353
}
5454
}

google-cloud-examples/src/test/java/com/google/cloud/examples/translate/snippets/ITTranslateSnippets.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,16 @@ public class ITTranslateSnippets {
4747
@BeforeClass
4848
public static void beforeClass() {
4949
RemoteTranslateHelper helper = RemoteTranslateHelper.create();
50-
translateSnippets = new TranslateSnippets(helper.options().service());
50+
translateSnippets = new TranslateSnippets(helper.getOptions().service());
5151
}
5252

5353
@Test
5454
public void testListSupportedLanguages() {
5555
Set<String> supportedLanguages = new HashSet<>();
5656
List<Language> languages = translateSnippets.listSupportedLanguages();
5757
for (Language language : languages) {
58-
supportedLanguages.add(language.code());
59-
assertNotNull(language.name());
58+
supportedLanguages.add(language.getCode());
59+
assertNotNull(language.getName());
6060
}
6161
for (String code : LANGUAGES) {
6262
assertTrue(supportedLanguages.contains(code));
@@ -68,8 +68,8 @@ public void testListSupportedLanguagesWithTarget() {
6868
Set<String> supportedLanguages = new HashSet<>();
6969
List<Language> languages = translateSnippets.listSupportedLanguagesWithTarget();
7070
for (Language language : languages) {
71-
supportedLanguages.add(language.code());
72-
assertNotNull(language.name());
71+
supportedLanguages.add(language.getCode());
72+
assertNotNull(language.getName());
7373
}
7474
for (String code : LANGUAGES) {
7575
assertTrue(supportedLanguages.contains(code));
@@ -80,48 +80,48 @@ public void testListSupportedLanguagesWithTarget() {
8080
public void testDetectLanguageOfTexts() {
8181
List<Detection> detections = translateSnippets.detectLanguageOfTexts();
8282
Detection detection = detections.get(0);
83-
assertEquals("en", detection.language());
83+
assertEquals("en", detection.getLanguage());
8484
detection = detections.get(1);
85-
assertEquals("es", detection.language());
85+
assertEquals("es", detection.getLanguage());
8686
}
8787

8888
@Test
8989
public void testDetectLanguageOfTextList() {
9090
List<Detection> detections = translateSnippets.detectLanguageOfTextList();
9191
Detection detection = detections.get(0);
92-
assertEquals("en", detection.language());
92+
assertEquals("en", detection.getLanguage());
9393
detection = detections.get(1);
94-
assertEquals("es", detection.language());
94+
assertEquals("es", detection.getLanguage());
9595
}
9696

9797
@Test
9898
public void testDetectLanguageOfText() {
9999
Detection detection = translateSnippets.detectLanguageOfText();
100-
assertEquals("en", detection.language());
100+
assertEquals("en", detection.getLanguage());
101101
}
102102

103103
@Test
104104
public void testTranslateTextList() {
105105
List<Translation> translations = translateSnippets.translateTexts();
106106
Translation translation = translations.get(0);
107-
assertEquals("Hello, World!", translation.translatedText());
108-
assertEquals("en", translation.sourceLanguage());
107+
assertEquals("Hello, World!", translation.getTranslatedText());
108+
assertEquals("en", translation.getSourceLanguage());
109109
translation = translations.get(1);
110-
assertEquals("Hello World!", translation.translatedText());
111-
assertEquals("es", translation.sourceLanguage());
110+
assertEquals("Hello World!", translation.getTranslatedText());
111+
assertEquals("es", translation.getSourceLanguage());
112112
}
113113

114114
@Test
115115
public void testTranslateText() {
116116
Translation translation = translateSnippets.translateText();
117-
assertEquals("Hello World!", translation.translatedText());
118-
assertEquals("es", translation.sourceLanguage());
117+
assertEquals("Hello World!", translation.getTranslatedText());
118+
assertEquals("es", translation.getSourceLanguage());
119119
}
120120

121121
@Test
122122
public void testTranslateTextWithOptions() {
123123
Translation translation = translateSnippets.translateTextWithOptions();
124-
assertEquals("Hallo Welt!", translation.translatedText());
125-
assertEquals("es", translation.sourceLanguage());
124+
assertEquals("Hallo Welt!", translation.getTranslatedText());
125+
assertEquals("es", translation.getSourceLanguage());
126126
}
127127
}

google-cloud-translate/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import com.google.cloud.translate.Detection;
104104
Then add the following code to detect the text's language:
105105

106106
```java
107-
String detectedLanguage = detection.language();
107+
String detectedLanguage = detection.getLanguage();
108108
```
109109
#### Translating text
110110

google-cloud-translate/src/main/java/com/google/cloud/translate/Detection.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,18 @@ private Detection(String language, Float confidence) {
4747
* @see <a href="https://cloud.google.com/translate/v2/translate-reference#supported_languages">
4848
* Supported Languages</a>
4949
*/
50+
@Deprecated
5051
public String language() {
52+
return getLanguage();
53+
}
54+
55+
/**
56+
* Returns the code of the detected language.
57+
*
58+
* @see <a href="https://cloud.google.com/translate/v2/translate-reference#supported_languages">
59+
* Supported Languages</a>
60+
*/
61+
public String getLanguage() {
5162
return language;
5263
}
5364

@@ -56,7 +67,17 @@ public String language() {
5667
* higher the confidence level for the language detection. Note that this value is not always
5768
* available.
5869
*/
70+
@Deprecated
5971
public float confidence() {
72+
return getConfidence();
73+
}
74+
75+
/**
76+
* Returns an optional confidence value in the interval [0,1]. The closer this value is to 1, the
77+
* higher the confidence level for the language detection. Note that this value is not always
78+
* available.
79+
*/
80+
public float getConfidence() {
6081
return confidence;
6182
}
6283

google-cloud-translate/src/main/java/com/google/cloud/translate/Language.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,30 @@ private Language(String code, String name) {
5454
/**
5555
* Returns the code of the language.
5656
*/
57+
@Deprecated
5758
public String code() {
59+
return getCode();
60+
}
61+
62+
/**
63+
* Returns the code of the language.
64+
*/
65+
public String getCode() {
5866
return code;
5967
}
6068

6169
/**
6270
* Returns the name of the language.
6371
*/
72+
@Deprecated
6473
public String name() {
74+
return getName();
75+
}
76+
77+
/**
78+
* Returns the name of the language.
79+
*/
80+
public String getName() {
6581
return name;
6682
}
6783

google-cloud-translate/src/main/java/com/google/cloud/translate/Option.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ abstract class Option implements Serializable {
3939
this.value = value;
4040
}
4141

42-
TranslateRpc.Option rpcOption() {
42+
TranslateRpc.Option getRpcOption() {
4343
return rpcOption;
4444
}
4545

46-
Object value() {
46+
Object getValue() {
4747
return value;
4848
}
4949

google-cloud-translate/src/main/java/com/google/cloud/translate/Translate.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ public static TranslateOption targetLanguage(String targetLanguage) {
8585

8686
/**
8787
* Returns the list of languages supported by Google Translate. If
88-
* {@link LanguageListOption#targetLanguage(String)} is provided, {@link Language#name()} values
89-
* are localized according to the provided target language. If no such option is passed,
90-
* {@link Language#name()} values are localized according to
88+
* {@link LanguageListOption#targetLanguage(String)} is provided, {@link Language#getName()}
89+
* values are localized according to the provided target language. If no such option is passed,
90+
* {@link Language#getName()} values are localized according to
9191
* {@link TranslateOptions#targetLanguage()}.
9292
*
9393
* <p>Example of listing supported languages, localized according to

google-cloud-translate/src/main/java/com/google/cloud/translate/TranslateImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public Translation translate(String text, TranslateOption... options) {
126126
private Map<TranslateRpc.Option, ?> optionMap(Option... options) {
127127
Map<TranslateRpc.Option, Object> optionMap = Maps.newEnumMap(TranslateRpc.Option.class);
128128
for (Option option : options) {
129-
Object prev = optionMap.put(option.rpcOption(), option.value());
129+
Object prev = optionMap.put(option.getRpcOption(), option.getValue());
130130
checkArgument(prev == null, "Duplicate option %s", option);
131131
}
132132
return optionMap;

0 commit comments

Comments
 (0)