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 * http://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 * Commonly used implementations of {@link CharacterPredicate}. Per the interface 021 * requirements, all implementations are thread safe. 022 * 023 * @since 1.0 024 */ 025public enum CharacterPredicates implements CharacterPredicate { 026 027 /** 028 * Tests code points against {@link Character#isLetter(int)}. 029 * 030 * @since 1.0 031 */ 032 LETTERS { 033 @Override 034 public boolean test(final int codePoint) { 035 return Character.isLetter(codePoint); 036 } 037 }, 038 039 /** 040 * Tests code points against {@link Character#isDigit(int)}. 041 * 042 * @since 1.0 043 */ 044 DIGITS { 045 @Override 046 public boolean test(final int codePoint) { 047 return Character.isDigit(codePoint); 048 } 049 }, 050 051 /** 052 * Tests if the code points represents a number between 0 and 9. 053 * 054 * @since 1.2 055 */ 056 ARABIC_NUMERALS { 057 @Override 058 public boolean test(final int codePoint) { 059 return codePoint >= '0' && codePoint <= '9'; 060 } 061 }, 062 063 /** 064 * Tests if the code points represents a letter between a and z. 065 * 066 * @since 1.2 067 */ 068 ASCII_LOWERCASE_LETTERS { 069 @Override 070 public boolean test(final int codePoint) { 071 return codePoint >= 'a' && codePoint <= 'z'; 072 } 073 }, 074 075 /** 076 * Tests if the code points represents a letter between A and Z. 077 * 078 * @since 1.2 079 */ 080 ASCII_UPPERCASE_LETTERS { 081 @Override 082 public boolean test(final int codePoint) { 083 return codePoint >= 'A' && codePoint <= 'Z'; 084 } 085 }, 086 087 /** 088 * Tests if the code points represents a letter between a and Z. 089 * 090 * @since 1.2 091 */ 092 ASCII_LETTERS { 093 @Override 094 public boolean test(final int codePoint) { 095 return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint); 096 } 097 }, 098 099 /** 100 * Tests if the code points represents a letter between a and Z or a number between 0 and 9. 101 * 102 * @since 1.2 103 */ 104 ASCII_ALPHA_NUMERALS { 105 @Override 106 public boolean test(final int codePoint) { 107 return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint) 108 || ARABIC_NUMERALS.test(codePoint); 109 } 110 } 111}