mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= 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:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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("^");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user