Skip to content

Commit

Permalink
Add isNumeric check
Browse files Browse the repository at this point in the history
  • Loading branch information
CyR1en committed Apr 8, 2019
1 parent aaef353 commit 452d031
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/main/java/com/cyr1en/flatdb/util/FastStrings.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ public static boolean isBlank(CharSequence charSequence) {
return true;
}

/**
* Check if a {@link CharSequence} is numeric.
*
* <p>This methods checks if the length of the {@link CharSequence}
* is 0, if true, that means the sequence is not numeric. This method
* also checks if all code points in the sequence are actually numbers.
* Refer to {@link FastStrings#charIsNumeric(int)} to learn more
* about numeric chars</p>
*
* @param charSequence {@link CharSequence} that you want to process.
* @return if the {@link CharSequence} is numeric.
*/
public static boolean isNumeric(CharSequence charSequence) {
if (isBlank(charSequence)) return false;
for (int i = 0; i < charSequence.length(); i++) {
if (!charIsNumeric((int) charSequence.charAt(i)))
return false;
}
return true;
}

public static boolean charIsNumeric(int codepoint) {
if (!Character.isValidCodePoint(codepoint))
return false;
return codepoint >= 0x0030 && codepoint <= 0x0039;
}

/**
* Checks if a codepoint of a char is a 'non-printable' char.
*
Expand Down

0 comments on commit 452d031

Please sign in to comment.