So, I got confused if there could be functions in Java enums. I am making a simple html editor and wanted to use enumerations to represent html tags, yes, I know that this is not the best way, but the way my group decided to implement it.
So, I'm trying to do something like this, but when I try to call TagEnums.normalTags(), he suggests making it a static method, I think I'm wondering if this is right or if there is a better way to implement it instead of posting ArrayList<String> normalTags()topublic static ArrayList<String> normalTags()
public enum TagEnum {
H1, H2, H3, H4, H5, H6, P, B, I, U, BR, HR, RP, RT, RUBY
public ArrayList<String> normalTags(){
String normalTags = "H1, H2, H3, H4, H5, H6, P, B, I, U";
ArrayList<String> tags = new ArrayList<String>();
for(Enum<?> currentEnum: TagEnum.values()){
if(normalTags.contains(currentEnum.toString())){
tags.add("<"+currentEnum.toString().toLowerCase()+">");
tags.add("</"+currentEnum.toString().toLowerCase()+">");
}
}
return tags;
}
}
source
share