= cold cleanup

* using lambda if possible (we are already building in Java8)
  * using diamond when new generic instance
  * remove used improt
This commit is contained in:
zavakid
2020-09-17 10:48:15 +08:00
parent df60eda679
commit e7658879bc
133 changed files with 990 additions and 1558 deletions

View File

@@ -14,20 +14,17 @@ import com.google.common.collect.MigrateMap;
public class PatternUtils {
private static Map<String, Pattern> patterns = MigrateMap.makeComputingMap(CacheBuilder.newBuilder().softValues(),
new Function<String, Pattern>() {
public Pattern apply(String pattern) {
try {
PatternCompiler pc = new Perl5Compiler();
return pc.compile(pattern,
Perl5Compiler.CASE_INSENSITIVE_MASK
| Perl5Compiler.READ_ONLY_MASK
| Perl5Compiler.SINGLELINE_MASK);
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
}
});
pattern -> {
try {
PatternCompiler pc = new Perl5Compiler();
return pc.compile(pattern,
Perl5Compiler.CASE_INSENSITIVE_MASK
| Perl5Compiler.READ_ONLY_MASK
| Perl5Compiler.SINGLELINE_MASK);
} catch (MalformedPatternException e) {
throw new RuntimeException(e);
}
});
public static Pattern getPattern(String pattern) {
return patterns.get(pattern);

View File

@@ -29,7 +29,7 @@ public class AviaterELFilter implements CanalEventFilter<CanalEntry.Entry> {
return true;
}
Map<String, Object> env = new HashMap<String, Object>();
Map<String, Object> env = new HashMap<>();
env.put(ROOT_KEY, entry);
return (Boolean) AviatorEvaluator.execute(expression, env);
}

View File

@@ -44,7 +44,7 @@ public class AviaterRegexFilter implements CanalEventFilter<String> {
this.defaultEmptyValue = defaultEmptyValue;
List<String> list = null;
if (StringUtils.isEmpty(pattern)) {
list = new ArrayList<String>();
list = new ArrayList<>();
} else {
String[] ss = StringUtils.split(pattern, SPLIT);
list = Arrays.asList(ss);
@@ -68,7 +68,7 @@ public class AviaterRegexFilter implements CanalEventFilter<String> {
return defaultEmptyValue;
}
Map<String, Object> env = new HashMap<String, Object>();
Map<String, Object> env = new HashMap<>();
env.put("pattern", pattern);
env.put("target", filtered.toLowerCase());
return (Boolean) exp.execute(env);
@@ -114,7 +114,7 @@ public class AviaterRegexFilter implements CanalEventFilter<String> {
*/
private List<String> completionPattern(List<String> patterns) {
List<String> result = new ArrayList<String>();
List<String> result = new ArrayList<>();
for (String pattern : patterns) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("^");

View File

@@ -30,7 +30,7 @@ public class AviaterSimpleFilter implements CanalEventFilter<String> {
public AviaterSimpleFilter(String filterExpression){
if (StringUtils.isEmpty(filterExpression)) {
list = new ArrayList<String>();
list = new ArrayList<>();
} else {
String[] ss = filterExpression.toLowerCase().split(SPLIT);
list = Arrays.asList(ss);
@@ -44,7 +44,7 @@ public class AviaterSimpleFilter implements CanalEventFilter<String> {
if (StringUtils.isEmpty(filtered)) {
return true;
}
Map<String, Object> env = new HashMap<String, Object>();
Map<String, Object> env = new HashMap<>();
env.put("list", list);
env.put("target", filtered.toLowerCase());
return (Boolean) exp.execute(env);

View File

@@ -21,22 +21,19 @@ public class MutliAviaterFilterTest {
final CountDownLatch countDown = new CountDownLatch(count);
final AtomicInteger successed = new AtomicInteger(0);
for (int i = 0; i < count; i++) {
executor.submit(new Runnable() {
public void run() {
try {
for (int i = 0; i < 100; i++) {
doRegexTest();
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// }
}
successed.incrementAndGet();
} finally {
countDown.countDown();
executor.submit(() -> {
try {
for (int i1 = 0; i1 < 100; i1++) {
doRegexTest();
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// }
}
successed.incrementAndGet();
} finally {
countDown.countDown();
}
});
}