You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by PascalSchumacher <gi...@git.apache.org> on 2017/06/14 20:06:49 UTC

[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

GitHub user PascalSchumacher opened a pull request:

    https://github.com/apache/commons-text/pull/50

    TEXT-90: Add CharacterPredicates for ASCII letters (uppercase/lowerca…

    …se) and Arabic numerals

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/PascalSchumacher/commons-text more_character_predicates

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/commons-text/pull/50.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #50
    
----
commit fd7997ec780dd17f635086429352cd478d967f11
Author: Pascal Schumacher <pa...@gmx.net>
Date:   2017-06-14T20:04:55Z

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

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/50#discussion_r122292528
  
    --- Diff: src/test/java/org/apache/commons/text/CharacterPredicatesTest.java ---
    @@ -44,4 +44,77 @@ public void testDigits() {
             assertFalse(CharacterPredicates.DIGITS.test('.'));
             assertFalse(CharacterPredicates.DIGITS.test('L'));
         }
    +
    +    @Test
    +    public void testArabicNumerals() {
    --- End diff --
    
    I personally do not like junit parametrized tests because every test method has to be in its own class and you have to a lot of boiler plate. For parametrized test I use https://github.com/TNG/junit-dataprovider
    
    Theories can be nice for testing methods with multiple parameters, although in my opinion well chosen parameter combinations are often enough. I think theories are a bit lacking compared to "real" property based testing like quick-check (no test data generation, no failure shrinking). For java https://github.com/pholser/junit-quickcheck is the best option I'm aware of, but it has been requiring java 8 for years.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/commons-text/pull/50


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by jvz <gi...@git.apache.org>.
Github user jvz commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/50#discussion_r122104071
  
    --- Diff: src/main/java/org/apache/commons/text/CharacterPredicates.java ---
    @@ -48,5 +48,73 @@ public boolean test(int codePoint) {
             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 >= ZERO_CODEPOINT && codePoint <= NINE_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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 >= LOWERCASE_A_CODEPOINT && codePoint <= LOWERCASE_Z_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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 >= UPPERCASE_A_CODEPOINT && codePoint <= UPPERCASE_Z_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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);
    +        }
    +    };
    +
    +    private static final int NINE_CODEPOINT = 57;
    --- End diff --
    
    Wouldn't it make more sense to use an implicit widening on `'9'` to `int` rather than hardcoded constants?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by PascalSchumacher <gi...@git.apache.org>.
Github user PascalSchumacher commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/50#discussion_r122294037
  
    --- Diff: src/main/java/org/apache/commons/text/CharacterPredicates.java ---
    @@ -48,5 +48,73 @@ public boolean test(int codePoint) {
             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 >= ZERO_CODEPOINT && codePoint <= NINE_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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 >= LOWERCASE_A_CODEPOINT && codePoint <= LOWERCASE_Z_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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 >= UPPERCASE_A_CODEPOINT && codePoint <= UPPERCASE_Z_CODEPOINT;
    +        }
    +    },
    +
    +    /**
    +     * 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);
    +        }
    +    };
    +
    +    private static final int NINE_CODEPOINT = 57;
    --- End diff --
    
    Sure. I have updated the pull request. Thanks for the suggestion!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by kinow <gi...@git.apache.org>.
Github user kinow commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/50#discussion_r122105816
  
    --- Diff: src/test/java/org/apache/commons/text/CharacterPredicatesTest.java ---
    @@ -44,4 +44,77 @@ public void testDigits() {
             assertFalse(CharacterPredicates.DIGITS.test('.'));
             assertFalse(CharacterPredicates.DIGITS.test('L'));
         }
    +
    +    @Test
    +    public void testArabicNumerals() {
    --- End diff --
    
    TIL about JUnit theories :) 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[GitHub] commons-text pull request #50: TEXT-90: Add CharacterPredicates for ASCII le...

Posted by jvz <gi...@git.apache.org>.
Github user jvz commented on a diff in the pull request:

    https://github.com/apache/commons-text/pull/50#discussion_r122104232
  
    --- Diff: src/test/java/org/apache/commons/text/CharacterPredicatesTest.java ---
    @@ -44,4 +44,77 @@ public void testDigits() {
             assertFalse(CharacterPredicates.DIGITS.test('.'));
             assertFalse(CharacterPredicates.DIGITS.test('L'));
         }
    +
    +    @Test
    +    public void testArabicNumerals() {
    --- End diff --
    
    This whole test looks repetitive enough to benefit from [parameterized tests](https://github.com/junit-team/junit4/wiki/Parameterized-tests) or even possibly [theories](https://github.com/junit-team/junit4/wiki/Theories).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org