Unverified 提交 705e592e authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #863 from igor-suhorukov/master

Polish: use isEmpty() to check whether the collection is empty or not.
...@@ -548,7 +548,7 @@ public class Parser { ...@@ -548,7 +548,7 @@ public class Parser {
} }
private DbException getSyntaxError() { private DbException getSyntaxError() {
if (expectedList == null || expectedList.size() == 0) { if (expectedList == null || expectedList.isEmpty()) {
return DbException.getSyntaxError(sqlCommand, parseIndex); return DbException.getSyntaxError(sqlCommand, parseIndex);
} }
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
...@@ -3023,7 +3023,7 @@ public class Parser { ...@@ -3023,7 +3023,7 @@ public class Parser {
// this can occur when parsing expressions only (for // this can occur when parsing expressions only (for
// example check constraints) // example check constraints)
throw getSyntaxError(); throw getSyntaxError();
} else if (parameters.size() > 0) { } else if (!parameters.isEmpty()) {
throw DbException throw DbException
.get(ErrorCode.CANNOT_MIX_INDEXED_AND_UNINDEXED_PARAMS); .get(ErrorCode.CANNOT_MIX_INDEXED_AND_UNINDEXED_PARAMS);
} }
...@@ -4725,7 +4725,7 @@ public class Parser { ...@@ -4725,7 +4725,7 @@ public class Parser {
int scale, displaySize; int scale, displaySize;
Column column; Column column;
String columnName = "C" + (i + 1); String columnName = "C" + (i + 1);
if (rows.size() == 0) { if (rows.isEmpty()) {
if (type == Value.UNKNOWN) { if (type == Value.UNKNOWN) {
type = Value.STRING; type = Value.STRING;
} }
......
...@@ -119,7 +119,7 @@ public class CreateTable extends SchemaCommand { ...@@ -119,7 +119,7 @@ public class CreateTable extends SchemaCommand {
} }
if (asQuery != null) { if (asQuery != null) {
asQuery.prepare(); asQuery.prepare();
if (data.columns.size() == 0) { if (data.columns.isEmpty()) {
generateColumnsFromQuery(); generateColumnsFromQuery();
} else if (data.columns.size() != asQuery.getColumnCount()) { } else if (data.columns.size() != asQuery.getColumnCount()) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
...@@ -98,7 +98,7 @@ public class CreateView extends SchemaCommand { ...@@ -98,7 +98,7 @@ public class CreateView extends SchemaCommand {
querySQL = selectSQL; querySQL = selectSQL;
} else { } else {
ArrayList<Parameter> params = select.getParameters(); ArrayList<Parameter> params = select.getParameters();
if (params != null && params.size() > 0) { if (params != null && !params.isEmpty()) {
throw DbException.getUnsupportedException("parameters in views"); throw DbException.getUnsupportedException("parameters in views");
} }
querySQL = select.getPlanSQL(); querySQL = select.getPlanSQL();
......
...@@ -77,7 +77,7 @@ public class DropTable extends SchemaCommand { ...@@ -77,7 +77,7 @@ public class DropTable extends SchemaCommand {
if (dropAction == ConstraintActionType.RESTRICT) { if (dropAction == ConstraintActionType.RESTRICT) {
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews(); CopyOnWriteArrayList<TableView> dependentViews = table.getDependentViews();
if (dependentViews != null && dependentViews.size() > 0) { if (dependentViews != null && !dependentViews.isEmpty()) {
for (TableView v : dependentViews) { for (TableView v : dependentViews) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
buff.append(v.getName()); buff.append(v.getName());
...@@ -86,7 +86,7 @@ public class DropTable extends SchemaCommand { ...@@ -86,7 +86,7 @@ public class DropTable extends SchemaCommand {
if (session.getDatabase() if (session.getDatabase()
.getSettings().standardDropTableRestrict) { .getSettings().standardDropTableRestrict) {
final List<Constraint> constraints = table.getConstraints(); final List<Constraint> constraints = table.getConstraints();
if (constraints != null && constraints.size() > 0) { if (constraints != null && !constraints.isEmpty()) {
for (Constraint c : constraints) { for (Constraint c : constraints) {
if (c.getTable() != table) { if (c.getTable() != table) {
buff.appendExceptFirst(", "); buff.appendExceptFirst(", ");
......
...@@ -243,7 +243,7 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -243,7 +243,7 @@ public class Insert extends Prepared implements ResultTarget {
if (sortedInsertMode) { if (sortedInsertMode) {
buff.append("SORTED "); buff.append("SORTED ");
} }
if (list.size() > 0) { if (!list.isEmpty()) {
buff.append("VALUES "); buff.append("VALUES ");
int row = 0; int row = 0;
if (list.size() > 1) { if (list.size() > 1) {
...@@ -274,14 +274,14 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -274,14 +274,14 @@ public class Insert extends Prepared implements ResultTarget {
@Override @Override
public void prepare() { public void prepare() {
if (columns == null) { if (columns == null) {
if (list.size() > 0 && list.get(0).length == 0) { if (!list.isEmpty() && list.get(0).length == 0) {
// special case where table is used as a sequence // special case where table is used as a sequence
columns = new Column[0]; columns = new Column[0];
} else { } else {
columns = table.getColumns(); columns = table.getColumns();
} }
} }
if (list.size() > 0) { if (!list.isEmpty()) {
for (Expression[] expr : list) { for (Expression[] expr : list) {
if (expr.length != columns.length) { if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
...@@ -84,7 +84,7 @@ public class Merge extends Prepared { ...@@ -84,7 +84,7 @@ public class Merge extends Prepared {
session.getUser().checkRight(targetTable, Right.INSERT); session.getUser().checkRight(targetTable, Right.INSERT);
session.getUser().checkRight(targetTable, Right.UPDATE); session.getUser().checkRight(targetTable, Right.UPDATE);
setCurrentRowNumber(0); setCurrentRowNumber(0);
if (valuesExpressionList.size() > 0) { if (!valuesExpressionList.isEmpty()) {
// process values in list // process values in list
count = 0; count = 0;
for (int x = 0, size = valuesExpressionList.size(); x < size; x++) { for (int x = 0, size = valuesExpressionList.size(); x < size; x++) {
...@@ -221,7 +221,7 @@ public class Merge extends Prepared { ...@@ -221,7 +221,7 @@ public class Merge extends Prepared {
buff.append(')'); buff.append(')');
} }
buff.append('\n'); buff.append('\n');
if (valuesExpressionList.size() > 0) { if (!valuesExpressionList.isEmpty()) {
buff.append("VALUES "); buff.append("VALUES ");
int row = 0; int row = 0;
for (Expression[] expr : valuesExpressionList) { for (Expression[] expr : valuesExpressionList) {
...@@ -249,14 +249,14 @@ public class Merge extends Prepared { ...@@ -249,14 +249,14 @@ public class Merge extends Prepared {
@Override @Override
public void prepare() { public void prepare() {
if (columns == null) { if (columns == null) {
if (valuesExpressionList.size() > 0 && valuesExpressionList.get(0).length == 0) { if (!valuesExpressionList.isEmpty() && valuesExpressionList.get(0).length == 0) {
// special case where table is used as a sequence // special case where table is used as a sequence
columns = new Column[0]; columns = new Column[0];
} else { } else {
columns = targetTable.getColumns(); columns = targetTable.getColumns();
} }
} }
if (valuesExpressionList.size() > 0) { if (!valuesExpressionList.isEmpty()) {
for (Expression[] expr : valuesExpressionList) { for (Expression[] expr : valuesExpressionList) {
if (expr.length != columns.length) { if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
...@@ -315,7 +315,7 @@ public class MergeUsing extends Prepared { ...@@ -315,7 +315,7 @@ public class MergeUsing extends Prepared {
buff.append(')'); buff.append(')');
} }
buff.append('\n'); buff.append('\n');
if (valuesExpressionList.size() > 0) { if (!valuesExpressionList.isEmpty()) {
buff.append("VALUES "); buff.append("VALUES ");
int row = 0; int row = 0;
for (Expression[] expr : valuesExpressionList) { for (Expression[] expr : valuesExpressionList) {
...@@ -376,7 +376,7 @@ public class MergeUsing extends Prepared { ...@@ -376,7 +376,7 @@ public class MergeUsing extends Prepared {
onCondition.createIndexConditions(session, targetTableFilter); onCondition.createIndexConditions(session, targetTableFilter);
if (columns == null) { if (columns == null) {
if (valuesExpressionList.size() > 0 if (!valuesExpressionList.isEmpty()
&& valuesExpressionList.get(0).length == 0) { && valuesExpressionList.get(0).length == 0) {
// special case where table is used as a sequence // special case where table is used as a sequence
columns = new Column[0]; columns = new Column[0];
...@@ -384,7 +384,7 @@ public class MergeUsing extends Prepared { ...@@ -384,7 +384,7 @@ public class MergeUsing extends Prepared {
columns = targetTable.getColumns(); columns = targetTable.getColumns();
} }
} }
if (valuesExpressionList.size() > 0) { if (!valuesExpressionList.isEmpty()) {
for (Expression[] expr : valuesExpressionList) { for (Expression[] expr : valuesExpressionList) {
if (expr.length != columns.length) { if (expr.length != columns.length) {
throw DbException throw DbException
......
...@@ -82,7 +82,7 @@ public class Replace extends Prepared { ...@@ -82,7 +82,7 @@ public class Replace extends Prepared {
session.getUser().checkRight(table, Right.INSERT); session.getUser().checkRight(table, Right.INSERT);
session.getUser().checkRight(table, Right.UPDATE); session.getUser().checkRight(table, Right.UPDATE);
setCurrentRowNumber(0); setCurrentRowNumber(0);
if (list.size() > 0) { if (!list.isEmpty()) {
count = 0; count = 0;
for (int x = 0, size = list.size(); x < size; x++) { for (int x = 0, size = list.size(); x < size; x++) {
setCurrentRowNumber(x + 1); setCurrentRowNumber(x + 1);
...@@ -208,7 +208,7 @@ public class Replace extends Prepared { ...@@ -208,7 +208,7 @@ public class Replace extends Prepared {
} }
buff.append(')'); buff.append(')');
buff.append('\n'); buff.append('\n');
if (list.size() > 0) { if (!list.isEmpty()) {
buff.append("VALUES "); buff.append("VALUES ");
int row = 0; int row = 0;
for (Expression[] expr : list) { for (Expression[] expr : list) {
...@@ -236,14 +236,14 @@ public class Replace extends Prepared { ...@@ -236,14 +236,14 @@ public class Replace extends Prepared {
@Override @Override
public void prepare() { public void prepare() {
if (columns == null) { if (columns == null) {
if (list.size() > 0 && list.get(0).length == 0) { if (!list.isEmpty() && list.get(0).length == 0) {
// special case where table is used as a sequence // special case where table is used as a sequence
columns = new Column[0]; columns = new Column[0];
} else { } else {
columns = table.getColumns(); columns = table.getColumns();
} }
} }
if (list.size() > 0) { if (!list.isEmpty()) {
for (Expression[] expr : list) { for (Expression[] expr : list) {
if (expr.length != columns.length) { if (expr.length != columns.length) {
throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH); throw DbException.get(ErrorCode.COLUMN_COUNT_DOES_NOT_MATCH);
......
...@@ -1212,7 +1212,7 @@ public class Database implements DataHandler { ...@@ -1212,7 +1212,7 @@ public class Database implements DataHandler {
trace.info("disconnecting session #{0}", session.getId()); trace.info("disconnecting session #{0}", session.getId());
} }
} }
if (userSessions.size() == 0 && if (userSessions.isEmpty() &&
session != systemSession && session != lobSession) { session != systemSession && session != lobSession) {
if (closeDelay == 0) { if (closeDelay == 0) {
close(false); close(false);
...@@ -1275,7 +1275,7 @@ public class Database implements DataHandler { ...@@ -1275,7 +1275,7 @@ public class Database implements DataHandler {
} }
closing = true; closing = true;
stopServer(); stopServer();
if (userSessions.size() > 0) { if (!userSessions.isEmpty()) {
if (!fromShutdownHook) { if (!fromShutdownHook) {
return; return;
} }
...@@ -1290,7 +1290,7 @@ public class Database implements DataHandler { ...@@ -1290,7 +1290,7 @@ public class Database implements DataHandler {
// set it to null, to make sure it's called only once // set it to null, to make sure it's called only once
eventListener = null; eventListener = null;
e.closingDatabase(); e.closingDatabase();
if (userSessions.size() > 0) { if (!userSessions.isEmpty()) {
// if a connection was opened, we can't close the database // if a connection was opened, we can't close the database
return; return;
} }
......
...@@ -63,7 +63,7 @@ public class Engine implements SessionFactory { ...@@ -63,7 +63,7 @@ public class Engine implements SessionFactory {
} }
database = new Database(ci, cipher); database = new Database(ci, cipher);
opened = true; opened = true;
if (database.getAllUsers().size() == 0) { if (database.getAllUsers().isEmpty()) {
// users is the last thing we add, so if no user is around, // users is the last thing we add, so if no user is around,
// the database is new (or not initialized correctly) // the database is new (or not initialized correctly)
user = new User(database, database.allocateObjectId(), user = new User(database, database.allocateObjectId(),
......
...@@ -163,7 +163,7 @@ public class FunctionAlias extends SchemaObjectBase { ...@@ -163,7 +163,7 @@ public class FunctionAlias extends SchemaObjectBase {
list.add(javaMethod); list.add(javaMethod);
} }
} }
if (list.size() == 0) { if (list.isEmpty()) {
throw DbException.get( throw DbException.get(
ErrorCode.PUBLIC_STATIC_JAVA_METHOD_NOT_FOUND_1, ErrorCode.PUBLIC_STATIC_JAVA_METHOD_NOT_FOUND_1,
methodName + " (" + className + ")"); methodName + " (" + className + ")");
......
...@@ -251,7 +251,7 @@ public class Session extends SessionWithState { ...@@ -251,7 +251,7 @@ public class Session extends SessionWithState {
} }
} }
public String getParsingCreateViewName() { public String getParsingCreateViewName() {
if (viewNameStack.size() == 0) { if (viewNameStack.isEmpty()) {
return null; return null;
} }
return viewNameStack.peek(); return viewNameStack.peek();
...@@ -652,7 +652,7 @@ public class Session extends SessionWithState { ...@@ -652,7 +652,7 @@ public class Session extends SessionWithState {
// increment the data mod count, so that other sessions // increment the data mod count, so that other sessions
// see the changes // see the changes
// TODO should not rely on locking // TODO should not rely on locking
if (locks.size() > 0) { if (!locks.isEmpty()) {
for (int i = 0, size = locks.size(); i < size; i++) { for (int i = 0, size = locks.size(); i < size; i++) {
Table t = locks.get(i); Table t = locks.get(i);
if (t instanceof MVTable) { if (t instanceof MVTable) {
...@@ -726,10 +726,10 @@ public class Session extends SessionWithState { ...@@ -726,10 +726,10 @@ public class Session extends SessionWithState {
} }
temporaryLobs.clear(); temporaryLobs.clear();
} }
if (temporaryResultLobs != null && temporaryResultLobs.size() > 0) { if (temporaryResultLobs != null && !temporaryResultLobs.isEmpty()) {
long keepYoungerThan = System.nanoTime() - long keepYoungerThan = System.nanoTime() -
TimeUnit.MILLISECONDS.toNanos(database.getSettings().lobTimeout); TimeUnit.MILLISECONDS.toNanos(database.getSettings().lobTimeout);
while (temporaryResultLobs.size() > 0) { while (!temporaryResultLobs.isEmpty()) {
TimeoutValue tv = temporaryResultLobs.getFirst(); TimeoutValue tv = temporaryResultLobs.getFirst();
if (onTimeout && tv.created >= keepYoungerThan) { if (onTimeout && tv.created >= keepYoungerThan) {
break; break;
...@@ -743,7 +743,7 @@ public class Session extends SessionWithState { ...@@ -743,7 +743,7 @@ public class Session extends SessionWithState {
} }
private void checkCommitRollback() { private void checkCommitRollback() {
if (commitOrRollbackDisabled && locks.size() > 0) { if (commitOrRollbackDisabled && !locks.isEmpty()) {
throw DbException.get(ErrorCode.COMMIT_ROLLBACK_NOT_ALLOWED); throw DbException.get(ErrorCode.COMMIT_ROLLBACK_NOT_ALLOWED);
} }
} }
...@@ -783,7 +783,7 @@ public class Session extends SessionWithState { ...@@ -783,7 +783,7 @@ public class Session extends SessionWithState {
transaction.commit(); transaction.commit();
transaction = null; transaction = null;
} }
if (locks.size() > 0 || needCommit) { if (!locks.isEmpty() || needCommit) {
database.commit(this); database.commit(this);
} }
cleanTempTables(false); cleanTempTables(false);
...@@ -990,7 +990,7 @@ public class Session extends SessionWithState { ...@@ -990,7 +990,7 @@ public class Session extends SessionWithState {
DbException.throwInternalError(); DbException.throwInternalError();
} }
} }
if (locks.size() > 0) { if (!locks.isEmpty()) {
// don't use the enhanced for loop to save memory // don't use the enhanced for loop to save memory
for (int i = 0, size = locks.size(); i < size; i++) { for (int i = 0, size = locks.size(); i < size; i++) {
Table t = locks.get(i); Table t = locks.get(i);
......
...@@ -482,7 +482,7 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -482,7 +482,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public void removeServer(IOException e, int i, int count) { public void removeServer(IOException e, int i, int count) {
trace.debug(e, "removing server because of exception"); trace.debug(e, "removing server because of exception");
transferList.remove(i); transferList.remove(i);
if (transferList.size() == 0 && autoReconnect(count)) { if (transferList.isEmpty() && autoReconnect(count)) {
return; return;
} }
checkClosed(); checkClosed();
...@@ -653,7 +653,7 @@ public class SessionRemote extends SessionWithState implements DataHandler { ...@@ -653,7 +653,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
@Override @Override
public boolean isClosed() { public boolean isClosed() {
return transferList == null || transferList.size() == 0; return transferList == null || transferList.isEmpty();
} }
/** /**
......
...@@ -24,7 +24,7 @@ abstract class SessionWithState implements SessionInterface { ...@@ -24,7 +24,7 @@ abstract class SessionWithState implements SessionInterface {
* Re-create the session state using the stored sessionState list. * Re-create the session state using the stored sessionState list.
*/ */
protected void recreateSessionState() { protected void recreateSessionState() {
if (sessionState != null && sessionState.size() > 0) { if (sessionState != null && !sessionState.isEmpty()) {
sessionStateUpdating = true; sessionStateUpdating = true;
try { try {
for (String sql : sessionState) { for (String sql : sessionState) {
......
...@@ -328,7 +328,7 @@ public class Aggregate extends Expression { ...@@ -328,7 +328,7 @@ public class Aggregate extends Expression {
Value v = data.getValue(session.getDatabase(), dataType, distinct); Value v = data.getValue(session.getDatabase(), dataType, distinct);
if (type == AggregateType.GROUP_CONCAT) { if (type == AggregateType.GROUP_CONCAT) {
ArrayList<Value> list = ((AggregateDataGroupConcat) data).getList(); ArrayList<Value> list = ((AggregateDataGroupConcat) data).getList();
if (list == null || list.size() == 0) { if (list == null || list.isEmpty()) {
return ValueNull.INSTANCE; return ValueNull.INSTANCE;
} }
if (groupConcatOrderList != null) { if (groupConcatOrderList != null) {
......
...@@ -624,7 +624,7 @@ public class FullText { ...@@ -624,7 +624,7 @@ public class FullText {
} }
} }
} }
if (rIds == null || rIds.size() == 0) { if (rIds == null || rIds.isEmpty()) {
return result; return result;
} }
PreparedStatement prepSelectRowById = setting.prepare(conn, SELECT_ROW_BY_ID); PreparedStatement prepSelectRowById = setting.prepare(conn, SELECT_ROW_BY_ID);
...@@ -913,7 +913,7 @@ public class FullText { ...@@ -913,7 +913,7 @@ public class FullText {
for (int i = 0; rs.next(); i++) { for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE"); columnTypes[i] = rs.getInt("DATA_TYPE");
} }
if (keyList.size() == 0) { if (keyList.isEmpty()) {
rs = meta.getPrimaryKeys(null, rs = meta.getPrimaryKeys(null,
StringUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName); tableName);
...@@ -921,7 +921,7 @@ public class FullText { ...@@ -921,7 +921,7 @@ public class FullText {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
} }
} }
if (keyList.size() == 0) { if (keyList.isEmpty()) {
throw throwException("No primary key for table " + tableName); throw throwException("No primary key for table " + tableName);
} }
ArrayList<String> indexList = New.arrayList(); ArrayList<String> indexList = New.arrayList();
...@@ -938,7 +938,7 @@ public class FullText { ...@@ -938,7 +938,7 @@ public class FullText {
Collections.addAll(indexList, StringUtils.arraySplit(columns, ',', true)); Collections.addAll(indexList, StringUtils.arraySplit(columns, ',', true));
} }
} }
if (indexList.size() == 0) { if (indexList.isEmpty()) {
indexList.addAll(columnList); indexList.addAll(columnList);
} }
index.keys = new int[keyList.size()]; index.keys = new int[keyList.size()];
......
...@@ -505,7 +505,7 @@ public class FullTextLucene extends FullText { ...@@ -505,7 +505,7 @@ public class FullTextLucene extends FullText {
for (int i = 0; rs.next(); i++) { for (int i = 0; rs.next(); i++) {
columnTypes[i] = rs.getInt("DATA_TYPE"); columnTypes[i] = rs.getInt("DATA_TYPE");
} }
if (keyList.size() == 0) { if (keyList.isEmpty()) {
rs = meta.getPrimaryKeys(null, rs = meta.getPrimaryKeys(null,
StringUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(schemaName),
tableName); tableName);
...@@ -513,7 +513,7 @@ public class FullTextLucene extends FullText { ...@@ -513,7 +513,7 @@ public class FullTextLucene extends FullText {
keyList.add(rs.getString("COLUMN_NAME")); keyList.add(rs.getString("COLUMN_NAME"));
} }
} }
if (keyList.size() == 0) { if (keyList.isEmpty()) {
throw throwException("No primary key for table " + tableName); throw throwException("No primary key for table " + tableName);
} }
ArrayList<String> indexList = New.arrayList(); ArrayList<String> indexList = New.arrayList();
...@@ -530,7 +530,7 @@ public class FullTextLucene extends FullText { ...@@ -530,7 +530,7 @@ public class FullTextLucene extends FullText {
StringUtils.arraySplit(cols, ',', true)); StringUtils.arraySplit(cols, ',', true));
} }
} }
if (indexList.size() == 0) { if (indexList.isEmpty()) {
indexList.addAll(columnList); indexList.addAll(columnList);
} }
keys = new int[keyList.size()]; keys = new int[keyList.size()];
......
...@@ -202,7 +202,7 @@ public class JdbcXAConnection extends TraceObject implements XAConnection, ...@@ -202,7 +202,7 @@ public class JdbcXAConnection extends TraceObject implements XAConnection,
} }
rs.close(); rs.close();
Xid[] result = list.toArray(new Xid[0]); Xid[] result = list.toArray(new Xid[0]);
if (list.size() > 0) { if (!list.isEmpty()) {
prepared = true; prepared = true;
} }
return result; return result;
......
...@@ -241,7 +241,7 @@ public class Trace { ...@@ -241,7 +241,7 @@ public class Trace {
*/ */
public static String formatParams( public static String formatParams(
ArrayList<? extends ParameterInterface> parameters) { ArrayList<? extends ParameterInterface> parameters) {
if (parameters.size() == 0) { if (parameters.isEmpty()) {
return ""; return "";
} }
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
......
...@@ -1479,7 +1479,7 @@ public final class MVStore { ...@@ -1479,7 +1479,7 @@ public final class MVStore {
for (Chunk c : modified) { for (Chunk c : modified) {
meta.put(Chunk.getMetaKey(c.id), c.asString()); meta.put(Chunk.getMetaKey(c.id), c.asString());
} }
if (modified.size() == 0) { if (modified.isEmpty()) {
break; break;
} }
} }
...@@ -1782,7 +1782,7 @@ public final class MVStore { ...@@ -1782,7 +1782,7 @@ public final class MVStore {
synchronized (this) { synchronized (this) {
old = compactGetOldChunks(targetFillRate, write); old = compactGetOldChunks(targetFillRate, write);
} }
if (old == null || old.size() == 0) { if (old == null || old.isEmpty()) {
return false; return false;
} }
compactRewrite(old); compactRewrite(old);
...@@ -1838,7 +1838,7 @@ public final class MVStore { ...@@ -1838,7 +1838,7 @@ public final class MVStore {
c.collectPriority = (int) (c.getFillRate() * 1000 / age); c.collectPriority = (int) (c.getFillRate() * 1000 / age);
old.add(c); old.add(c);
} }
if (old.size() == 0) { if (old.isEmpty()) {
return null; return null;
} }
...@@ -2287,7 +2287,7 @@ public final class MVStore { ...@@ -2287,7 +2287,7 @@ public final class MVStore {
keep = c; keep = c;
} }
} }
if (remove.size() > 0) { if (!remove.isEmpty()) {
// remove the youngest first, so we don't create gaps // remove the youngest first, so we don't create gaps
// (in case we remove many chunks) // (in case we remove many chunks)
Collections.sort(remove, Collections.reverseOrder()); Collections.sort(remove, Collections.reverseOrder());
......
...@@ -610,7 +610,7 @@ public class MVTable extends TableBase { ...@@ -610,7 +610,7 @@ public class MVTable extends TableBase {
remaining--; remaining--;
} }
sortRows(buffer, index); sortRows(buffer, index);
if (bufferNames.size() > 0) { if (!bufferNames.isEmpty()) {
String mapName = store.nextTemporaryMapName(); String mapName = store.nextTemporaryMapName();
index.addRowsToBuffer(buffer, mapName); index.addRowsToBuffer(buffer, mapName);
bufferNames.add(mapName); bufferNames.add(mapName);
......
...@@ -305,7 +305,7 @@ public class SpatialDataType implements DataType { ...@@ -305,7 +305,7 @@ public class SpatialDataType implements DataType {
*/ */
public int[] getExtremes(ArrayList<Object> list) { public int[] getExtremes(ArrayList<Object> list) {
list = getNotNull(list); list = getNotNull(list);
if (list.size() == 0) { if (list.isEmpty()) {
return null; return null;
} }
SpatialKey bounds = (SpatialKey) createBoundingBox(list.get(0)); SpatialKey bounds = (SpatialKey) createBoundingBox(list.get(0));
......
...@@ -118,7 +118,7 @@ public class UpdatableRow { ...@@ -118,7 +118,7 @@ public class UpdatableRow {
} }
private boolean isIndexUsable(ArrayList<String> indexColumns) { private boolean isIndexUsable(ArrayList<String> indexColumns) {
if (indexColumns.size() == 0) { if (indexColumns.isEmpty()) {
return false; return false;
} }
for (String c : indexColumns) { for (String c : indexColumns) {
......
...@@ -182,7 +182,7 @@ public class CipherFactory { ...@@ -182,7 +182,7 @@ public class CipherFactory {
boolean ecdhAnonRemoved = algorithms.remove("ECDH_anon"); boolean ecdhAnonRemoved = algorithms.remove("ECDH_anon");
if (dhAnonRemoved || ecdhAnonRemoved) { if (dhAnonRemoved || ecdhAnonRemoved) {
String string = Arrays.toString(algorithms.toArray(new String[algorithms.size()])); String string = Arrays.toString(algorithms.toArray(new String[algorithms.size()]));
return (algorithms.size() > 0) ? string.substring(1, string.length() - 1): ""; return (!algorithms.isEmpty()) ? string.substring(1, string.length() - 1): "";
} }
return list; return list;
} }
......
...@@ -886,7 +886,7 @@ public class PgServerThread implements Runnable { ...@@ -886,7 +886,7 @@ public class PgServerThread implements Runnable {
} }
stat.execute("set search_path = PUBLIC, pg_catalog"); stat.execute("set search_path = PUBLIC, pg_catalog");
HashSet<Integer> typeSet = server.getTypeSet(); HashSet<Integer> typeSet = server.getTypeSet();
if (typeSet.size() == 0) { if (typeSet.isEmpty()) {
try (ResultSet rs = stat.executeQuery("select oid from pg_catalog.pg_type")) { try (ResultSet rs = stat.executeQuery("select oid from pg_catalog.pg_type")) {
while (rs.next()) { while (rs.next()) {
typeSet.add(rs.getInt(1)); typeSet.add(rs.getInt(1));
......
...@@ -98,7 +98,7 @@ public class PageParser { ...@@ -98,7 +98,7 @@ public class PageParser {
result.append("?items?"); result.append("?items?");
list = New.arrayList(); list = New.arrayList();
} }
if (list.size() == 0) { if (list.isEmpty()) {
parseBlockUntil("</c:forEach>"); parseBlockUntil("</c:forEach>");
} }
for (Object o : list) { for (Object o : list) {
......
...@@ -1869,7 +1869,7 @@ public class WebApp { ...@@ -1869,7 +1869,7 @@ public class WebApp {
String setting = attributes.getProperty("name", ""); String setting = attributes.getProperty("name", "");
server.removeSetting(setting); server.removeSetting(setting);
ArrayList<ConnectionInfo> settings = server.getSettings(); ArrayList<ConnectionInfo> settings = server.getSettings();
if (settings.size() > 0) { if (!settings.isEmpty()) {
attributes.put("setting", settings.get(0)); attributes.put("setting", settings.get(0));
} }
server.saveProperties(null); server.saveProperties(null);
......
...@@ -206,7 +206,7 @@ class WebSession { ...@@ -206,7 +206,7 @@ class WebSession {
"${text.admin.notConnected}" : conn.getMetaData().getURL()); "${text.admin.notConnected}" : conn.getMetaData().getURL());
m.put("user", conn == null ? m.put("user", conn == null ?
"-" : conn.getMetaData().getUserName()); "-" : conn.getMetaData().getUserName());
m.put("lastQuery", commandHistory.size() == 0 ? m.put("lastQuery", commandHistory.isEmpty() ?
"" : commandHistory.get(0)); "" : commandHistory.get(0));
m.put("executing", executingStatement == null ? m.put("executing", executingStatement == null ?
"${text.admin.no}" : "${text.admin.yes}"); "${text.admin.no}" : "${text.admin.yes}");
......
...@@ -1407,7 +1407,7 @@ public class PageStore implements CacheWriter { ...@@ -1407,7 +1407,7 @@ public class PageStore implements CacheWriter {
isEmpty &= log.recover(PageLog.RECOVERY_STAGE_REDO); isEmpty &= log.recover(PageLog.RECOVERY_STAGE_REDO);
boolean setReadOnly = false; boolean setReadOnly = false;
if (!database.isReadOnly()) { if (!database.isReadOnly()) {
if (log.getInDoubtTransactions().size() == 0) { if (log.getInDoubtTransactions().isEmpty()) {
log.recoverEnd(); log.recoverEnd();
int firstUncommittedSection = getFirstUncommittedSection(); int firstUncommittedSection = getFirstUncommittedSection();
log.removeUntil(firstUncommittedSection); log.removeUntil(firstUncommittedSection);
......
...@@ -671,7 +671,7 @@ public class RegularTable extends TableBase { ...@@ -671,7 +671,7 @@ public class RegularTable extends TableBase {
lockExclusiveSession = null; lockExclusiveSession = null;
} }
synchronized (database) { synchronized (database) {
if (lockSharedSessions.size() > 0) { if (!lockSharedSessions.isEmpty()) {
lockSharedSessions.remove(s); lockSharedSessions.remove(s);
} }
if (!waitingSessions.isEmpty()) { if (!waitingSessions.isEmpty()) {
......
...@@ -529,20 +529,20 @@ public abstract class Table extends SchemaObjectBase { ...@@ -529,20 +529,20 @@ public abstract class Table extends SchemaObjectBase {
@Override @Override
public void removeChildrenAndResources(Session session) { public void removeChildrenAndResources(Session session) {
while (dependentViews.size() > 0) { while (!dependentViews.isEmpty()) {
TableView view = dependentViews.get(0); TableView view = dependentViews.get(0);
dependentViews.remove(0); dependentViews.remove(0);
database.removeSchemaObject(session, view); database.removeSchemaObject(session, view);
} }
while (synonyms != null && synonyms.size() > 0) { while (synonyms != null && !synonyms.isEmpty()) {
TableSynonym synonym = synonyms.remove(0); TableSynonym synonym = synonyms.remove(0);
database.removeSchemaObject(session, synonym); database.removeSchemaObject(session, synonym);
} }
while (triggers != null && triggers.size() > 0) { while (triggers != null && !triggers.isEmpty()) {
TriggerObject trigger = triggers.remove(0); TriggerObject trigger = triggers.remove(0);
database.removeSchemaObject(session, trigger); database.removeSchemaObject(session, trigger);
} }
while (constraints != null && constraints.size() > 0) { while (constraints != null && !constraints.isEmpty()) {
Constraint constraint = constraints.remove(0); Constraint constraint = constraints.remove(0);
database.removeSchemaObject(session, constraint); database.removeSchemaObject(session, constraint);
} }
...@@ -554,7 +554,7 @@ public abstract class Table extends SchemaObjectBase { ...@@ -554,7 +554,7 @@ public abstract class Table extends SchemaObjectBase {
database.removeMeta(session, getId()); database.removeMeta(session, getId());
// must delete sequences later (in case there is a power failure // must delete sequences later (in case there is a power failure
// before removing the table object) // before removing the table object)
while (sequences != null && sequences.size() > 0) { while (sequences != null && !sequences.isEmpty()) {
Sequence sequence = sequences.remove(0); Sequence sequence = sequences.remove(0);
// only remove if no other table depends on this sequence // only remove if no other table depends on this sequence
// this is possible when calling ALTER TABLE ALTER COLUMN // this is possible when calling ALTER TABLE ALTER COLUMN
...@@ -975,8 +975,8 @@ public abstract class Table extends SchemaObjectBase { ...@@ -975,8 +975,8 @@ public abstract class Table extends SchemaObjectBase {
* @return if there are any triggers or rows defined * @return if there are any triggers or rows defined
*/ */
public boolean fireRow() { public boolean fireRow() {
return (constraints != null && constraints.size() > 0) || return (constraints != null && !constraints.isEmpty()) ||
(triggers != null && triggers.size() > 0); (triggers != null && !triggers.isEmpty());
} }
/** /**
......
...@@ -197,7 +197,7 @@ public class TableFilter implements ColumnResolver { ...@@ -197,7 +197,7 @@ public class TableFilter implements ColumnResolver {
if (select != null) { if (select != null) {
sortOrder = select.getSortOrder(); sortOrder = select.getSortOrder();
} }
if (indexConditions.size() == 0) { if (indexConditions.isEmpty()) {
item1 = new PlanItem(); item1 = new PlanItem();
item1.setIndex(table.getScanIndex(s, null, filters, filter, item1.setIndex(table.getScanIndex(s, null, filters, filter,
sortOrder, allColumnsSet)); sortOrder, allColumnsSet));
...@@ -854,7 +854,7 @@ public class TableFilter implements ColumnResolver { ...@@ -854,7 +854,7 @@ public class TableFilter implements ColumnResolver {
} }
} }
planBuff.append(index.getPlanSQL()); planBuff.append(index.getPlanSQL());
if (indexConditions.size() > 0) { if (!indexConditions.isEmpty()) {
planBuff.append(": "); planBuff.append(": ");
for (IndexCondition condition : indexConditions) { for (IndexCondition condition : indexConditions) {
planBuff.appendExceptFirst("\n AND "); planBuff.appendExceptFirst("\n AND ");
......
...@@ -173,7 +173,7 @@ public class TableLink extends Table { ...@@ -173,7 +173,7 @@ public class TableLink extends Table {
try (Statement stat = conn.getConnection().createStatement()) { try (Statement stat = conn.getConnection().createStatement()) {
rs = stat.executeQuery("SELECT * FROM " + rs = stat.executeQuery("SELECT * FROM " +
qualifiedTableName + " T WHERE 1=0"); qualifiedTableName + " T WHERE 1=0");
if (columnList.size() == 0) { if (columnList.isEmpty()) {
// alternative solution // alternative solution
ResultSetMetaData rsMeta = rs.getMetaData(); ResultSetMetaData rsMeta = rs.getMetaData();
for (i = 0; i < rsMeta.getColumnCount();) { for (i = 0; i < rsMeta.getColumnCount();) {
...@@ -501,7 +501,7 @@ public class TableLink extends Table { ...@@ -501,7 +501,7 @@ public class TableLink extends Table {
if (trace.isDebugEnabled()) { if (trace.isDebugEnabled()) {
StatementBuilder buff = new StatementBuilder(); StatementBuilder buff = new StatementBuilder();
buff.append(getName()).append(":\n").append(sql); buff.append(getName()).append(":\n").append(sql);
if (params != null && params.size() > 0) { if (params != null && !params.isEmpty()) {
buff.append(" {"); buff.append(" {");
int i = 1; int i = 1;
for (Value v : params) { for (Value v : params) {
......
...@@ -114,7 +114,7 @@ public class Backup extends Tool { ...@@ -114,7 +114,7 @@ public class Backup extends Tool {
} else { } else {
list = FileLister.getDatabaseFiles(directory, db, true); list = FileLister.getDatabaseFiles(directory, db, true);
} }
if (list.size() == 0) { if (list.isEmpty()) {
if (!quiet) { if (!quiet) {
printNoDatabaseFilesFound(directory, db); printNoDatabaseFilesFound(directory, db);
} }
......
...@@ -170,7 +170,7 @@ public class ChangeFileEncryption extends Tool { ...@@ -170,7 +170,7 @@ public class ChangeFileEncryption extends Tool {
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true); ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
FileLister.tryUnlockDatabase(files, "encryption"); FileLister.tryUnlockDatabase(files, "encryption");
files = FileLister.getDatabaseFiles(dir, db, false); files = FileLister.getDatabaseFiles(dir, db, false);
if (files.size() == 0 && !quiet) { if (files.isEmpty() && !quiet) {
printNoDatabaseFilesFound(dir, db); printNoDatabaseFilesFound(dir, db);
} }
// first, test only if the file can be renamed // first, test only if the file can be renamed
......
...@@ -343,7 +343,7 @@ public class Csv implements SimpleRowSource { ...@@ -343,7 +343,7 @@ public class Csv implements SimpleRowSource {
String v = readValue(); String v = readValue();
if (v == null) { if (v == null) {
if (endOfLine) { if (endOfLine) {
if (endOfFile || list.size() > 0) { if (endOfFile || !list.isEmpty()) {
break; break;
} }
} else { } else {
......
...@@ -84,7 +84,7 @@ public class DeleteDbFiles extends Tool { ...@@ -84,7 +84,7 @@ public class DeleteDbFiles extends Tool {
*/ */
private void process(String dir, String db, boolean quiet) { private void process(String dir, String db, boolean quiet) {
ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true); ArrayList<String> files = FileLister.getDatabaseFiles(dir, db, true);
if (files.size() == 0 && !quiet) { if (files.isEmpty() && !quiet) {
printNoDatabaseFilesFound(dir, db); printNoDatabaseFilesFound(dir, db);
} }
for (String fileName : files) { for (String fileName : files) {
......
...@@ -330,7 +330,7 @@ public class Recover extends Tool implements DataHandler { ...@@ -330,7 +330,7 @@ public class Recover extends Tool implements DataHandler {
private void process(String dir, String db) { private void process(String dir, String db) {
ArrayList<String> list = FileLister.getDatabaseFiles(dir, db, true); ArrayList<String> list = FileLister.getDatabaseFiles(dir, db, true);
if (list.size() == 0) { if (list.isEmpty()) {
printNoDatabaseFilesFound(dir, db); printNoDatabaseFilesFound(dir, db);
} }
for (String fileName : list) { for (String fileName : list) {
......
...@@ -243,7 +243,7 @@ public class Shell extends Tool implements Runnable { ...@@ -243,7 +243,7 @@ public class Shell extends Tool implements Runnable {
s = s.replace('\n', ' ').replace('\r', ' '); s = s.replace('\n', ' ').replace('\r', ' ');
println("#" + (1 + i) + ": " + s); println("#" + (1 + i) + ": " + s);
} }
if (history.size() > 0) { if (!history.isEmpty()) {
println("To re-run a statement, type the number and press and enter"); println("To re-run a statement, type the number and press and enter");
} else { } else {
println("No history"); println("No history");
......
...@@ -116,7 +116,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData, ...@@ -116,7 +116,7 @@ public class SimpleResultSet implements ResultSet, ResultSetMetaData,
*/ */
public void addColumn(String name, int sqlType, String sqlTypeName, public void addColumn(String name, int sqlType, String sqlTypeName,
int precision, int scale) { int precision, int scale) {
if (rows != null && rows.size() > 0) { if (rows != null && !rows.isEmpty()) {
throw new IllegalStateException( throw new IllegalStateException(
"Cannot add a column after adding rows"); "Cannot add a column after adding rows");
} }
......
...@@ -71,7 +71,7 @@ public class AbbaDetector { ...@@ -71,7 +71,7 @@ public class AbbaDetector {
System.out.println(thread + " " + indent + System.out.println(thread + " " + indent +
"sync " + getObjectName(o)); "sync " + getObjectName(o));
} }
if (stack.size() > 0) { if (!stack.isEmpty()) {
markHigher(o, stack); markHigher(o, stack);
} }
stack.push(o); stack.push(o);
......
...@@ -163,7 +163,7 @@ public class CacheLRU implements Cache { ...@@ -163,7 +163,7 @@ public class CacheLRU implements Cache {
if (rc <= Constants.CACHE_MIN_RECORDS) { if (rc <= Constants.CACHE_MIN_RECORDS) {
break; break;
} }
if (changed.size() == 0) { if (changed.isEmpty()) {
if (mem <= maxMemory) { if (mem <= maxMemory) {
break; break;
} }
...@@ -209,7 +209,7 @@ public class CacheLRU implements Cache { ...@@ -209,7 +209,7 @@ public class CacheLRU implements Cache {
remove(check.getPos()); remove(check.getPos());
} }
} }
if (changed.size() > 0) { if (!changed.isEmpty()) {
if (!flushed) { if (!flushed) {
writer.flushLog(); writer.flushLog();
} }
......
...@@ -253,7 +253,7 @@ public class Profiler implements Runnable { ...@@ -253,7 +253,7 @@ public class Profiler implements Runnable {
line = line.substring(3).trim(); line = line.substring(3).trim();
stack.add(line); stack.add(line);
} }
if (stack.size() > 0) { if (!stack.isEmpty()) {
String[] s = stack.toArray(new String[0]); String[] s = stack.toArray(new String[0]);
list.add(s); list.add(s);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论