Class TranslationQueue

java.lang.Object
com.iizix.translate.TranslationQueue

public class TranslationQueue extends Object
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 Details Link icon

    • sourceLanguageCode Link icon

      protected final String sourceLanguageCode
      The source language code, null for auto-detect.
    • targetLanguageCode Link icon

      protected final String targetLanguageCode
      The target language code.
    • sourceLanguageDescription Link icon

      protected final String sourceLanguageDescription
      The description of source language.
    • targetLanguageDescription Link icon

      protected final String targetLanguageDescription
      The description of target language.
    • translator Link icon

      protected final ITranslator translator
      The translator.
  • Constructor Details Link icon

    • TranslationQueue Link icon

      protected 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 Link icon

    • addRequest Link icon

      protected boolean addRequest(KString sourceText, ITranslationReply reply)
      Adds a translation request.
      Parameters:
      sourceText - The source text.
      reply - Callback when translation completes.
      Returns:
      true for new request added, false for request already pending.
    • scheduleJobInstance Link icon

      protected void scheduleJobInstance()
      Schedules a new translation job instance if required, called from a synchronized block.

      Override as required.

    • getNext Link icon

      protected KString getNext()
      Gets an item from the queue that needs processing.
      Returns:
      The string to translate, null for no more entries.
    • getAll Link icon

      protected KString[] getAll()
      Gets all current elements in queue, without removing them.
      Returns:
      The string array to translate, null for no more entries.
    • clearJobInstance Link icon

      protected void clearJobInstance()
      Clears the job instance if any, called from a synchronized block.

      Override as required.

    • cancelJob Link icon

      protected void cancelJob()
      Cancels the job instance if any, called from a synchronized block.

      Override as required.

    • cancel Link icon

      protected void cancel()
      Cancels the queue.
    • isCanceled Link icon

      protected boolean isCanceled()
      Checks the cancel state.
    • getQueueElementCount Link icon

      protected int getQueueElementCount()
      Gets the queue translations count.
    • processQueuedElement Link icon

      protected boolean processQueuedElement()
      Processes one element from queue.
      Returns:
      true for success, false for no more elements in queue.
    • onCompleted Link icon

      protected void onCompleted(KString sourceText, Translation translation)
      Informs the queue of a completed translation.
      Parameters:
      sourceText - The source text.
      translation - The translation instance.
    • getTranslatedCount Link icon

      public long getTranslatedCount()
      Gets the count of translated texts in this queue.
      Returns:
      The count of successful translations.
    • deconfigure Link icon

      public void deconfigure()
      Deconfigures the queue and its translator.