Skip to content

Commit dafbab6

Browse files
committed
refactor: clean code
Signed-off-by: Thibault Meyer <meyer.thibault@gmail.com>
1 parent 85d0bf7 commit dafbab6

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • src/main/java/io/github/thibaultmeyer/cuid

src/main/java/io/github/thibaultmeyer/cuid/CUID.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,24 @@ public static boolean isValid(final String cuidAsString) {
117117

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

126+
/**
127+
* Always return non-negative value.
128+
*
129+
* @param i the integer value
130+
* @return a non-negative value
131+
* @since 2.0.3
132+
*/
133+
private static int safeAbs(final int i) {
134+
135+
return i == Integer.MIN_VALUE ? 0 : Math.abs(i);
136+
}
137+
126138
/**
127139
* {@inheritDoc}
128140
*
@@ -177,11 +189,6 @@ public int hashCode() {
177189
return Objects.hash(value);
178190
}
179191

180-
// Always return non-negative value (including Integer.MIN_VALUE)
181-
private static int safeAbs(int a) {
182-
return a == Integer.MIN_VALUE ? 0 : Math.abs(a);
183-
}
184-
185192
/**
186193
* CUID Version 1.
187194
*

0 commit comments

Comments
 (0)