KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > AcceptorFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.editor;
21
22 /** Mostly used acceptors
23 *
24 * @author Miloslav Metelka
25 * @version 1.00
26 */

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