1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.commons.text;
18
19 /**
20 * Enumerates commonly used implementations of {@link CharacterPredicate}. Per the interface requirements, all implementations are thread safe.
21 *
22 * @since 1.0
23 */
24 public enum CharacterPredicates implements CharacterPredicate {
25
26 /**
27 * Tests code points against {@link Character#isLetter(int)}.
28 *
29 * @since 1.0
30 */
31 LETTERS {
32 @Override
33 public boolean test(final int codePoint) {
34 return Character.isLetter(codePoint);
35 }
36 },
37
38 /**
39 * Tests code points against {@link Character#isDigit(int)}.
40 *
41 * @since 1.0
42 */
43 DIGITS {
44 @Override
45 public boolean test(final int codePoint) {
46 return Character.isDigit(codePoint);
47 }
48 },
49
50 /**
51 * Tests if the code points represents a number between 0 and 9.
52 *
53 * @since 1.2
54 */
55 ARABIC_NUMERALS {
56 @Override
57 public boolean test(final int codePoint) {
58 return codePoint >= '0' && codePoint <= '9';
59 }
60 },
61
62 /**
63 * Tests if the code points represents a letter between a and z.
64 *
65 * @since 1.2
66 */
67 ASCII_LOWERCASE_LETTERS {
68 @Override
69 public boolean test(final int codePoint) {
70 return codePoint >= 'a' && codePoint <= 'z';
71 }
72 },
73
74 /**
75 * Tests if the code points represents a letter between A and Z.
76 *
77 * @since 1.2
78 */
79 ASCII_UPPERCASE_LETTERS {
80 @Override
81 public boolean test(final int codePoint) {
82 return codePoint >= 'A' && codePoint <= 'Z';
83 }
84 },
85
86 /**
87 * Tests if the code points represents a letter between a and Z.
88 *
89 * @since 1.2
90 */
91 ASCII_LETTERS {
92 @Override
93 public boolean test(final int codePoint) {
94 return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint);
95 }
96 },
97
98 /**
99 * 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 }