Advertisement
MrLore

Java Keywords Utility Class

Dec 9th, 2012
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.82 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.HashSet;
  4.  
  5. /**
  6.  * JavaKeywords is a Utility class related to the reserved keywords
  7.  *
  8.  * @author MrLore
  9.  */
  10. public class JavaKeywords
  11. {
  12.     private static final HashSet<String> keywords = new HashSet(Arrays.asList(new String[]
  13.     {
  14.         //There are 50 keywords, and 3 literals; true, false and null.
  15.         "abstract",     "assert",        "boolean",      "break",           "byte",
  16.         "case",         "catch",         "char",         "class",           "const",
  17.         "continue",     "default",       "do",           "double",          "else",
  18.         "enum",         "extends",       "false",        "final",           "finally",
  19.         "float",        "for",           "goto",         "if",              "implements",
  20.         "import",       "instanceof",    "int",          "interface",       "long",
  21.         "native",       "new",           "null",         "package",         "private",
  22.         "protected",    "public",        "return",       "short",           "static",
  23.         "strictfp",     "super",         "switch",       "synchronized",    "this",
  24.         "throw",        "throws",        "transient",    "true",            "try",
  25.         "void",         "volatile",      "while"
  26.     }));
  27.    
  28.     public static boolean isKeyword(String toCheck)
  29.     {
  30.         return keywords.contains(toCheck);
  31.     }//End isKeyword()
  32.    
  33.     public static String[] getAsArray()
  34.     {
  35.         return keywords.toArray(new String[keywords.size()]);
  36.     }//End getAsArray()
  37.    
  38.     public static ArrayList<String> getAsArrayList()
  39.     {
  40.         return new ArrayList(keywords);
  41.     }//End getAsArrayList()
  42.    
  43.     public static HashSet<String> getAsHashSet()
  44.     {
  45.         return keywords;
  46.     }//End getAsHashSet()
  47. }//End JavaKeywords
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement