Skip to content

Commit

Permalink
Improve code style
Browse files Browse the repository at this point in the history
- Prefer isEmpty() over length == 0
  • Loading branch information
spannm committed Feb 16, 2024
1 parent 52e6a5d commit 77c6026
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static DocumentEntry getDocumentEntry(String entryName,
// split entry name into individual components and decode them
List<String> entryNames = new ArrayList<>();
for (String str : entryName.split(ENTRY_SEPARATOR)) {
if (str.length() == 0) {
if (str.isEmpty()) {
continue;
}
entryNames.add(decodeEntryName(str));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ public static TimeZone getDefaultTimeZone() {
String tzProp = System.getProperty(TIMEZONE_PROPERTY);
if (tzProp != null) {
tzProp = tzProp.trim();
if (tzProp.length() > 0) {
if (!tzProp.isEmpty()) {
return TimeZone.getTimeZone(tzProp);
}
}
Expand All @@ -1971,7 +1971,7 @@ public static Charset getDefaultCharset(JetFormat format) {
String csProp = System.getProperty(CHARSET_PROPERTY_PREFIX + format);
if (csProp != null) {
csProp = csProp.trim();
if (csProp.length() > 0) {
if (!csProp.isEmpty()) {
return Charset.forName(csProp);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ static short[] loadMappings(String mappingsFilePath, char firstChar, char lastCh
String mappingLine = null;
while ((mappingLine = reader.readLine()) != null) {
mappingLine = mappingLine.trim();
if (mappingLine.length() == 0) {
if (mappingLine.isEmpty()) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private static CharHandler parseSignificantCodes(String[] codeStrings) {
* Converts a string of hex encoded bytes to a byte[], optionally throwing an exception if no codes are given.
*/
private static byte[] codesToBytes(String codes, boolean required) {
if (codes.length() == 0) {
if (codes.isEmpty()) {
if (required) {
throw new IllegalStateException("empty code bytes");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected Value eval3(EvalContext ctx,
public static final Function HEX = registerStringFunc(new Func1NullIsNull("Hex") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
if (param1.getType().isString() && param1.getAsString(ctx).length() == 0) {
if (param1.getType().isString() && param1.getAsString(ctx).isEmpty()) {
return ValueSupport.ZERO_VAL;
}
int lv = param1.getAsLongInt(ctx);
Expand Down Expand Up @@ -116,7 +116,7 @@ protected Value evalVar(EvalContext ctx, Value[] params) {
public static final Function OCT = registerStringFunc(new Func1NullIsNull("Oct") {
@Override
protected Value eval1(EvalContext ctx, Value param1) {
if (param1.getType().isString() && param1.getAsString(ctx).length() == 0) {
if (param1.getType().isString() && param1.getAsString(ctx).isEmpty()) {
return ValueSupport.ZERO_VAL;
}
int lv = param1.getAsLongInt(ctx);
Expand Down Expand Up @@ -416,7 +416,7 @@ protected Value eval1(EvalContext ctx, Value param1) {
String str = ValueSupport.WHITESPACE_PAT.matcher(param1.getAsString(ctx))
.replaceAll("");

if (str.length() == 0) {
if (str.isEmpty()) {
return ValueSupport.ZERO_D_VAL;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ public static Pattern likePatternToRegex(String pattern) {

String charClass = pattern.substring(startPos, endPos);

if (charClass.length() > 0 && charClass.charAt(0) == '!') {
if (!charClass.isEmpty() && charClass.charAt(0) == '!') {
// this is a negated char class
charClass = '^' + charClass.substring(1);
}
Expand Down Expand Up @@ -1364,7 +1364,7 @@ private static boolean isLiteralDefaultValue(
}

return resultType == Value.Type.STRING
&& (exprStr.length() == 0 || exprStr.charAt(0) != ExpressionTokenizer.QUOTED_STR_CHAR);
&& (exprStr.isEmpty() || exprStr.charAt(0) != ExpressionTokenizer.QUOTED_STR_CHAR);
}

private interface LeftAssocExpr {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ private static BDFormat createCustomNumberFormat(
String fmtStr = fmtStrs[fmtIdx];
if (!hasFmts[fmtIdx]) {
// convert the literal string to a dummy number format
if (fmtStr.length() > 0) {
if (!fmtStr.isEmpty()) {
// strip quoting
StringBuilder sb = buf.getScratchBuffer().append(fmtStr)
.deleteCharAt(fmtStr.length() - 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected BigDecimal getNumber(LocaleContext ctx) {
// ignore extraneous whitespace whitespace and handle "&[hH]" or
// "&[oO]" prefix (only supports integers)
String tmpVal = _val.trim();
if (tmpVal.length() > 0) {
if (!tmpVal.isEmpty()) {

if (tmpVal.charAt(0) != ValueSupport.NUMBER_BASE_PREFIX) {
// convert to standard numeric support for parsing
Expand Down
10 changes: 5 additions & 5 deletions src/test/java/io/github/spannm/jackcess/impl/IndexCodesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void x_testReverseIsoMdb2010() throws Exception {
Character cc = c;
String[] chars = inlineCodes.get(cc);
if (chars != null) {
if (chars.length == 1 && chars[0].length() == 0) {
if (chars.length == 1 && chars[0].isEmpty()) {
System.out.println("X");
} else {
System.out.println("S" + toByteString(chars));
Expand Down Expand Up @@ -580,7 +580,7 @@ public void x_testReverseIsoMdb() throws Exception {
Character cc = c;
String[] chars = inlineCodes.get(cc);
if (chars != null) {
if (chars.length == 1 && chars[0].length() == 0) {
if (chars.length == 1 && chars[0].isEmpty()) {
System.out.println("X");
} else {
System.out.println("S" + toByteString(chars));
Expand Down Expand Up @@ -638,7 +638,7 @@ public void x_testReverseIsoMdb() throws Exception {

private static String toByteString(String[] chars) {
String str = join(chars, "", "");
if (str.length() > 0 && str.charAt(0) == '0') {
if (!str.isEmpty() && str.charAt(0) == '0') {
str = str.substring(1);
}
return str;
Expand Down Expand Up @@ -667,7 +667,7 @@ private static void handleInternational2Entry(String inlineCodes, String entryCo
if (entryCodes != null) {
inatExtraCodes.put(c, entryCodes.trim().split(" "));
}
if (crazyCodes != null && crazyCodes.length() > 0) {
if (crazyCodes != null && !crazyCodes.isEmpty()) {
inatCrazyCodes.put(c, crazyCodes.trim().split(" "));
}
}
Expand Down Expand Up @@ -699,7 +699,7 @@ private static String join(String[] strs, String joinStr, String prefixStr) {
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < strs.length; ++i) {
if (strs[i].length() == 0) {
if (strs[i].isEmpty()) {
continue;
}
builder.append(prefixStr).append(strs[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public String toString() {
static {
String testFormatStr = System.getProperty("io.github.spannm.jackcess.testFormats");
Set<FileFormat> testFormats = EnumSet.allOf(FileFormat.class);
if (testFormatStr != null && testFormatStr.length() > 0) {
if (testFormatStr != null && !testFormatStr.isEmpty()) {
testFormats.clear();
for (String tmp : testFormatStr.split(",")) {
testFormats.add(FileFormat.valueOf(tmp.toUpperCase()));
Expand Down

0 comments on commit 77c6026

Please sign in to comment.