class Pokemon {
public enum Tipo {
FIRE, WATER, ICE, ELECTRIC, GRASS, DARK, BUG, GHOST, ROCK, FAIRY, GROUND, DRAGON, PSYCHIC, POISON, NORMAL, FIGHTING, STEEL, FLYING;
}
for ( Tipo tipo : Tipo.values ( ) ) {
String classe
= tipo.
name ( ) .
toLowerCase ( ) ;
// (?i) é uma expressão regular para ignorar o case das palavras. Por exemplo: Irá encontrar Electric, ELECTRIC e electric
// Os parênteses indicam um grupo, que será utilizado na segunda parte do replace com $ + a posição desse grupo
// o | é uma cláusula OU na expressão regular, ou seja, irá procurar electric-type e electric também
texto = texto.replaceAll ( "(?i)(" + classe + "-type|" + classe + ")" , "<span class=\" tipo-pokemon " + classe + "\" >$1</span>" ) ;
}
return texto;
}
public static void main
( String [ ] args
) { Pokemon pokemon = new Pokemon( ) ;
System .
out .
println ( pokemon.
substituir ( "Electric-type: Quando o HP está abaixo de 1/3, os moves do tipo FIRE ganham um bônus de 50% grass." ) ) ; }
}
CmNsYXNzIFBva2Vtb24gewoKICBwdWJsaWMgZW51bSBUaXBvIHsKICAgIEZJUkUsIFdBVEVSLCBJQ0UsIEVMRUNUUklDLCBHUkFTUywgREFSSywgQlVHLCBHSE9TVCwgUk9DSywgRkFJUlksIEdST1VORCwgRFJBR09OLCBQU1lDSElDLCBQT0lTT04sIE5PUk1BTCwgRklHSFRJTkcsIFNURUVMLCBGTFlJTkc7CiAgfQoKICBwdWJsaWMgU3RyaW5nIHN1YnN0aXR1aXIoU3RyaW5nIHRleHRvKSB7CiAgICBmb3IgKFRpcG8gdGlwbyA6IFRpcG8udmFsdWVzKCkpIHsKICAgICAgU3RyaW5nIGNsYXNzZSA9IHRpcG8ubmFtZSgpLnRvTG93ZXJDYXNlKCk7CgogICAgICAvLyAoP2kpIMOpIHVtYSBleHByZXNzw6NvIHJlZ3VsYXIgcGFyYSBpZ25vcmFyIG8gY2FzZSBkYXMgcGFsYXZyYXMuIFBvciBleGVtcGxvOiBJcsOhIGVuY29udHJhciBFb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