Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashSet;
- /**
- * JavaKeywords is a Utility class related to the reserved keywords
- *
- * @author James McManus
- */
- public class JavaKeywords
- {
- private static final HashSet<String> keywords = new HashSet<>(Arrays.asList(new String[]
- {
- //There are 50 keywords, and 3 literals; true, false and null.
- "abstract", "assert", "boolean", "break", "byte",
- "case", "catch", "char", "class", "const",
- "continue", "default", "do", "double", "else",
- "enum", "extends", "false", "final", "finally",
- "float", "for", "goto", "if", "implements",
- "import", "instanceof", "int", "interface", "long",
- "native", "new", "null", "package", "private",
- "protected", "public", "return", "short", "static",
- "strictfp", "super", "switch", "synchronized", "this",
- "throw", "throws", "transient", "true", "try",
- "void", "volatile", "while"
- }));
- public static boolean isKeyword(String toCheck)
- {
- return keywords.contains(toCheck);
- }//End isKeyword()
- public static boolean containsKeyword(String toCheck)
- {
- toCheck = toCheck.toLowerCase();
- for(String keyword : keywords)
- {
- if(toCheck.equals(keyword) || toCheck.endsWith("." + keyword) ||
- toCheck.startsWith(keyword + ".") || toCheck.contains("." + keyword + "."))
- {
- return true;
- }//End if
- }//End for
- return false;
- }//End containsKeyword()
- public static String[] getAsArray()
- {
- return keywords.toArray(new String[keywords.size()]);
- }//End getAll()
- public static ArrayList<String> getAsArrayList()
- {
- return new ArrayList<>(keywords);
- }//End getAsArrayList()
- public static HashSet<String> getAsHashSet()
- {
- return keywords;
- }//End getAll()
- }//End JavaKeywords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement