package fr.epita.assistants; import fr.epita.assistants.utils.StringInfo; import io.smallrye.reactive.messaging.annotations.Broadcast; import org.eclipse.microprofile.reactive.messaging.Incoming; import org.eclipse.microprofile.reactive.messaging.Outgoing; public class StringInfoProcessor { private boolean isPalindrome(String word) { if (word == null) return false; word = word.toLowerCase().strip(); if (word.isEmpty()) return true; for (int i = 0, j = word.length() - 1; i < j; i++, j--) { while (word.charAt(i) == ' ') { i++; } while (word.charAt(j) == ' ') { j--; } if (word.charAt(i) != word.charAt(j)) return false; } return true; } @Incoming("string-info-command") @Outgoing("string-info-aggregate") @Broadcast public StringInfo process(String s) { String tmp = s.toLowerCase(); int v = 0; int c = 0; for (int i = 0; i < tmp.length(); i++) { if (tmp.charAt(i) == 'a' || tmp.charAt(i) == 'e' || tmp.charAt(i) == 'i' || tmp.charAt(i) == 'o' || tmp.charAt(i) == 'u' || tmp.charAt(i) == 'y') v++; else if (tmp.charAt(i) <= 'z' && tmp.charAt(i) >= 'a') c++; } return new StringInfo(s, v, c, isPalindrome(s)); } }