Skip to content

Commit

Permalink
Remove trailing whitespace
Browse files Browse the repository at this point in the history
Use final
Use varargs
Remove extra parens
  • Loading branch information
garydgregory committed Sep 13, 2023
1 parent 85f9fa1 commit 7813a38
Show file tree
Hide file tree
Showing 49 changed files with 165 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public CreditCardValidator(final int options) {
* @return Whether the card number is valid.
*/
public boolean isValid(final String card) {
if ((card == null) || (card.length() < 13) || (card.length() > 19)) {
if (card == null || card.length() < 13 || card.length() > 19) {
return false;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ protected boolean luhnCheck(final String cardNumber) {
return false;
}

if (((count & 1) ^ oddOrEven) == 0) { // not
if ((count & 1 ^ oddOrEven) == 0) { // not
digit *= 2;
if (digit > 9) {
digit -= 9;
Expand All @@ -189,7 +189,7 @@ protected boolean luhnCheck(final String cardNumber) {
sum += digit;
}

return (sum == 0) ? false : (sum % 10 == 0);
return sum == 0 ? false : sum % 10 == 0;
}

/**
Expand Down Expand Up @@ -222,9 +222,8 @@ private static class Visa implements CreditCardType {
private static final String PREFIX = "4";
@Override
public boolean matches(final String card) {
return (
card.substring(0, 1).equals(PREFIX)
&& (card.length() == 13 || card.length() == 16));
return card.substring(0, 1).equals(PREFIX)
&& (card.length() == 13 || card.length() == 16);
}
}

Expand All @@ -233,15 +232,15 @@ private static class Amex implements CreditCardType {
@Override
public boolean matches(final String card) {
final String prefix2 = card.substring(0, 2) + ",";
return ((PREFIX.contains(prefix2)) && (card.length() == 15));
return PREFIX.contains(prefix2) && card.length() == 15;
}
}

private static class Discover implements CreditCardType {
private static final String PREFIX = "6011";
@Override
public boolean matches(final String card) {
return (card.substring(0, 4).equals(PREFIX) && (card.length() == 16));
return card.substring(0, 4).equals(PREFIX) && card.length() == 16;
}
}

Expand All @@ -250,7 +249,7 @@ private static class Mastercard implements CreditCardType {
@Override
public boolean matches(final String card) {
final String prefix2 = card.substring(0, 2) + ",";
return ((PREFIX.contains(prefix2)) && (card.length() == 16));
return PREFIX.contains(prefix2) && card.length() == 16;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public boolean isValid(final String value, final String datePattern, final boole
return false;
}

if (strict && (datePattern.length() != value.length())) {
if (strict && datePattern.length() != value.length()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected boolean isValidSymbolicDomain(String domain) {
domainSegment[i] = atomMatcher.group(1);
final int l = domainSegment[i].length() + 1;
domain =
(l >= domain.length())
l >= domain.length()
? ""
: domain.substring(l);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/commons/validator/Form.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* This contains a set of validation rules for a form/JavaBean. The information
* is contained in a list of <code>Field</code> objects. Instances of this class
* are configured with a &lt;form&gt; xml element.
* </p>
* </p>
* <p>
* The use of FastHashMap is deprecated and will be replaced in a future
* release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static Float formatFloat(final String value, final Locale locale) {

// If there was no error and we used the whole string
if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() &&
num.doubleValue() >= (Float.MAX_VALUE * -1) &&
num.doubleValue() >= Float.MAX_VALUE * -1 &&
num.doubleValue() <= Float.MAX_VALUE) {
result = Float.valueOf(num.floatValue());
}
Expand Down Expand Up @@ -339,7 +339,7 @@ public static Double formatDouble(final String value, final Locale locale) {

// If there was no error and we used the whole string
if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length() &&
num.doubleValue() >= (Double.MAX_VALUE * -1) &&
num.doubleValue() >= Double.MAX_VALUE * -1 &&
num.doubleValue() <= Double.MAX_VALUE) {
result = Double.valueOf(num.doubleValue());
}
Expand Down
50 changes: 25 additions & 25 deletions src/main/java/org/apache/commons/validator/GenericValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static boolean matchRegexp(final String value, final String regexp) {
* @return true if the value can be converted to a Byte.
*/
public static boolean isByte(final String value) {
return (GenericTypeValidator.formatByte(value) != null);
return GenericTypeValidator.formatByte(value) != null;
}

/**
Expand All @@ -86,7 +86,7 @@ public static boolean isByte(final String value) {
* @return true if the value can be converted to a Short.
*/
public static boolean isShort(final String value) {
return (GenericTypeValidator.formatShort(value) != null);
return GenericTypeValidator.formatShort(value) != null;
}

/**
Expand All @@ -96,7 +96,7 @@ public static boolean isShort(final String value) {
* @return true if the value can be converted to an Integer.
*/
public static boolean isInt(final String value) {
return (GenericTypeValidator.formatInt(value) != null);
return GenericTypeValidator.formatInt(value) != null;
}

/**
Expand All @@ -106,7 +106,7 @@ public static boolean isInt(final String value) {
* @return true if the value can be converted to a Long.
*/
public static boolean isLong(final String value) {
return (GenericTypeValidator.formatLong(value) != null);
return GenericTypeValidator.formatLong(value) != null;
}

/**
Expand All @@ -116,7 +116,7 @@ public static boolean isLong(final String value) {
* @return true if the value can be converted to a Float.
*/
public static boolean isFloat(final String value) {
return (GenericTypeValidator.formatFloat(value) != null);
return GenericTypeValidator.formatFloat(value) != null;
}

/**
Expand All @@ -126,7 +126,7 @@ public static boolean isFloat(final String value) {
* @return true if the value can be converted to a Double.
*/
public static boolean isDouble(final String value) {
return (GenericTypeValidator.formatDouble(value) != null);
return GenericTypeValidator.formatDouble(value) != null;
}

/**
Expand Down Expand Up @@ -170,7 +170,7 @@ public static boolean isDate(final String value, final String datePattern, final
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final byte value, final byte min, final byte max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand All @@ -183,7 +183,7 @@ public static boolean isInRange(final byte value, final byte min, final byte max
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final int value, final int min, final int max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand All @@ -196,7 +196,7 @@ public static boolean isInRange(final int value, final int min, final int max) {
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final float value, final float min, final float max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand All @@ -209,7 +209,7 @@ public static boolean isInRange(final float value, final float min, final float
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final short value, final short min, final short max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand All @@ -222,7 +222,7 @@ public static boolean isInRange(final short value, final short min, final short
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final long value, final long min, final long max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand All @@ -235,7 +235,7 @@ public static boolean isInRange(final long value, final long min, final long max
* @return true if the value is in the specified range.
*/
public static boolean isInRange(final double value, final double min, final double max) {
return ((value >= min) && (value <= max));
return value >= min && value <= max;
}

/**
Expand Down Expand Up @@ -277,7 +277,7 @@ public static boolean isUrl(final String value) {
* @return true if the value's length is less than the specified maximum.
*/
public static boolean maxLength(final String value, final int max) {
return (value.length() <= max);
return value.length() <= max;
}

/**
Expand All @@ -290,7 +290,7 @@ public static boolean maxLength(final String value, final int max) {
*/
public static boolean maxLength(final String value, final int max, final int lineEndLength) {
final int adjustAmount = adjustForLineEnding(value, lineEndLength);
return ((value.length() + adjustAmount) <= max);
return value.length() + adjustAmount <= max;
}

/**
Expand All @@ -301,7 +301,7 @@ public static boolean maxLength(final String value, final int max, final int lin
* @return true if the value's length is more than the specified minimum.
*/
public static boolean minLength(final String value, final int min) {
return (value.length() >= min);
return value.length() >= min;
}

/**
Expand All @@ -314,7 +314,7 @@ public static boolean minLength(final String value, final int min) {
*/
public static boolean minLength(final String value, final int min, final int lineEndLength) {
final int adjustAmount = adjustForLineEnding(value, lineEndLength);
return ((value.length() + adjustAmount) >= min);
return value.length() + adjustAmount >= min;
}

/**
Expand All @@ -337,7 +337,7 @@ private static int adjustForLineEnding(final String value, final int lineEndLeng
rCount++;
}
}
return ((nCount * lineEndLength) - (rCount + nCount));
return nCount * lineEndLength - (rCount + nCount);
}

// See http://issues.apache.org/bugzilla/show_bug.cgi?id=29015 WRT the "value" methods
Expand All @@ -350,7 +350,7 @@ private static int adjustForLineEnding(final String value, final int lineEndLeng
* @return true if the value is &gt;= the specified minimum.
*/
public static boolean minValue(final int value, final int min) {
return (value >= min);
return value >= min;
}

/**
Expand All @@ -361,7 +361,7 @@ public static boolean minValue(final int value, final int min) {
* @return true if the value is &gt;= the specified minimum.
*/
public static boolean minValue(final long value, final long min) {
return (value >= min);
return value >= min;
}

/**
Expand All @@ -372,7 +372,7 @@ public static boolean minValue(final long value, final long min) {
* @return true if the value is &gt;= the specified minimum.
*/
public static boolean minValue(final double value, final double min) {
return (value >= min);
return value >= min;
}

/**
Expand All @@ -383,7 +383,7 @@ public static boolean minValue(final double value, final double min) {
* @return true if the value is &gt;= the specified minimum.
*/
public static boolean minValue(final float value, final float min) {
return (value >= min);
return value >= min;
}

/**
Expand All @@ -394,7 +394,7 @@ public static boolean minValue(final float value, final float min) {
* @return true if the value is &lt;= the specified maximum.
*/
public static boolean maxValue(final int value, final int max) {
return (value <= max);
return value <= max;
}

/**
Expand All @@ -405,7 +405,7 @@ public static boolean maxValue(final int value, final int max) {
* @return true if the value is &lt;= the specified maximum.
*/
public static boolean maxValue(final long value, final long max) {
return (value <= max);
return value <= max;
}

/**
Expand All @@ -416,7 +416,7 @@ public static boolean maxValue(final long value, final long max) {
* @return true if the value is &lt;= the specified maximum.
*/
public static boolean maxValue(final double value, final double max) {
return (value <= max);
return value <= max;
}

/**
Expand All @@ -427,7 +427,7 @@ public static boolean maxValue(final double value, final double max) {
* @return true if the value is &lt;= the specified maximum.
*/
public static boolean maxValue(final float value, final float max) {
return (value <= max);
return value <= max;
}

}
6 changes: 3 additions & 3 deletions src/main/java/org/apache/commons/validator/UrlValidator.java
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ protected boolean isValidAuthority(final String authority) {
domainSegment[segmentCount] = atomMatcher.group(1);
segmentLength = domainSegment[segmentCount].length() + 1;
hostIP =
(segmentLength >= hostIP.length())
segmentLength >= hostIP.length()
? ""
: hostIP.substring(segmentLength);

Expand Down Expand Up @@ -407,13 +407,13 @@ protected boolean isValidPath(final String path) {
}

final int slash2Count = countToken("//", path);
if (options.isOff(ALLOW_2_SLASHES) && (slash2Count > 0)) {
if (options.isOff(ALLOW_2_SLASHES) && slash2Count > 0) {
return false;
}

final int slashCount = countToken("/", path);
final int dot2Count = countToken("..", path);
if (dot2Count > 0 && (slashCount - slash2Count - 1) <= dot2Count){
if (dot2Count > 0 && slashCount - slash2Count - 1 <= dot2Count){
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ private String formatJavascriptFileName() {
* @return true if the javascript for this action has already been loaded.
*/
private boolean javascriptAlreadyLoaded() {
return (this.javascript != null);
return this.javascript != null;
}

/**
Expand Down Expand Up @@ -564,7 +564,7 @@ boolean executeValidationMethod(
}

final boolean valid = this.isValid(result);
if (!valid || (valid && !onlyReturnErrors(params))) {
if (!valid || valid && !onlyReturnErrors(params)) {
results.add(field, this.name, valid, result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ protected String buildKey(final FormSet fs) {
* Assembles a Locale code from the given parts.
*/
private String buildLocale(final String lang, final String country, final String variant) {
String key = ((lang != null && !lang.isEmpty()) ? lang : "");
key += ((country != null && !country.isEmpty()) ? "_" + country : "");
key += ((variant != null && !variant.isEmpty()) ? "_" + variant : "");
String key = lang != null && !lang.isEmpty() ? lang : "";
key += country != null && !country.isEmpty() ? "_" + country : "";
key += variant != null && !variant.isEmpty() ? "_" + variant : "";
return key;
}

Expand Down
Loading

0 comments on commit 7813a38

Please sign in to comment.