1 package lv.id.jc.piglatin.service;
2
3 import java.util.Locale;
4 import java.util.concurrent.atomic.AtomicInteger;
5 import java.util.function.UnaryOperator;
6
7 import org.springframework.beans.factory.annotation.Qualifier;
8 import org.springframework.stereotype.Service;
9
10
11
12
13 @Service
14 public class TranslationService {
15
16 private final UnaryOperator<String> translator;
17 private final AtomicInteger translationCounter;
18
19 public TranslationService(
20 @Qualifier("phraseTranslator") UnaryOperator<String> translator,
21 @Qualifier("translationCounter") AtomicInteger translationCounter
22 ) {
23 this.translator = translator;
24 this.translationCounter = translationCounter;
25 }
26
27
28
29
30
31
32
33 public String translate(String text) {
34 translationCounter.incrementAndGet();
35 return translator.apply(text.toLowerCase(Locale.ROOT));
36 }
37 }