001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      https://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.text;
018
019/**
020 * Enumerates commonly used implementations of {@link CharacterPredicate}. Per the interface requirements, all implementations are thread safe.
021 *
022 * @since 1.0
023 */
024public enum CharacterPredicates implements CharacterPredicate {
025
026    /**
027     * Tests code points against {@link Character#isLetter(int)}.
028     *
029     * @since 1.0
030     */
031    LETTERS {
032        @Override
033        public boolean test(final int codePoint) {
034            return Character.isLetter(codePoint);
035        }
036    },
037
038    /**
039     * Tests code points against {@link Character#isDigit(int)}.
040     *
041     * @since 1.0
042     */
043    DIGITS {
044        @Override
045        public boolean test(final int codePoint) {
046            return Character.isDigit(codePoint);
047        }
048    },
049
050    /**
051     * Tests if the code points represents a number between 0 and 9.
052     *
053     * @since 1.2
054     */
055    ARABIC_NUMERALS {
056        @Override
057        public boolean test(final int codePoint) {
058            return codePoint >= '0' && codePoint <= '9';
059        }
060    },
061
062    /**
063     * Tests if the code points represents a letter between a and z.
064     *
065     * @since 1.2
066     */
067    ASCII_LOWERCASE_LETTERS {
068        @Override
069        public boolean test(final int codePoint) {
070            return codePoint >= 'a' && codePoint <= 'z';
071        }
072    },
073
074    /**
075     * Tests if the code points represents a letter between A and Z.
076     *
077     * @since 1.2
078     */
079    ASCII_UPPERCASE_LETTERS {
080        @Override
081        public boolean test(final int codePoint) {
082            return codePoint >= 'A' && codePoint <= 'Z';
083        }
084    },
085
086    /**
087     * Tests if the code points represents a letter between a and Z.
088     *
089     * @since 1.2
090     */
091    ASCII_LETTERS {
092        @Override
093        public boolean test(final int codePoint) {
094            return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint);
095        }
096    },
097
098    /**
099     * Tests if the code points represents a letter between a and Z or a number between 0 and 9.
100     *
101     * @since 1.2
102     */
103    ASCII_ALPHA_NUMERALS {
104        @Override
105        public boolean test(final int codePoint) {
106            return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint)
107                    || ARABIC_NUMERALS.test(codePoint);
108        }
109    }
110}