1 package gnu.expr; 2 import gnu.mapping.*; 3 import java.io.*; 4 import gnu.text.Printable; 5 import gnu.lists.Consumer; 6 7 public class Keyword extends Symbol 8 implements Printable, Externalizable 9 { 10 public static final Namespace keywordNamespace = new Namespace(); 11 static { keywordNamespace.setName("(keywords)"); } 12 13 public Keyword() 14 { 15 } 16 17 private Keyword (String name) 18 { 19 super(keywordNamespace, name); 20 } 21 22 23 public Keyword (Namespace namespace, String name) 24 { 25 super(namespace, name); 26 } 27 28 31 public Symbol asSymbol () 32 { 33 return Namespace.EmptyNamespace.getSymbol(getName()); 34 } 35 36 41 static public Keyword make (String name) 42 { 43 int hash = name.hashCode(); 44 Keyword keyword = (Keyword) keywordNamespace.lookup(name, hash, false); 45 if (keyword == null) 46 { 47 keyword = new Keyword(name); 48 keywordNamespace.add(keyword, hash); 49 } 50 return keyword; 51 } 52 53 59 60 public static boolean isKeyword (Object obj) 61 { 62 return obj instanceof Keyword; 63 } 64 65 public final String toString() 66 { 67 return getName()+':'; 68 } 69 70 public void print (Consumer out) 71 { 72 Symbols.print(getName(), out); 73 out.write(':'); 74 } 75 76 86 public static Object searchForKeyword (Object [] vals, 87 int offset, Object keyword) 88 { 89 for (int i = offset; i < vals.length; i += 2) 90 { 91 if (vals[i] == keyword) 92 return vals[i+1]; 93 } 94 return Special.dfault; 95 } 96 97 108 public static Object searchForKeyword (Object [] vals, 109 int offset, Object keyword, 110 Object dfault) 111 { 112 for (int i = offset; i < vals.length; i += 2) 113 { 114 if (vals[i] == keyword) 115 return vals[i+1]; 116 } 117 return dfault; 118 } 119 } 120 | Popular Tags |