1 19 20 package org.netbeans.modules.editor.lib2; 21 22 27 public class AcceptorFactory { 28 29 public static final Acceptor TRUE = new Fixed(true); 30 31 public static final Acceptor FALSE = new Fixed(false); 32 33 public static final Acceptor NL = new Char('\n'); 34 35 public static final Acceptor SPACE_NL = new TwoChar(' ', '\n'); 36 37 public static final Acceptor WHITESPACE 38 = new Acceptor() { 39 public final boolean accept(char ch) { 40 return Character.isWhitespace(ch); 41 } 42 }; 43 44 public static final Acceptor LETTER_DIGIT 45 = new Acceptor() { 46 public final boolean accept(char ch) { 47 return Character.isLetterOrDigit(ch); 48 } 49 }; 50 51 public static final Acceptor JAVA_IDENTIFIER 52 = new Acceptor() { 53 public final boolean accept(char ch) { 54 return Character.isJavaIdentifierPart(ch); 55 } 56 }; 57 58 public static final Acceptor NON_JAVA_IDENTIFIER 59 = new Acceptor() { 60 public final boolean accept(char ch) { 61 return !Character.isJavaIdentifierPart(ch); 62 } 63 }; 64 65 private static final class Fixed implements Acceptor { 66 private boolean state; 67 68 public Fixed(boolean state) { 69 this.state = state; 70 } 71 72 public final boolean accept(char ch) { 73 return state; 74 } 75 } 76 77 private static final class Char implements Acceptor { 78 private char hit; 79 80 public Char(char hit) { 81 this.hit = hit; 82 } 83 84 public final boolean accept(char ch) { 85 return ch == hit; 86 } 87 } 88 89 private static final class TwoChar implements Acceptor { 90 private char hit1, hit2; 91 92 public TwoChar(char hit1, char hit2) { 93 this.hit1 = hit1; 94 this.hit2 = hit2; 95 } 96 97 public final boolean accept(char ch) { 98 return ch == hit1 || ch == hit2; 99 } 100 } 101 } 102 | Popular Tags |