Skip to content

Commit

Permalink
ENH - Clean code
Browse files Browse the repository at this point in the history
Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
  • Loading branch information
thibaultmeyer committed Jul 28, 2024
1 parent ec7858e commit 0c6c587
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/main/java/io/github/thibaultmeyer/cuid/CUID.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,24 @@ public static boolean isValid(final String cuidAsString) {

return cuidAsString != null
&& (cuidAsString.length() == CUIDv1.LENGTH_STANDARD && cuidAsString.startsWith(CUIDv1.START_CHARACTER) // Version 1
|| (cuidAsString.length() > 0)) // Version 2
|| (!cuidAsString.isEmpty())) // Version 2
&& cuidAsString.chars()
.filter(c -> !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')))
.count() == 0;
}

/**
* Always return non-negative value.
*
* @param i the integer value
* @return a non-negative value
* @since 2.0.3
*/
private static int safeAbs(final int i) {

return i == Integer.MIN_VALUE ? 0 : Math.abs(i);
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -177,11 +189,6 @@ public int hashCode() {
return Objects.hash(value);
}

// Always return non-negative value (including Integer.MIN_VALUE)
private static int safeAbs(int a) {
return a == Integer.MIN_VALUE ? 0 : Math.abs(a);
}

/**
* CUID Version 1.
*
Expand Down

0 comments on commit 0c6c587

Please sign in to comment.