I have an Enum that contains a list of values. I have a method where I get a text as a parameter. This method, besides going through Enum, breaks the text by words. The main function of the method is to see if there is any word in the text that is equal to some Enum value. The code is below:
public String checkTipo(String texto) {
List<TipoPokemon> lista = Arrays.asList(TipoPokemon.values());
String palavras[] = texto.split(" ");
for(int i=0 ; i < lista.size() ; i++){
for (String palavra : palavras){
String tipo = lista.get(i).getNome();
if (palavra.toLowerCase().equals(tipo)){
return "Olá";
}
}
}
return "";
}
My Enum is:
package br.com.pokemax.modelo;
public enum TipoPokemon {
FIRE("FIRE"),
WATER("WATER"),
GRASS("GRASS"),
ELECTRIC("ELECTRIC"),
ICE("ICE"),
DARK("DARK"),
GHOST("GHOST"),
FAIRY("FAIRY"),
PSYCHIC("PSYCHIC"),
DRAGON("DRAGON"),
POISON("POISON"),
GROUND("GROUND"),
ROCK("ROCK"),
NORMAL("NORMAL"),
BUG("BUG"),
FIGHTING("FIGHTING"),
STEEL("STEEL"),
FLYING("FLYING");
private String nome;
private TipoPokemon(String nome) {
this.nome = nome;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
I'm trying to debug and in the part where I create the variable type , it returns in foreach
and does not check if
, I need to compare word with Enum, can somebody help me ?