mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fixed sonar rule violations
This commit is contained in:
@@ -50,7 +50,9 @@ public class SQLSelect extends SQLObjectImpl {
|
||||
this.query.output(buf);
|
||||
buf.append(" ");
|
||||
|
||||
if (this.orderBy != null) this.orderBy.output(buf);
|
||||
if (this.orderBy != null) {
|
||||
this.orderBy.output(buf);
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -228,7 +228,9 @@ public class MySqlSelectParser extends SQLSelectParser {
|
||||
SQLSelectGroupByClause groupBy = new SQLSelectGroupByClause();
|
||||
while (true) {
|
||||
groupBy.getItems().add(this.exprParser.expr());
|
||||
if (!(lexer.token() == (Token.COMMA))) break;
|
||||
if (!(lexer.token() == (Token.COMMA))) {
|
||||
break;
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,9 @@ public class OracleSelect extends SQLSelect {
|
||||
this.query.output(buf);
|
||||
buf.append(" ");
|
||||
|
||||
if (this.orderBy != null) this.orderBy.output(buf);
|
||||
if (this.orderBy != null) {
|
||||
this.orderBy.output(buf);
|
||||
}
|
||||
}
|
||||
|
||||
protected void accept0(SQLASTVisitor visitor) {
|
||||
|
||||
@@ -619,10 +619,18 @@ public class OracleExprParser extends SQLExprParser {
|
||||
String currentTokenUpperValue = lexer.stringVal();
|
||||
lexer.nextToken();
|
||||
|
||||
if (currentTokenUpperValue.equals("YEAR")) return OracleIntervalType.YEAR;
|
||||
if (currentTokenUpperValue.equals("MONTH")) return OracleIntervalType.MONTH;
|
||||
if (currentTokenUpperValue.equals("HOUR")) return OracleIntervalType.HOUR;
|
||||
if (currentTokenUpperValue.equals("MINUTE")) return OracleIntervalType.MINUTE;
|
||||
if (currentTokenUpperValue.equals("YEAR")) {
|
||||
return OracleIntervalType.YEAR;
|
||||
}
|
||||
if (currentTokenUpperValue.equals("MONTH")) {
|
||||
return OracleIntervalType.MONTH;
|
||||
}
|
||||
if (currentTokenUpperValue.equals("HOUR")) {
|
||||
return OracleIntervalType.HOUR;
|
||||
}
|
||||
if (currentTokenUpperValue.equals("MINUTE")) {
|
||||
return OracleIntervalType.MINUTE;
|
||||
}
|
||||
if (currentTokenUpperValue.equals("SECOND")) {
|
||||
return OracleIntervalType.SECOND;
|
||||
}
|
||||
|
||||
@@ -965,7 +965,9 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
item.setAlias(as());
|
||||
pivot.getItems().add(item);
|
||||
|
||||
if (!(lexer.token() == (Token.COMMA))) break;
|
||||
if (!(lexer.token() == (Token.COMMA))) {
|
||||
break;
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
@@ -977,7 +979,9 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
pivot.getPivotFor().add(new SQLIdentifierExpr(lexer.stringVal()));
|
||||
lexer.nextToken();
|
||||
|
||||
if (!(lexer.token() == (Token.COMMA))) break;
|
||||
if (!(lexer.token() == (Token.COMMA))) {
|
||||
break;
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
@@ -1047,7 +1051,9 @@ public class OracleSelectParser extends SQLSelectParser {
|
||||
unPivot.getPivotFor().add(new SQLIdentifierExpr(lexer.stringVal()));
|
||||
lexer.nextToken();
|
||||
|
||||
if (!(lexer.token() == (Token.COMMA))) break;
|
||||
if (!(lexer.token() == (Token.COMMA))) {
|
||||
break;
|
||||
}
|
||||
lexer.nextToken();
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,9 @@ public class OracleUpdateParser extends SQLStatementParser {
|
||||
}
|
||||
|
||||
private void parseErrorLoging(OracleUpdateStatement update) throws ParserException {
|
||||
if (identifierEquals("LOG")) throw new ParserException("TODO");
|
||||
if (identifierEquals("LOG")) {
|
||||
throw new ParserException("TODO");
|
||||
}
|
||||
}
|
||||
|
||||
private void parseReturn(OracleUpdateStatement update) throws ParserException {
|
||||
|
||||
@@ -195,7 +195,9 @@ public class DruidStatService implements DruidStatServiceMBean {
|
||||
|
||||
private List<Map<String, Object>> comparatorOrderBy(List<Map<String, Object>> array, Map<String, String> parameters) {
|
||||
// when open the stat page before executing some sql
|
||||
if (array == null || array.isEmpty()) return null;
|
||||
if (array == null || array.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// when parameters is null
|
||||
String orderBy, orderType = null;
|
||||
@@ -223,7 +225,9 @@ public class DruidStatService implements DruidStatServiceMBean {
|
||||
orderBy = orderBy == null ? DEFAULT_ORDERBY : orderBy;
|
||||
orderType = orderType == null ? DEFAULT_ORDER_TYPE : orderType;
|
||||
|
||||
if (!"desc".equals(orderType)) orderType = DEFAULT_ORDER_TYPE;
|
||||
if (!"desc".equals(orderType)) {
|
||||
orderType = DEFAULT_ORDER_TYPE;
|
||||
}
|
||||
|
||||
// orderby the statData array
|
||||
if (orderBy != null && orderBy.trim().length() != 0) {
|
||||
@@ -233,7 +237,9 @@ public class DruidStatService implements DruidStatServiceMBean {
|
||||
// page
|
||||
int fromIndex = (page - 1) * perPageCount;
|
||||
int toIndex = page * perPageCount;
|
||||
if (toIndex > array.size()) toIndex = array.size();
|
||||
if (toIndex > array.size()) {
|
||||
toIndex = array.size();
|
||||
}
|
||||
|
||||
return array.subList(fromIndex, toIndex);
|
||||
}
|
||||
@@ -338,7 +344,9 @@ public class DruidStatService implements DruidStatServiceMBean {
|
||||
|
||||
for (String parameterStr : parametersArray) {
|
||||
int index = parameterStr.indexOf("=");
|
||||
if (index <= 0) continue;
|
||||
if (index <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String name = parameterStr.substring(0, index);
|
||||
String value = parameterStr.substring(index + 1);
|
||||
|
||||
@@ -32,7 +32,9 @@ public class Option {
|
||||
}
|
||||
|
||||
public static boolean isPrintHelp(String[] args) {
|
||||
if (args == null ) return true;
|
||||
if (args == null ) {
|
||||
return true;
|
||||
}
|
||||
for (String arg: args) {
|
||||
if (arg.equals("-help") ) {
|
||||
return true;
|
||||
|
||||
@@ -79,9 +79,19 @@ public class Resources extends Object {
|
||||
*/
|
||||
public static URL getResourceURL(ClassLoader loader, String resource) throws IOException {
|
||||
URL url = null;
|
||||
if (loader != null) url = loader.getResource(resource);
|
||||
if (url == null) url = ClassLoader.getSystemResource(resource);
|
||||
if (url == null) throw new IOException("Could not find resource " + resource);
|
||||
|
||||
if (loader != null) {
|
||||
url = loader.getResource(resource);
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
url = ClassLoader.getSystemResource(resource);
|
||||
}
|
||||
|
||||
if (url == null) {
|
||||
throw new IOException("Could not find resource " + resource);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@@ -106,9 +116,15 @@ public class Resources extends Object {
|
||||
*/
|
||||
public static InputStream getResourceAsStream(ClassLoader loader, String resource) throws IOException {
|
||||
InputStream in = null;
|
||||
if (loader != null) in = loader.getResourceAsStream(resource);
|
||||
if (in == null) in = ClassLoader.getSystemResourceAsStream(resource);
|
||||
if (in == null) throw new IOException("Could not find resource " + resource);
|
||||
if (loader != null) {
|
||||
in = loader.getResourceAsStream(resource);
|
||||
}
|
||||
if (in == null) {
|
||||
in = ClassLoader.getSystemResourceAsStream(resource);
|
||||
}
|
||||
if (in == null) {
|
||||
throw new IOException("Could not find resource " + resource);
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,9 @@ public class SpringMethodInfo {
|
||||
Class<?>[] params = method.getParameterTypes();
|
||||
for (int j = 0; j < params.length; j++) {
|
||||
sb.append(params[j].getName());
|
||||
if (j < (params.length - 1)) sb.append(",");
|
||||
if (j < (params.length - 1)) {
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
|
||||
|
||||
@@ -62,16 +62,19 @@ public final class HexBin {
|
||||
* @return return encoded string
|
||||
*/
|
||||
static public String encode(byte[] binaryData) {
|
||||
if (binaryData == null)
|
||||
if (binaryData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int lengthData = binaryData.length;
|
||||
int lengthEncode = lengthData * 2;
|
||||
char[] encodedData = new char[lengthEncode];
|
||||
int temp;
|
||||
for (int i = 0; i < lengthData; i++) {
|
||||
temp = binaryData[i];
|
||||
if (temp < 0)
|
||||
if (temp < 0) {
|
||||
temp += 256;
|
||||
}
|
||||
encodedData[i*2] = lookUpHexAlphabet[temp >> 4];
|
||||
encodedData[i*2+1] = lookUpHexAlphabet[temp & 0xf];
|
||||
}
|
||||
@@ -85,11 +88,14 @@ public final class HexBin {
|
||||
* @return return array of byte to encode
|
||||
*/
|
||||
static public byte[] decode(String encoded) {
|
||||
if (encoded == null)
|
||||
if (encoded == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int lengthData = encoded.length();
|
||||
if (lengthData % 2 != 0)
|
||||
if (lengthData % 2 != 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
char[] binaryData = encoded.toCharArray();
|
||||
int lengthDecode = lengthData / 2;
|
||||
@@ -99,12 +105,14 @@ public final class HexBin {
|
||||
for( int i = 0; i<lengthDecode; i++ ){
|
||||
tempChar = binaryData[i*2];
|
||||
temp1 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
|
||||
if (temp1 == -1)
|
||||
if (temp1 == -1) {
|
||||
return null;
|
||||
}
|
||||
tempChar = binaryData[i*2+1];
|
||||
temp2 = (tempChar < BASELENGTH) ? hexNumberTable[tempChar] : -1;
|
||||
if (temp2 == -1)
|
||||
if (temp2 == -1) {
|
||||
return null;
|
||||
}
|
||||
decodedData[i] = (byte)((temp1 << 4) | temp2);
|
||||
}
|
||||
return decodedData;
|
||||
|
||||
@@ -78,7 +78,9 @@ public abstract class LazyCompositeData implements CompositeData, Serializable {
|
||||
* Lazy creation of a CompositeData object only when the CompositeData interface is used.
|
||||
*/
|
||||
private synchronized CompositeData compositeData() {
|
||||
if (compositeData != null) return compositeData;
|
||||
if (compositeData != null) {
|
||||
return compositeData;
|
||||
}
|
||||
compositeData = getCompositeData();
|
||||
return compositeData;
|
||||
}
|
||||
@@ -100,25 +102,33 @@ public abstract class LazyCompositeData implements CompositeData, Serializable {
|
||||
|
||||
// Helper methods
|
||||
static String getString(CompositeData cd, String itemName) {
|
||||
if (cd == null) throw new IllegalArgumentException("Null CompositeData");
|
||||
if (cd == null) {
|
||||
throw new IllegalArgumentException("Null CompositeData");
|
||||
}
|
||||
|
||||
return (String) cd.get(itemName);
|
||||
}
|
||||
|
||||
static boolean getBoolean(CompositeData cd, String itemName) {
|
||||
if (cd == null) throw new IllegalArgumentException("Null CompositeData");
|
||||
if (cd == null) {
|
||||
throw new IllegalArgumentException("Null CompositeData");
|
||||
}
|
||||
|
||||
return ((Boolean) cd.get(itemName)).booleanValue();
|
||||
}
|
||||
|
||||
static long getLong(CompositeData cd, String itemName) {
|
||||
if (cd == null) throw new IllegalArgumentException("Null CompositeData");
|
||||
if (cd == null) {
|
||||
throw new IllegalArgumentException("Null CompositeData");
|
||||
}
|
||||
|
||||
return ((Number) cd.get(itemName)).longValue();
|
||||
}
|
||||
|
||||
static int getInt(CompositeData cd, String itemName) {
|
||||
if (cd == null) throw new IllegalArgumentException("Null CompositeData");
|
||||
if (cd == null) {
|
||||
throw new IllegalArgumentException("Null CompositeData");
|
||||
}
|
||||
|
||||
return ((Number) cd.get(itemName)).intValue();
|
||||
}
|
||||
@@ -128,7 +138,9 @@ public abstract class LazyCompositeData implements CompositeData, Serializable {
|
||||
* same.
|
||||
*/
|
||||
protected static boolean isTypeMatched(CompositeType type1, CompositeType type2) {
|
||||
if (type1 == type2) return true;
|
||||
if (type1 == type2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// We can't use CompositeType.isValue() since it returns false
|
||||
// if the type name doesn't match.
|
||||
@@ -142,11 +154,19 @@ public abstract class LazyCompositeData implements CompositeData, Serializable {
|
||||
OpenType<?> ot1 = type1.getType(item);
|
||||
OpenType<?> ot2 = type2.getType(item);
|
||||
if (ot1 instanceof CompositeType) {
|
||||
if (!(ot2 instanceof CompositeType)) return false;
|
||||
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2)) return false;
|
||||
if (!(ot2 instanceof CompositeType)) {
|
||||
return false;
|
||||
}
|
||||
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (ot1 instanceof TabularType) {
|
||||
if (!(ot2 instanceof TabularType)) return false;
|
||||
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2)) return false;
|
||||
if (!(ot2 instanceof TabularType)) {
|
||||
return false;
|
||||
}
|
||||
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2)) {
|
||||
return false;
|
||||
}
|
||||
} else if (!ot1.equals(ot2)) {
|
||||
return false;
|
||||
}
|
||||
@@ -155,7 +175,9 @@ public abstract class LazyCompositeData implements CompositeData, Serializable {
|
||||
}
|
||||
|
||||
protected static boolean isTypeMatched(TabularType type1, TabularType type2) {
|
||||
if (type1 == type2) return true;
|
||||
if (type1 == type2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
List<String> list1 = type1.getIndexNames();
|
||||
List<String> list2 = type2.getIndexNames();
|
||||
|
||||
@@ -78,15 +78,27 @@ public class MapComparator<K extends Object, V extends Object> implements Compar
|
||||
Object v1 = getValueByKey(o1, orderByKey);
|
||||
Object v2 = getValueByKey(o2, orderByKey);
|
||||
|
||||
if (v1 == null && v2 == null) return 0;
|
||||
if (v1 == null) return -1;
|
||||
if (v2 == null) return 1;
|
||||
if (v1 == null && v2 == null) {
|
||||
return 0;
|
||||
}
|
||||
if (v1 == null) {
|
||||
return -1;
|
||||
}
|
||||
if (v2 == null) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (v1 instanceof Number) return compare((Number) v1, (Number) v2);
|
||||
if (v1 instanceof Number) {
|
||||
return compare((Number) v1, (Number) v2);
|
||||
}
|
||||
|
||||
if (v1 instanceof String) return compare((String) v1, (String) v2);
|
||||
if (v1 instanceof String) {
|
||||
return compare((String) v1, (String) v2);
|
||||
}
|
||||
|
||||
if (v1 instanceof Date) return compare((Date) v1, (Date) v2);
|
||||
if (v1 instanceof Date) {
|
||||
return compare((Date) v1, (Date) v2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -61,9 +61,14 @@ public class StringUtils {
|
||||
* @return
|
||||
*/
|
||||
public static Integer stringToInteger(String in) {
|
||||
if (in == null) return null;
|
||||
if (in == null) {
|
||||
return null;
|
||||
}
|
||||
in = in.trim();
|
||||
if (in.length() == 0) return null;
|
||||
if (in.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Integer.parseInt(in);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
@@ -103,8 +103,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* @throws UnsupportedOperationException always
|
||||
*/
|
||||
public void setSeed(long seed) {
|
||||
if (initialized)
|
||||
if (initialized) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
rnd = (seed ^ multiplier) & mask;
|
||||
}
|
||||
|
||||
@@ -124,8 +125,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* @return the next value
|
||||
*/
|
||||
public int nextInt(int least, int bound) {
|
||||
if (least >= bound)
|
||||
if (least >= bound) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return nextInt(bound - least) + least;
|
||||
}
|
||||
|
||||
@@ -139,8 +141,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* @throws IllegalArgumentException if n is not positive
|
||||
*/
|
||||
public long nextLong(long n) {
|
||||
if (n <= 0)
|
||||
if (n <= 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
// Divide n by two until small enough for nextInt. On each
|
||||
// iteration (at most 31 of them but usually much less),
|
||||
// randomly choose both whether to include high bit in result
|
||||
@@ -169,8 +172,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* to bound
|
||||
*/
|
||||
public long nextLong(long least, long bound) {
|
||||
if (least >= bound)
|
||||
if (least >= bound) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return nextLong(bound - least) + least;
|
||||
}
|
||||
|
||||
@@ -184,8 +188,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* @throws IllegalArgumentException if n is not positive
|
||||
*/
|
||||
public double nextDouble(double n) {
|
||||
if (n <= 0)
|
||||
if (n <= 0) {
|
||||
throw new IllegalArgumentException("n must be positive");
|
||||
}
|
||||
return nextDouble() * n;
|
||||
}
|
||||
|
||||
@@ -200,8 +205,9 @@ public class ThreadLocalRandom extends Random {
|
||||
* to bound
|
||||
*/
|
||||
public double nextDouble(double least, double bound) {
|
||||
if (least >= bound)
|
||||
if (least >= bound) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return nextDouble() * (bound - least) + least;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user