Unverified Commit 3f5b8da1 authored by Licho's avatar Licho Committed by GitHub

refactor: some trick modification (#1135)

* refactor: some trick modification

* refactor: some trick modification

* fix: checkstyle
Signed-off-by: 's avatarlicho <lecho.sun@gmail.com>
Signed-off-by: 's avatarlicho <lecho.sun@gmail.com>
parent b64a565f
......@@ -32,6 +32,9 @@ import java.util.Map;
*/
public class Asserts {
private Asserts() {
}
public static boolean isNotNull(Object object) {
return object != null;
}
......@@ -88,25 +91,19 @@ public class Asserts {
}
}
public static boolean isNullCollection(Collection collection) {
if (isNull(collection) || collection.size() == 0) {
return true;
}
return false;
public static boolean isNullCollection(Collection<?> collection) {
return isNull(collection) || collection.isEmpty();
}
public static boolean isNotNullCollection(Collection collection) {
public static boolean isNotNullCollection(Collection<?> collection) {
return !isNullCollection(collection);
}
public static boolean isNullMap(Map map) {
if (isNull(map) || map.size() == 0) {
return true;
}
return false;
public static boolean isNullMap(Map<?, ?> map) {
return isNull(map) || map.size() == 0;
}
public static boolean isNotNullMap(Map map) {
public static boolean isNotNullMap(Map<?, ?> map) {
return !isNullMap(map);
}
......@@ -128,13 +125,13 @@ public class Asserts {
}
}
public static void checkNullCollection(Collection collection, String msg) {
public static void checkNullCollection(Collection<?> collection, String msg) {
if (isNullCollection(collection)) {
throw new RunTimeException(msg);
}
}
public static void checkNullMap(Map map, String msg) {
public static void checkNullMap(Map<?, ?> map, String msg) {
if (isNullMap(map)) {
throw new RunTimeException(msg);
}
......
......@@ -41,7 +41,7 @@ public class SqlUtil {
return new String[0];
}
String[] splits = sql.replaceAll(";\r\n", ";\n").split(sqlSeparator);
String[] splits = sql.replace(";\r\n", ";\n").split(sqlSeparator);
String lastStatement = splits[splits.length - 1].trim();
if (lastStatement.endsWith(SEMICOLON)) {
splits[splits.length - 1] = lastStatement.substring(0, lastStatement.length() - 1);
......
......@@ -63,10 +63,7 @@ public enum SqlType {
}
public boolean isInsert() {
if (type.equals("INSERT")) {
return true;
}
return false;
return type.equals("INSERT");
}
}
......@@ -26,6 +26,8 @@ import com.dlink.trans.ddl.SetOperation;
import com.dlink.trans.ddl.ShowFragmentOperation;
import com.dlink.trans.ddl.ShowFragmentsOperation;
import java.util.Arrays;
/**
* Operations
*
......@@ -34,8 +36,10 @@ import com.dlink.trans.ddl.ShowFragmentsOperation;
**/
public class Operations {
private static Operation[] operations = {
new CreateAggTableOperation()
private Operations() {
}
private static final Operation[] ALL_OPERATIONS = {new CreateAggTableOperation()
, new SetOperation()
, new CreateCDCSourceOperation()
, new ShowFragmentsOperation()
......@@ -70,12 +74,15 @@ public class Operations {
}
public static Operation buildOperation(String statement) {
String sql = statement.replace("\n", " ").replaceAll("\\s{1,}", " ").trim().toUpperCase();
for (int i = 0; i < operations.length; i++) {
if (sql.startsWith(operations[i].getHandle())) {
return operations[i].create(statement);
}
}
return null;
String sql = statement.replace("\n", " ")
.replaceAll("\\s+", " ")
.trim()
.toUpperCase();
return Arrays.stream(ALL_OPERATIONS)
.filter(p -> sql.startsWith(p.getHandle()))
.findFirst()
.map(p -> p.create(statement))
.orElse(null);
}
}
......@@ -29,12 +29,16 @@ import com.dlink.assertion.Asserts;
**/
public enum GatewayType {
LOCAL("l", "local"), STANDALONE("s", "standalone"),
YARN_SESSION("ys", "yarn-session"), YARN_APPLICATION("ya", "yarn-application"),
YARN_PER_JOB("ypj", "yarn-per-job"), KUBERNETES_SESSION("ks", "kubernetes-session"), KUBERNETES_APPLICATION("ka", "kubernetes-application");
LOCAL("l", "local"),
STANDALONE("s", "standalone"),
YARN_SESSION("ys", "yarn-session"),
YARN_APPLICATION("ya", "yarn-application"),
YARN_PER_JOB("ypj", "yarn-per-job"),
KUBERNETES_SESSION("ks", "kubernetes-session"),
KUBERNETES_APPLICATION("ka", "kubernetes-application");
private String value;
private String longValue;
private final String value;
private final String longValue;
GatewayType(String value, String longValue) {
this.value = value;
......@@ -59,10 +63,7 @@ public enum GatewayType {
}
public boolean equalsValue(String type) {
if (Asserts.isEquals(value, type) || Asserts.isEquals(longValue, type)) {
return true;
}
return false;
return Asserts.isEquals(value, type) || Asserts.isEquals(longValue, type);
}
public static boolean isDeployCluster(String type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment