@Override public Translate create(TranslateOptions options) { return new TranslateImpl(options); } }
@Override public List<Detection> detect(String... texts) { return detect(Arrays.asList(texts)); }
@Override public Translation translate(String text, TranslateOption... options) { return translate(Collections.singletonList(text), options).get(0); }
@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)); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()), Language.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<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); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()); 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 Detection detect(String text) { return detect(Collections.singletonList(text)).get(0); }
@Override public Translate create(TranslateOptions options) { return new TranslateImpl(options); } }
@Override public Translation translate(String text, TranslateOption... options) { return translate(Collections.singletonList(text), options).get(0); }
@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<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)); } }, options().retryParams(), EXCEPTION_HANDLER, options().clock()), Translation.FROM_PB_FUNCTION); } catch (RetryHelperException e) { throw TranslateException.translateAndThrow(e); } }
@Override public List<Detection> detect(String... texts) { return detect(Arrays.asList(texts)); }
@Override public Translate create(TranslateOptions options) { return new TranslateImpl(options); } }
@Override public Translation translate(String text, TranslateOption... options) { return translate(Collections.singletonList(text), options).get(0); }
@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<Detection> detect(String... texts) { return detect(Arrays.asList(texts)); }
@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 Detection detect(String text) { return detect(Collections.singletonList(text)).get(0); }
@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); } }