Use consistent ternary expression style
Update all ternary expressions so that the condition is always in parentheses and "not equals" is used in the test. This helps to bring consistency across the codebase which makes ternary expression easier to scan. For example: `a = (a != null) ? a : b` Issue gh-8945
This commit is contained in:
+1
-1
@@ -97,7 +97,7 @@ public class BCryptPasswordEncoder implements PasswordEncoder {
|
||||
throw new IllegalArgumentException("Bad strength");
|
||||
}
|
||||
this.version = version;
|
||||
this.strength = strength == -1 ? 10 : strength;
|
||||
this.strength = (strength == -1) ? 10 : strength;
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
|
||||
@@ -333,9 +333,9 @@ public final class Base64 {
|
||||
// significant bytes passed in the array.
|
||||
// We have to shift left 24 in order to flush out the 1's that appear
|
||||
// when Java treats a value as negative that is cast from a byte to an int.
|
||||
int inBuff = (numSigBytes > 0 ? ((source[srcOffset] << 24) >>> 8) : 0)
|
||||
| (numSigBytes > 1 ? ((source[srcOffset + 1] << 24) >>> 16) : 0)
|
||||
| (numSigBytes > 2 ? ((source[srcOffset + 2] << 24) >>> 24) : 0);
|
||||
int inBuff = ((numSigBytes > 0) ? ((source[srcOffset] << 24) >>> 8) : 0)
|
||||
| ((numSigBytes > 1) ? ((source[srcOffset + 1] << 24) >>> 16) : 0)
|
||||
| ((numSigBytes > 2) ? ((source[srcOffset + 2] << 24) >>> 24) : 0);
|
||||
|
||||
switch (numSigBytes) {
|
||||
case 3:
|
||||
@@ -404,8 +404,10 @@ public final class Base64 {
|
||||
// Try to determine more precisely how big the array needs to be.
|
||||
// If we get it right, we don't have to do an array copy, and
|
||||
// we save a bunch of memory.
|
||||
int encLen = (len / 3) * 4 + (len % 3 > 0 ? 4 : 0); // Bytes needed for actual
|
||||
// encoding
|
||||
|
||||
// Bytes needed for actual encoding
|
||||
int encLen = (len / 3) * 4 + ((len % 3 > 0) ? 4 : 0);
|
||||
|
||||
if (breakLines) {
|
||||
encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters
|
||||
}
|
||||
|
||||
+5
-5
@@ -71,7 +71,7 @@ public final class AesBytesEncryptor implements BytesEncryptor {
|
||||
}
|
||||
|
||||
public AlgorithmParameterSpec getParameterSpec(byte[] iv) {
|
||||
return this == CBC ? new IvParameterSpec(iv) : new GCMParameterSpec(128, iv);
|
||||
return (this != CBC) ? new GCMParameterSpec(128, iv) : new IvParameterSpec(iv);
|
||||
}
|
||||
|
||||
public Cipher createCipher() {
|
||||
@@ -110,7 +110,7 @@ public final class AesBytesEncryptor implements BytesEncryptor {
|
||||
this.alg = alg;
|
||||
this.encryptor = alg.createCipher();
|
||||
this.decryptor = alg.createCipher();
|
||||
this.ivGenerator = ivGenerator != null ? ivGenerator : alg.defaultIvGenerator();
|
||||
this.ivGenerator = (ivGenerator != null) ? ivGenerator : alg.defaultIvGenerator();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -119,7 +119,7 @@ public final class AesBytesEncryptor implements BytesEncryptor {
|
||||
byte[] iv = this.ivGenerator.generateKey();
|
||||
CipherUtils.initCipher(this.encryptor, Cipher.ENCRYPT_MODE, this.secretKey, this.alg.getParameterSpec(iv));
|
||||
byte[] encrypted = CipherUtils.doFinal(this.encryptor, bytes);
|
||||
return this.ivGenerator != NULL_IV_GENERATOR ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
return (this.ivGenerator != NULL_IV_GENERATOR) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,12 +129,12 @@ public final class AesBytesEncryptor implements BytesEncryptor {
|
||||
byte[] iv = iv(encryptedBytes);
|
||||
CipherUtils.initCipher(this.decryptor, Cipher.DECRYPT_MODE, this.secretKey, this.alg.getParameterSpec(iv));
|
||||
return CipherUtils.doFinal(this.decryptor,
|
||||
this.ivGenerator != NULL_IV_GENERATOR ? encrypted(encryptedBytes, iv.length) : encryptedBytes);
|
||||
(this.ivGenerator != NULL_IV_GENERATOR) ? encrypted(encryptedBytes, iv.length) : encryptedBytes);
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] iv(byte[] encrypted) {
|
||||
return this.ivGenerator != NULL_IV_GENERATOR
|
||||
return (this.ivGenerator != NULL_IV_GENERATOR)
|
||||
? EncodingUtils.subArray(encrypted, 0, this.ivGenerator.getKeyLength())
|
||||
: NULL_IV_GENERATOR.generateKey();
|
||||
}
|
||||
|
||||
+1
-1
@@ -54,7 +54,7 @@ public class BouncyCastleAesCbcBytesEncryptor extends BouncyCastleAesBytesEncryp
|
||||
new CBCBlockCipher(new org.bouncycastle.crypto.engines.AESFastEngine()), new PKCS7Padding());
|
||||
blockCipher.init(true, new ParametersWithIV(this.secretKey, iv));
|
||||
byte[] encrypted = process(blockCipher, bytes);
|
||||
return iv != null ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
return (iv != null) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public class BouncyCastleAesGcmBytesEncryptor extends BouncyCastleAesBytesEncryp
|
||||
blockCipher.init(true, new AEADParameters(this.secretKey, 128, iv, null));
|
||||
|
||||
byte[] encrypted = process(blockCipher, bytes);
|
||||
return iv != null ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
return (iv != null) ? EncodingUtils.concatenate(iv, encrypted) : encrypted;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ public class LdapShaPasswordEncoder implements PasswordEncoder {
|
||||
*/
|
||||
@Override
|
||||
public boolean matches(CharSequence rawPassword, String encodedPassword) {
|
||||
return matches(rawPassword == null ? null : rawPassword.toString(), encodedPassword);
|
||||
return matches((rawPassword != null) ? rawPassword.toString() : null, encodedPassword);
|
||||
}
|
||||
|
||||
private boolean matches(String rawPassword, String encodedPassword) {
|
||||
|
||||
Reference in New Issue
Block a user