Package com.iizix.translate
Class TranslationQueue
java.lang.Object
com.iizix.translate.TranslationQueue
Translation queue object that holds the translations required from one language to another. The queue is enabled to have the same translation multiple times and only queries the translator once. Future implementations could hold a history of the most used ones, etc...
- Author:
- Christopher Mindus
- Field SummaryFieldsModifier and TypeFieldDescription- protected final StringThe source language code, null for auto-detect.- protected final StringThe description of source language.- protected final StringThe target language code.- protected final StringThe description of target language.- protected final ITranslatorThe translator.
- Constructor SummaryConstructorsModifierConstructorDescription- protected- TranslationQueue- (String sourceLanguageCode, String targetLanguageCode, ITranslator translator) Constructor.
- Method SummaryModifier and TypeMethodDescription- protected boolean- addRequest- (KString sourceText, ITranslationReply reply) Adds a translation request.- protected void- cancel()Cancels the queue.- protected voidCancels the job instance if any, called from a synchronized block.- protected voidClears the job instance if any, called from a synchronized block.- voidDeconfigures the queue and its translator.- protected KString[]- getAll()Gets all current elements in queue, without removing them.- protected KString- getNext()Gets an item from the queue that needs processing.- protected intGets the queue translations count.- longGets the count of translated texts in this queue.- protected booleanChecks the cancel state.- protected void- onCompleted- (KString sourceText, Translation translation) Informs the queue of a completed translation.- protected booleanProcesses one element from queue.- protected voidSchedules a new translation job instance if required, called from a synchronized block.
- Field Details- sourceLanguageCodeThe source language code, null for auto-detect.
- targetLanguageCodeThe target language code.
- sourceLanguageDescriptionThe description of source language.
- targetLanguageDescriptionThe description of target language.
- translatorThe translator.
 
- Constructor Details- TranslationQueueprotected TranslationQueue- (String sourceLanguageCode, String targetLanguageCode, ITranslator translator) Constructor.- Parameters:
- sourceLanguageCode- The source language code, null for auto-detect.
- targetLanguageCode- The target language code.
- translator- The translator.
 
 
- Method Details- addRequestAdds a translation request.- Parameters:
- sourceText- The source text.
- reply- Callback when translation completes.
- Returns:
- true for new request added, false for request already pending.
 
- scheduleJobInstanceprotected void scheduleJobInstance()Schedules a new translation job instance if required, called from a synchronized block.- Override as required. 
- getNextGets an item from the queue that needs processing.- Returns:
- The string to translate, null for no more entries.
 
- getAllGets all current elements in queue, without removing them.- Returns:
- The string array to translate, null for no more entries.
 
- clearJobInstanceprotected void clearJobInstance()Clears the job instance if any, called from a synchronized block.- Override as required. 
- cancelJobprotected void cancelJob()Cancels the job instance if any, called from a synchronized block.- Override as required. 
- cancelprotected void cancel()Cancels the queue.
- isCanceledprotected boolean isCanceled()Checks the cancel state.
- getQueueElementCountprotected int getQueueElementCount()Gets the queue translations count.
- processQueuedElementprotected boolean processQueuedElement()Processes one element from queue.- Returns:
- true for success, false for no more elements in queue.
 
- onCompletedInforms the queue of a completed translation.- Parameters:
- sourceText- The source text.
- translation- The translation instance.
 
- getTranslatedCountpublic long getTranslatedCount()Gets the count of translated texts in this queue.- Returns:
- The count of successful translations.
 
- deconfigurepublic void deconfigure()Deconfigures the queue and its translator.