changeset 6389:16994ab70364

RT-36051: Make com.sun.javafx.css.parser.Recognizer a FunctionalInterface
author David Grieve<david.grieve@oracle.com>
date Thu, 27 Feb 2014 11:32:41 -0500
parents 5f994e8a51cc
children 56e68b2ba599
files modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSLexer.java modules/graphics/src/main/java/com/sun/javafx/css/parser/Recognizer.java modules/graphics/src/main/java/com/sun/javafx/css/parser/SimpleRecognizer.java
diffstat 3 files changed, 52 insertions(+), 115 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSLexer.java	Thu Feb 27 11:03:36 2014 -0500
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/parser/CSSLexer.java	Thu Feb 27 11:32:41 2014 -0500
@@ -77,87 +77,73 @@
     final static int FONT_FACE = 42;
     final static int URL = 43;
 
-    private final Recognizer A = new SimpleRecognizer('a','A');
-    private final Recognizer B = new SimpleRecognizer('b','B');
-    private final Recognizer C = new SimpleRecognizer('c','C');
-    private final Recognizer D = new SimpleRecognizer('d','D');
-    private final Recognizer E = new SimpleRecognizer('e','E');
-    private final Recognizer F = new SimpleRecognizer('f','F');
-    private final Recognizer G = new SimpleRecognizer('g','G');
-    private final Recognizer H = new SimpleRecognizer('h','H');
-    private final Recognizer I = new SimpleRecognizer('i','I');
-    private final Recognizer J = new SimpleRecognizer('j','J');
-    private final Recognizer K = new SimpleRecognizer('k','K');
-    private final Recognizer L = new SimpleRecognizer('l','L');
-    private final Recognizer M = new SimpleRecognizer('m','M');
-    private final Recognizer N = new SimpleRecognizer('n','N');
-    private final Recognizer O = new SimpleRecognizer('o','O');
-    private final Recognizer P = new SimpleRecognizer('p','P');
-    private final Recognizer Q = new SimpleRecognizer('q','Q');
-    private final Recognizer R = new SimpleRecognizer('r','R');
-    private final Recognizer S = new SimpleRecognizer('s','S');
-    private final Recognizer T = new SimpleRecognizer('t','T');
-    private final Recognizer U = new SimpleRecognizer('u','U');
-    private final Recognizer V = new SimpleRecognizer('v','V');
-    private final Recognizer W = new SimpleRecognizer('w','W');
-    private final Recognizer X = new SimpleRecognizer('x','X');
-    private final Recognizer Y = new SimpleRecognizer('y','Y');
-    private final Recognizer Z = new SimpleRecognizer('z','Z');
-    private final Recognizer ALPHA = new Recognizer() {
-        @Override public boolean recognize(int c) {
+    private final Recognizer A = (c) -> { return c == 'a' || c == 'A'; };
+    private final Recognizer B = (c) -> { return c == 'b' || c == 'B'; };
+    private final Recognizer C = (c) -> { return c == 'c' || c == 'C'; };
+    private final Recognizer D = (c) -> { return c == 'd' || c == 'D'; };
+    private final Recognizer E = (c) -> { return c == 'e' || c == 'E'; };
+    private final Recognizer F = (c) -> { return c == 'f' || c == 'F'; };
+    private final Recognizer G = (c) -> { return c == 'g' || c == 'G'; };
+    private final Recognizer H = (c) -> { return c == 'h' || c == 'H'; };
+    private final Recognizer I = (c) -> { return c == 'i' || c == 'I'; };
+    private final Recognizer J = (c) -> { return c == 'j' || c == 'J'; };
+    private final Recognizer K = (c) -> { return c == 'k' || c == 'K'; };
+    private final Recognizer L = (c) -> { return c == 'l' || c == 'L'; };
+    private final Recognizer M = (c) -> { return c == 'm' || c == 'M'; };
+    private final Recognizer N = (c) -> { return c == 'n' || c == 'N'; };
+    private final Recognizer O = (c) -> { return c == 'o' || c == 'O'; };
+    private final Recognizer P = (c) -> { return c == 'p' || c == 'P'; };
+    private final Recognizer Q = (c) -> { return c == 'q' || c == 'Q'; };
+    private final Recognizer R = (c) -> { return c == 'r' || c == 'R'; };
+    private final Recognizer S = (c) -> { return c == 's' || c == 'S'; };
+    private final Recognizer T = (c) -> { return c == 't' || c == 'T'; };
+    private final Recognizer U = (c) -> { return c == 'u' || c == 'U'; };
+    private final Recognizer V = (c) -> { return c == 'v' || c == 'V'; };
+    private final Recognizer W = (c) -> { return c == 'w' || c == 'W'; };
+    private final Recognizer X = (c) -> { return c == 'x' || c == 'X'; };
+    private final Recognizer Y = (c) -> { return c == 'y' || c == 'Y'; };
+    private final Recognizer Z = (c) -> { return c == 'z' || c == 'Z'; };
+    private final Recognizer ALPHA =  (c) -> {
             return ('a' <= c && c <= 'z') ||
                    ('A' <= c && c <= 'Z');
         };
-    };
 
-    private final Recognizer NON_ASCII = new Recognizer() {
-        @Override public boolean recognize(int c) {
-            return '\u0080' <= c && c <= '\uFFFF';
-        }
-    };
+    private final Recognizer NON_ASCII = (c) -> { return '\u0080' <= c && c <= '\uFFFF'; };
 
-    private final Recognizer DOT_CHAR = new SimpleRecognizer('.');
-    private final Recognizer GREATER_CHAR = new SimpleRecognizer('>');
-    private final Recognizer LBRACE_CHAR = new SimpleRecognizer('{');
-    private final Recognizer RBRACE_CHAR = new SimpleRecognizer( '}');
-    private final Recognizer SEMI_CHAR  = new SimpleRecognizer(';');
-    private final Recognizer COLON_CHAR = new SimpleRecognizer(':');
-    private final Recognizer SOLIDUS_CHAR = new SimpleRecognizer('/');
-    private final Recognizer MINUS_CHAR = new SimpleRecognizer('-');
-    private final Recognizer PLUS_CHAR = new SimpleRecognizer('+');
-    private final Recognizer STAR_CHAR = new SimpleRecognizer('*');
-    private final Recognizer LPAREN_CHAR = new SimpleRecognizer('(');
-    private final Recognizer RPAREN_CHAR = new SimpleRecognizer(')');
-    private final Recognizer COMMA_CHAR = new SimpleRecognizer(',');
-    private final Recognizer UNDERSCORE_CHAR = new SimpleRecognizer('_');
-    private final Recognizer HASH_CHAR = new SimpleRecognizer('#');
+    private final Recognizer DOT_CHAR =        (c) -> { return c == '.'; };
+    private final Recognizer GREATER_CHAR =    (c) -> { return c == '>'; };
+    private final Recognizer LBRACE_CHAR =     (c) -> { return c == '{'; };
+    private final Recognizer RBRACE_CHAR =     (c) -> { return c == '}'; };
+    private final Recognizer SEMI_CHAR  =      (c) -> { return c == ';'; };
+    private final Recognizer COLON_CHAR =      (c) -> { return c == ':'; };
+    private final Recognizer SOLIDUS_CHAR =    (c) -> { return c == '/'; };
+    private final Recognizer MINUS_CHAR =      (c) -> { return c == '-'; };
+    private final Recognizer PLUS_CHAR =       (c) -> { return c == '+'; };
+    private final Recognizer STAR_CHAR =       (c) -> { return c == '*'; };
+    private final Recognizer LPAREN_CHAR =     (c) -> { return c == '('; };
+    private final Recognizer RPAREN_CHAR =     (c) -> { return c == ')'; };
+    private final Recognizer COMMA_CHAR =      (c) -> { return c == ','; };
+    private final Recognizer UNDERSCORE_CHAR = (c) -> { return c == '_'; };
+    private final Recognizer HASH_CHAR =       (c) -> { return c == '#'; };
 
-    private final Recognizer WS_CHARS = new Recognizer() {
-        @Override public boolean recognize(int c) {
+    private final Recognizer WS_CHARS = (c) -> {
             return c == ' '  ||
                    c == '\t' ||
                    c == '\r' ||
                    c == '\n' ||
                    c == '\f';
-        }
-    };
-    private final Recognizer NL_CHARS = new Recognizer() {
-        @Override public boolean recognize(int c) {
+        };
+    private final Recognizer NL_CHARS = (c) -> {
             return (c == '\r' || c == '\n');
-        }
-    };
+        };
 
-    private final Recognizer DIGIT = new SimpleRecognizer(
-        '0','1','2','3','4','5','6','7','8','9'
-    );
+    private final Recognizer DIGIT = (c) -> { return '0' <= c && c <= '9'; };
 
-    private final Recognizer HEX_DIGIT = new Recognizer() {
-        @Override public boolean recognize(int c) {
+    private final Recognizer HEX_DIGIT = (c) ->  {
             return ('0' <= c && c <= '9') ||
                    ('a' <= c && c <= 'f') ||
                    ('A' <= c && c <= 'F');
-        }
-    };
+        };
 
     // The initial accepts any character
     final LexerState initState = new LexerState("initState", null) {
@@ -630,7 +616,7 @@
             { P, X },
             { R, A, D },
             { T, U, R, N },
-            { new SimpleRecognizer('%') }                                
+            { (c) -> { return c == '%'; } }
             
         };
         
--- a/modules/graphics/src/main/java/com/sun/javafx/css/parser/Recognizer.java	Thu Feb 27 11:03:36 2014 -0500
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/parser/Recognizer.java	Thu Feb 27 11:32:41 2014 -0500
@@ -25,7 +25,7 @@
 
 package com.sun.javafx.css.parser;
 
-
+@FunctionalInterface
 interface Recognizer {
 
     boolean recognize(int c);
--- a/modules/graphics/src/main/java/com/sun/javafx/css/parser/SimpleRecognizer.java	Thu Feb 27 11:03:36 2014 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,49 +0,0 @@
-/*
- * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package com.sun.javafx.css.parser;
-
-
-class SimpleRecognizer implements Recognizer {
-
-    public boolean recognize(int c) {
-        for (int n=0; n<recognizedChars.length; n++)
-            if (recognizedChars[n] == c) return true;
-        return false;
-    }
-
-    public SimpleRecognizer(int c, int... others) {
-        final int nChars = 1 + (others != null ? others.length : 0);
-        recognizedChars = new int[nChars];
-        recognizedChars[0] = c;
-        for (int n=1; n<nChars; n++) recognizedChars[n] = others[n-1];
-    }
-
-    private SimpleRecognizer() {
-        recognizedChars = null;
-    }
-
-    private final int[] recognizedChars;
-}