Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify boolean expressions #857

Merged
merged 1 commit into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/com/microsoft/sqlserver/jdbc/Column.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void updateValue(JDBCType jdbcType, Object value, JavaType javaType, StreamSette
if (JDBCType.TINYINT == cryptoMetadata.getBaseTypeInfo().getSSType().getJDBCType()
&& javaType == JavaType.SHORT) {
if (value instanceof Boolean) {
if (true == ((boolean) value)) {
if ((boolean) value) {
value = 1;
} else {
value = 0;
Expand Down Expand Up @@ -251,7 +251,7 @@ else if (jdbcType.isBinary()) {
}

if (Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, con)) {
if ((null == cryptoMetadata) && true == forceEncrypt) {
if ((null == cryptoMetadata) && forceEncrypt) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumnRS"));
Object[] msgArgs = {parameterIndex};
Expand All @@ -273,7 +273,7 @@ else if (jdbcType.isBinary()) {
}
}
} else {
if (true == forceEncrypt) {
if (forceEncrypt) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAEFalseRS"));
Object[] msgArgs = {parameterIndex};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static String concatPrimaryDatabase(String primary, String instance, Str
static FailoverInfo getFailoverInfo(SQLServerConnection connection, String primaryServer, String instance,
String database) {
synchronized (FailoverMapSingleton.class) {
if (true == failoverMap.isEmpty()) {
if (failoverMap.isEmpty()) {
return null;
} else {
String mapKey = concatPrimaryDatabase(primaryServer, instance, database);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@ private void findSocketUsingJavaNIO(InetAddress[] inetAddrs, int portNumber,

// ch.finishConnect should either return true or throw an exception
// as we have subscribed for OP_CONNECT.
assert connected == true : "finishConnect on channel:" + ch + " cannot be false";
assert connected : "finishConnect on channel:" + ch + " cannot be false";

selectedChannel = ch;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void setValue(JDBCType jdbcType, Object value, JavaType javaType, StreamSetterAr
}

// forceEncryption is true, shouldhonorae is false
if ((true == forceEncrypt) && (false == Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, con))) {
if (forceEncrypt && !Util.shouldHonorAEForParameters(stmtColumnEncriptionSetting, con)) {

MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAEFalse"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ private void writeColumnMetaDataColumnData(TDSWriter tdsWriter, int idx) throws
// the driver will not sent AE information, so, we need to set Encryption bit flag to 0.
if (null == srcColumnMetadata.get(srcColumnIndex).cryptoMeta
&& null == destColumnMetadata.get(destColumnIndex).cryptoMeta
&& true == copyOptions.isAllowEncryptedValueModifications()) {
&& copyOptions.isAllowEncryptedValueModifications()) {

// flags[1]>>3 & 0x01 is the encryption bit flag.
// it is the 4th least significant bit in this byte, so minus 8 to set it to 0.
Expand Down Expand Up @@ -1477,27 +1477,27 @@ private String createInsertBulkCommand(TDSWriter tdsWriter) throws SQLServerExce
}
}

if (true == copyOptions.isCheckConstraints()) {
if (copyOptions.isCheckConstraints()) {
bulkOptions.add("CHECK_CONSTRAINTS");
}

if (true == copyOptions.isFireTriggers()) {
if (copyOptions.isFireTriggers()) {
bulkOptions.add("FIRE_TRIGGERS");
}

if (true == copyOptions.isKeepNulls()) {
if (copyOptions.isKeepNulls()) {
bulkOptions.add("KEEP_NULLS");
}

if (copyOptions.getBatchSize() > 0) {
bulkOptions.add("ROWS_PER_BATCH = " + copyOptions.getBatchSize());
}

if (true == copyOptions.isTableLock()) {
if (copyOptions.isTableLock()) {
bulkOptions.add("TABLOCK");
}

if (true == copyOptions.isAllowEncryptedValueModifications()) {
if (copyOptions.isAllowEncryptedValueModifications()) {
bulkOptions.add("ALLOW_ENCRYPTED_VALUE_MODIFICATIONS");
}

Expand Down
26 changes: 13 additions & 13 deletions src/main/java/com/microsoft/sqlserver/jdbc/SQLServerConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ Connection connectInternal(Properties propsIn,
}
trustedServerNameAE = sPropValue;

if (true == serverNameAsACE) {
if (serverNameAsACE) {
try {
sPropValue = java.net.IDN.toASCII(sPropValue);
} catch (IllegalArgumentException ex) {
Expand Down Expand Up @@ -1529,8 +1529,8 @@ Connection connectInternal(Properties propsIn,
}
authenticationString = SqlAuthentication.valueOfString(sPropValue).toString();

if ((true == integratedSecurity)
&& (!authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString()))) {
if (integratedSecurity
&& !authenticationString.equalsIgnoreCase(SqlAuthentication.NotSpecified.toString())) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + " "
+ SQLServerException.getErrString("R_SetAuthenticationWhenIntegratedSecurityTrue"));
Expand Down Expand Up @@ -1591,7 +1591,7 @@ Connection connectInternal(Properties propsIn,
throw new SQLServerException(SQLServerException.getErrString("R_AccessTokenCannotBeEmpty"), null);
}

if ((true == integratedSecurity) && (null != accessTokenInByte)) {
if (integratedSecurity && (null != accessTokenInByte)) {
if (connectionlogger.isLoggable(Level.SEVERE)) {
connectionlogger.severe(toString() + " "
+ SQLServerException.getErrString("R_SetAccesstokenWhenIntegratedSecurityTrue"));
Expand Down Expand Up @@ -2983,7 +2983,7 @@ String sqlStatementToSetTransactionIsolationLevel() throws SQLServerException {
* @return the required syntax
*/
static String sqlStatementToSetCommit(boolean autoCommit) {
return (true == autoCommit) ? "set implicit_transactions off " : "set implicit_transactions on ";
return autoCommit ? "set implicit_transactions off " : "set implicit_transactions on ";
}

@Override
Expand Down Expand Up @@ -3033,7 +3033,7 @@ public void setAutoCommit(boolean newAutoCommitMode) throws SQLServerException {

// When changing to auto-commit from inside an existing transaction,
// commit that transaction first.
if (newAutoCommitMode == true)
if (newAutoCommitMode)
commitPendingTransaction = "IF @@TRANCOUNT > 0 COMMIT TRAN ";

if (connectionlogger.isLoggable(Level.FINER)) {
Expand Down Expand Up @@ -3457,19 +3457,19 @@ int writeFedAuthFeatureRequest(boolean write, TDSWriter tdsWriter,
// set upper 7 bits of options to indicate fed auth library type
switch (fedAuthFeatureExtensionData.libraryType) {
case TDS.TDS_FEDAUTH_LIBRARY_ADAL:
assert federatedAuthenticationInfoRequested == true;
assert federatedAuthenticationInfoRequested;
options |= TDS.TDS_FEDAUTH_LIBRARY_ADAL << 1;
break;
case TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN:
assert federatedAuthenticationRequested == true;
assert federatedAuthenticationRequested;
options |= TDS.TDS_FEDAUTH_LIBRARY_SECURITYTOKEN << 1;
break;
default:
assert (false); // Unrecognized library type for fedauth feature extension request
break;
}

options |= (byte) (fedAuthFeatureExtensionData.fedAuthRequiredPreLoginResponse == true ? 0x01 : 0x00);
options |= (byte) (fedAuthFeatureExtensionData.fedAuthRequiredPreLoginResponse ? 0x01 : 0x00);

// write FeatureDataLen
tdsWriter.writeInt(dataLen);
Expand Down Expand Up @@ -4279,7 +4279,7 @@ private void onFeatureExtAck(byte featureId, byte[] data) throws SQLServerExcept
}

byte enabled = data[1];
serverSupportsDataClassification = (enabled == 0) ? false : true;
serverSupportsDataClassification = enabled != 0;
}
case TDS.TDS_FEATURE_EXT_UTF8SUPPORT: {
if (connectionlogger.isLoggable(Level.FINER)) {
Expand Down Expand Up @@ -4977,7 +4977,7 @@ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
}

final private Savepoint setNamedSavepoint(String sName) throws SQLServerException {
if (true == databaseAutoCommitMode) {
if (databaseAutoCommitMode) {
SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantSetSavepoint"),
null, false);
}
Expand Down Expand Up @@ -5028,7 +5028,7 @@ public void rollback(Savepoint s) throws SQLServerException {
loggerExternal.finer(toString() + " ActivityId: " + ActivityCorrelator.getNext().toString());
}
checkClosed();
if (true == databaseAutoCommitMode) {
if (databaseAutoCommitMode) {
SQLServerException.makeFromDriverError(this, this, SQLServerException.getErrString("R_cantInvokeRollback"),
null, false);
}
Expand Down Expand Up @@ -5988,7 +5988,7 @@ boolean isAzureDW() throws SQLServerException, SQLException {
// Base data type: int
final int ENGINE_EDITION_FOR_SQL_AZURE_DW = 6;
rs.next();
isAzureDW = (rs.getInt(1) == ENGINE_EDITION_FOR_SQL_AZURE_DW) ? true : false;
isAzureDW = rs.getInt(1) == ENGINE_EDITION_FOR_SQL_AZURE_DW;
}
return isAzureDW;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ Reference getReferenceInternal(String dataSourceClassString) {
if (propertyName.equals(SQLServerDriverStringProperty.TRUST_STORE_PASSWORD.toString())) {
// The property set and the variable set at the same time is not
// possible
assert trustStorePasswordStripped == false;
assert !trustStorePasswordStripped;
ref.add(new StringRefAddr("trustStorePasswordStripped", "true"));
} else {
// do not add passwords to the collection. we have normal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ private void getParameterEncryptionMetadata(Parameter[] params) throws SQLServer
// Decrypt the symmetric key.(This will also validate and throw if needed).
SQLServerSecurityUtility.decryptSymmetricKey(params[paramIndex].cryptoMeta, connection);
} else {
if (true == params[paramIndex].getForceEncryption()) {
if (params[paramIndex].getForceEncryption()) {
MessageFormat form = new MessageFormat(
SQLServerException.getErrString("R_ForceEncryptionTrue_HonorAETrue_UnencryptedColumn"));
Object[] msgArgs = {userSQL, paramIndex + 1};
Expand Down Expand Up @@ -1081,7 +1081,7 @@ private ResultSet buildExecuteMetaData() throws SQLServerException {
internalStmt = (SQLServerStatement) connection.createStatement();
emptyResultSet = internalStmt.executeQueryInternal("set fmtonly on " + fmtSQL + "\nset fmtonly off");
} catch (SQLException sqle) {
if (false == sqle.getMessage().equals(SQLServerException.getErrString("R_noResultset"))) {
if (!sqle.getMessage().equals(SQLServerException.getErrString("R_noResultset"))) {
// if the error is not no resultset then throw a processings error.
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_processingError"));
Object[] msgArgs = {sqle.getMessage()};
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/microsoft/sqlserver/jdbc/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ else if (ch == ':')
name = SQLServerDriver.getNormalizedPropertyName(name, logger);
if (null != name) {
if (logger.isLoggable(Level.FINE)) {
if (false == name.equals(SQLServerDriverStringProperty.USER.toString())) {
if (!name.equals(SQLServerDriverStringProperty.USER.toString())) {
if (!name.toLowerCase(Locale.ENGLISH).contains("password")
&& !name.toLowerCase(Locale.ENGLISH).contains("keystoresecret")) {
logger.fine("Property:" + name + " Value:" + value);
Expand Down Expand Up @@ -417,8 +417,8 @@ else if (ch == ':')
name = SQLServerDriver.getNormalizedPropertyName(name, logger);
if (null != name) {
if (logger.isLoggable(Level.FINE)) {
if ((false == name.equals(SQLServerDriverStringProperty.USER.toString()))
&& (false == name.equals(SQLServerDriverStringProperty.PASSWORD.toString())))
if (!name.equals(SQLServerDriverStringProperty.USER.toString())
&& !name.equals(SQLServerDriverStringProperty.PASSWORD.toString()))
logger.fine("Property:" + name + " Value:" + value);
}
p.put(name, value);
Expand Down Expand Up @@ -487,9 +487,9 @@ else if (ch == ':')
name = SQLServerDriver.getNormalizedPropertyName(name, logger);
if (null != name) {
if (logger.isLoggable(Level.FINE)) {
if ((false == name.equals(SQLServerDriverStringProperty.USER.toString()))
&& (false == name.equals(SQLServerDriverStringProperty.PASSWORD.toString()))
&& (false == name.equals(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString())))
if (!name.equals(SQLServerDriverStringProperty.USER.toString())
&& !name.equals(SQLServerDriverStringProperty.PASSWORD.toString())
&& !name.equals(SQLServerDriverStringProperty.KEY_STORE_SECRET.toString()))
logger.fine("Property:" + name + " Value:" + value);
}
p.put(name, value);
Expand Down