commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [text] TEXT-90: Add CharacterPredicates for ASCII letters (uppercase/lowercase) and Arabic numerals (closes #50)
Date Thu, 22 Jun 2017 18:53:47 GMT
Repository: commons-text
Updated Branches:
  refs/heads/master 25ec8d186 -> 569dbc094


TEXT-90: Add CharacterPredicates for ASCII letters (uppercase/lowercase) and Arabic numerals
(closes #50)

Add CharacterPredicates#ARABIC_NUMERALS, #ASCII_LOWERCASE_LETTERS, #ASCII_UPPERCASE_LETTERS,
#ASCII_LETTERS and #ASCII_ALPHA_NUMERALS.


Project: http://git-wip-us.apache.org/repos/asf/commons-text/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-text/commit/569dbc09
Tree: http://git-wip-us.apache.org/repos/asf/commons-text/tree/569dbc09
Diff: http://git-wip-us.apache.org/repos/asf/commons-text/diff/569dbc09

Branch: refs/heads/master
Commit: 569dbc09402a6f28334936567a597e3d0db9185c
Parents: 25ec8d1
Author: Pascal Schumacher <pascalschumacher@gmx.net>
Authored: Wed Jun 14 22:04:55 2017 +0200
Committer: Pascal Schumacher <pascalschumacher@gmx.net>
Committed: Thu Jun 22 20:53:39 2017 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../commons/text/CharacterPredicates.java       | 61 ++++++++++++++++++
 .../commons/text/CharacterPredicatesTest.java   | 66 ++++++++++++++++++++
 3 files changed, 128 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-text/blob/569dbc09/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f6c5b8f..412d1f4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
   <release version="1.2" date="tbd" description="tbd">
+     <action issue="TEXT-90" type="add" dev="pschumacher">Add CharacterPredicates for
ASCII letters (uppercase/lowercase) and arabic numerals</action>
     <action issue="TEXT-85" type="add" dev="chtompki" due-to="Arun Vinud S S">Added
CaseUtils class with camel case conversion support</action>
     <action issue="TEXT-91" type="add" dev="pschumacher">RandomStringGenerator should
be able to generate a String with a random length</action>
     <action issue="TEXT-92" type="update" dev="pschumacher">Update commons-lang dependency
to version 3.6</action>

http://git-wip-us.apache.org/repos/asf/commons-text/blob/569dbc09/src/main/java/org/apache/commons/text/CharacterPredicates.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/text/CharacterPredicates.java b/src/main/java/org/apache/commons/text/CharacterPredicates.java
index a4544de..dc504c7 100644
--- a/src/main/java/org/apache/commons/text/CharacterPredicates.java
+++ b/src/main/java/org/apache/commons/text/CharacterPredicates.java
@@ -48,5 +48,66 @@ public enum CharacterPredicates implements CharacterPredicate {
         public boolean test(int codePoint) {
             return Character.isDigit(codePoint);
         }
+    },
+
+    /**
+     * Tests if the code points represents a number between 0 and 9.
+     *
+     * @since 1.2
+     */
+    ARABIC_NUMERALS {
+        @Override
+        public boolean test(int codePoint) {
+            return codePoint >= '0' && codePoint <= '9';
+        }
+    },
+
+    /**
+     * Tests if the code points represents a letter between a and z.
+     *
+     * @since 1.2
+     */
+    ASCII_LOWERCASE_LETTERS {
+        @Override
+        public boolean test(int codePoint) {
+            return codePoint >= 'a' && codePoint <= 'z';
+        }
+    },
+
+    /**
+     * Tests if the code points represents a letter between A and Z.
+     *
+     * @since 1.2
+     */
+    ASCII_UPPERCASE_LETTERS {
+        @Override
+        public boolean test(int codePoint) {
+            return codePoint >= 'A' && codePoint <= 'Z';
+        }
+    },
+
+    /**
+     * Tests if the code points represents a letter between a and Z.
+     *
+     * @since 1.2
+     */
+    ASCII_LETTERS {
+        @Override
+        public boolean test(int codePoint) {
+            return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint);
+        }
+    },
+
+    /**
+     * Tests if the code points represents a letter between a and Z or a number between 0
and 9.
+     *
+     * @since 1.2
+     */
+    ASCII_ALPHA_NUMERALS {
+        @Override
+        public boolean test(int codePoint) {
+            return ASCII_LOWERCASE_LETTERS.test(codePoint) || ASCII_UPPERCASE_LETTERS.test(codePoint)
+                    || ARABIC_NUMERALS.test(codePoint);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/commons-text/blob/569dbc09/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java b/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java
index a22b466..1100868 100644
--- a/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java
+++ b/src/test/java/org/apache/commons/text/CharacterPredicatesTest.java
@@ -44,4 +44,70 @@ public class CharacterPredicatesTest {
         assertFalse(CharacterPredicates.DIGITS.test('.'));
         assertFalse(CharacterPredicates.DIGITS.test('L'));
     }
+
+    @Test
+    public void testArabicNumerals() {
+        assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('0'));
+        assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('1'));
+        assertTrue(CharacterPredicates.ARABIC_NUMERALS.test('9'));
+
+        assertFalse(CharacterPredicates.ARABIC_NUMERALS.test('/'));
+        assertFalse(CharacterPredicates.ARABIC_NUMERALS.test(':'));
+        assertFalse(CharacterPredicates.ARABIC_NUMERALS.test('a'));
+    }
+
+    @Test
+    public void testAsciiLowercaseLetters() {
+        assertTrue(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('a'));
+        assertTrue(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('z'));
+
+        assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('9'));
+        assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('A'));
+        assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('Z'));
+        assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('`'));
+        assertFalse(CharacterPredicates.ASCII_LOWERCASE_LETTERS.test('{'));
+    }
+
+    @Test
+    public void testAsciiUppercaseLetters() {
+        assertTrue(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('A'));
+        assertTrue(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('Z'));
+
+        assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('9'));
+        assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('@'));
+        assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('['));
+        assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('a'));
+        assertFalse(CharacterPredicates.ASCII_UPPERCASE_LETTERS.test('z'));
+    }
+
+    @Test
+    public void testAsciiLetters() {
+        assertTrue(CharacterPredicates.ASCII_LETTERS.test('a'));
+        assertTrue(CharacterPredicates.ASCII_LETTERS.test('z'));
+        assertTrue(CharacterPredicates.ASCII_LETTERS.test('A'));
+        assertTrue(CharacterPredicates.ASCII_LETTERS.test('Z'));
+
+        assertFalse(CharacterPredicates.ASCII_LETTERS.test('9'));
+        assertFalse(CharacterPredicates.ASCII_LETTERS.test('`'));
+        assertFalse(CharacterPredicates.ASCII_LETTERS.test('{'));
+        assertFalse(CharacterPredicates.ASCII_LETTERS.test('@'));
+        assertFalse(CharacterPredicates.ASCII_LETTERS.test('['));
+    }
+
+    @Test
+    public void testAsciiAlphaNumerals() {
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('a'));
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('z'));
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('A'));
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('Z'));
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('0'));
+        assertTrue(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('9'));
+
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('`'));
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('{'));
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('@'));
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('['));
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test('/'));
+        assertFalse(CharacterPredicates.ASCII_ALPHA_NUMERALS.test(':'));
+    }
 }
\ No newline at end of file


Mime
View raw message