-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f4965d
commit b52c576
Showing
8 changed files
with
136 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 31 additions & 41 deletions
72
src/main/java/io/github/brenoepics/at4j/data/response/TranslationResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,66 @@ | ||
package io.github.brenoepics.at4j.data.response; | ||
|
||
import io.github.brenoepics.at4j.data.DetectedLanguage; | ||
import io.github.brenoepics.at4j.data.Translation; | ||
|
||
import java.util.Collection; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* This class represents a response from a translation service. It contains the detected language of | ||
* the input and a collection of translations. | ||
* This class represents a response that contains a list of translation results. | ||
*/ | ||
public class TranslationResponse { | ||
// List to store the translation results | ||
private final List<TranslationResult> resultList; | ||
|
||
/** | ||
* The detected language of the input text. It can be null if the language could not be detected. | ||
* | ||
* @see DetectedLanguage | ||
* Default constructor that initializes an empty list of translation results. | ||
*/ | ||
private DetectedLanguage detectedLanguage = null; | ||
|
||
private final String baseText; | ||
|
||
// A collection of translations for the input text. | ||
private final Collection<Translation> translations; | ||
public TranslationResponse() { | ||
resultList = new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Constructs a TranslationResponse with a detected language and a collection of translations. | ||
* Constructor that initializes the list of translation results with the provided list. | ||
* | ||
* @param detectedLanguage The detected language of the input text. | ||
* @param translations A collection of translations for the input text. | ||
* @param results The list of translation results to be stored. | ||
*/ | ||
public TranslationResponse( | ||
String baseText, DetectedLanguage detectedLanguage, Collection<Translation> translations) { | ||
this.baseText = baseText; | ||
this.detectedLanguage = detectedLanguage; | ||
this.translations = translations; | ||
public TranslationResponse(List<TranslationResult> results) { | ||
resultList = results; | ||
} | ||
|
||
/** | ||
* Constructs a TranslationResponse with a collection of translations. The detected language is | ||
* set to null. | ||
* Method to add a translation result to the list. | ||
* | ||
* @param translations A collection of translations for the input text. | ||
* @param result The translation result to be added. | ||
*/ | ||
public TranslationResponse(String baseText, Collection<Translation> translations) { | ||
this.baseText = baseText; | ||
this.translations = translations; | ||
public void addResult(TranslationResult result) { | ||
resultList.add(result); | ||
} | ||
|
||
/** | ||
* Returns the detected language of the input text. | ||
* Method to retrieve the list of translation results. | ||
* | ||
* @return The detected language of the input text. | ||
* @return The list of translation results. | ||
*/ | ||
public DetectedLanguage getDetectedLanguage() { | ||
return detectedLanguage; | ||
public List<TranslationResult> getResultList() { | ||
return resultList; | ||
} | ||
|
||
/** | ||
* Returns the collection of translations for the input text. | ||
* Static factory method to create a new TranslationResponse with the provided list of results. | ||
* | ||
* @return The collection of translations for the input text. | ||
* @param results The list of translation results to be stored. | ||
* @return A new TranslationResponse instance. | ||
*/ | ||
public Collection<Translation> getTranslations() { | ||
return translations; | ||
public static TranslationResponse of(List<TranslationResult> results) { | ||
return new TranslationResponse(results); | ||
} | ||
|
||
/** | ||
* Returns the base texts that were translated | ||
* Static factory method to create a new TranslationResponse with the provided result. | ||
* | ||
* @return the base text | ||
* @param result The translation result to be stored. | ||
* @return A new TranslationResponse instance. | ||
*/ | ||
public String getBaseText() { | ||
return baseText; | ||
public static TranslationResponse of(TranslationResult result) { | ||
return new TranslationResponse(List.of(result)); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/io/github/brenoepics/at4j/data/response/TranslationResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package io.github.brenoepics.at4j.data.response; | ||
|
||
import io.github.brenoepics.at4j.data.DetectedLanguage; | ||
import io.github.brenoepics.at4j.data.Translation; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* This class represents a response from a translation service. It contains the detected language of | ||
* the input and a collection of translations. | ||
*/ | ||
public class TranslationResult { | ||
|
||
/** | ||
* The detected language of the input text. It can be null if the language could not be detected. | ||
* | ||
* @see DetectedLanguage | ||
*/ | ||
private DetectedLanguage detectedLanguage = null; | ||
|
||
private final String baseText; | ||
|
||
// A collection of translations for the input text. | ||
private final Collection<Translation> translations; | ||
|
||
/** | ||
* Constructs a TranslationResponse with a detected language and a collection of translations. | ||
* | ||
* @param detectedLanguage The detected language of the input text. | ||
* @param translations A collection of translations for the input text. | ||
*/ | ||
public TranslationResult( | ||
String baseText, DetectedLanguage detectedLanguage, Collection<Translation> translations) { | ||
this.baseText = baseText; | ||
this.detectedLanguage = detectedLanguage; | ||
this.translations = translations; | ||
} | ||
|
||
/** | ||
* Constructs a TranslationResponse with a collection of translations. The detected language is | ||
* set to null. | ||
* | ||
* @param translations A collection of translations for the input text. | ||
*/ | ||
public TranslationResult(String baseText, Collection<Translation> translations) { | ||
this.baseText = baseText; | ||
this.translations = translations; | ||
} | ||
|
||
/** | ||
* Returns the detected language of the input text. | ||
* | ||
* @return The detected language of the input text. | ||
*/ | ||
public DetectedLanguage getDetectedLanguage() { | ||
return detectedLanguage; | ||
} | ||
|
||
/** | ||
* Returns the collection of translations for the input text. | ||
* | ||
* @return The collection of translations for the input text. | ||
*/ | ||
public Collection<Translation> getTranslations() { | ||
return translations; | ||
} | ||
|
||
/** | ||
* Returns the base texts that were translated | ||
* | ||
* @return the base text | ||
*/ | ||
public String getBaseText() { | ||
return baseText; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters