@Override public List<Detection> detect(final List<String> texts) { try { List<List<DetectionsResourceItems>> detectionsPb = runWithRetries( new Callable<List<List<DetectionsResourceItems>>>() { @Override public List<List<DetectionsResourceItems>> call() { return translateRpc.detect(texts); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); Iterator<List<DetectionsResourceItems>> detectionIterator = detectionsPb.iterator(); Iterator<String> textIterator = texts.iterator(); while (detectionIterator.hasNext() && textIterator.hasNext()) { List<DetectionsResourceItems> detectionPb = detectionIterator.next(); String text = textIterator.next(); checkState( detectionPb != null && !detectionPb.isEmpty(), "No detection found for text: %s", text); checkState(detectionPb.size() == 1, "Multiple detections found for text: %s", text); } return Lists.transform(detectionsPb, DETECTION_FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Language> listSupportedLanguages(final LanguageListOption... options) { try { return Lists.transform( runWithRetries( new Callable<List<LanguagesResource>>() { @Override public List<LanguagesResource> call() { return translateRpc.listSupportedLanguages(optionMap(options)); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()), Language.FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Translation> translate(final List<String> texts, final TranslateOption... options) { try { return Lists.transform( runWithRetries( new Callable<List<TranslationsResource>>() { @Override public List<TranslationsResource> call() { return translateRpc.translate(texts, optionMap(options)); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()), Translation.FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Detection> detect(final List<String> texts) { try { List<List<DetectionsResourceItems>> detectionsPb = runWithRetries( new Callable<List<List<DetectionsResourceItems>>>() { @Override public List<List<DetectionsResourceItems>> call() { return translateRpc.detect(texts); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); Iterator<List<DetectionsResourceItems>> detectionIterator = detectionsPb.iterator(); Iterator<String> textIterator = texts.iterator(); while (detectionIterator.hasNext() && textIterator.hasNext()) { List<DetectionsResourceItems> detectionPb = detectionIterator.next(); String text = textIterator.next(); checkState( detectionPb != null && !detectionPb.isEmpty(), "No detection found for text: %s", text); checkState(detectionPb.size() == 1, "Multiple detections found for text: %s", text); } return Lists.transform(detectionsPb, DETECTION_FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Language> listSupportedLanguages(final LanguageListOption... options) { try { return Lists.transform( runWithRetries( new Callable<List<LanguagesResource>>() { @Override public List<LanguagesResource> call() { return translateRpc.listSupportedLanguages(optionMap(options)); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()), Language.FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Translation> translate(final List<String> texts, final TranslateOption... options) { try { return Lists.transform( runWithRetries( new Callable<List<TranslationsResource>>() { @Override public List<TranslationsResource> call() { return translateRpc.translate(texts, optionMap(options)); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()), Translation.FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }