01: /*
02: * Sun Public License Notice
03: *
04: * The contents of this file are subject to the Sun Public License
05: * Version 1.0 (the "License"). You may not use this file except in
06: * compliance with the License. A copy of the License is available at
07: * http://www.sun.com/
08: *
09: * The Original Code is NetBeans. The Initial Developer of the Original
10: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
11: * Microsystems, Inc. All Rights Reserved.
12: */
13:
14: package org.netbeans.editor;
15:
16: /**
17: * Mostly used acceptors
18: *
19: * @author Miloslav Metelka
20: * @version 1.00
21: */
22:
23: public class AcceptorFactory {
24:
25: public static final Acceptor TRUE = new Fixed(true);
26:
27: public static final Acceptor FALSE = new Fixed(false);
28:
29: public static final Acceptor NL = new Char('\n');
30:
31: public static final Acceptor SPACE_NL = new TwoChar(' ', '\n');
32:
33: public static final Acceptor WHITESPACE = new Acceptor() {
34: public final boolean accept(char ch) {
35: return Character.isWhitespace(ch);
36: }
37: };
38:
39: public static final Acceptor LETTER_DIGIT = new Acceptor() {
40: public final boolean accept(char ch) {
41: return Character.isLetterOrDigit(ch);
42: }
43: };
44:
45: public static final Acceptor JAVA_IDENTIFIER = new Acceptor() {
46: public final boolean accept(char ch) {
47: return Character.isJavaIdentifierPart(ch);
48: }
49: };
50:
51: public static final Acceptor NON_JAVA_IDENTIFIER = new Acceptor() {
52: public final boolean accept(char ch) {
53: return !Character.isJavaIdentifierPart(ch);
54: }
55: };
56:
57: private static final class Fixed implements Acceptor {
58: private boolean state;
59:
60: public Fixed(boolean state) {
61: this .state = state;
62: }
63:
64: public final boolean accept(char ch) {
65: return state;
66: }
67: }
68:
69: private static final class Char implements Acceptor {
70: private char hit;
71:
72: public Char(char hit) {
73: this .hit = hit;
74: }
75:
76: public final boolean accept(char ch) {
77: return ch == hit;
78: }
79: }
80:
81: private static final class TwoChar implements Acceptor {
82: private char hit1, hit2;
83:
84: public TwoChar(char hit1, char hit2) {
85: this .hit1 = hit1;
86: this .hit2 = hit2;
87: }
88:
89: public final boolean accept(char ch) {
90: return ch == hit1 || ch == hit2;
91: }
92: }
93:
94: }
|