mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= code cleanup
- for loop replaceable with enhanced 'for' loop - using diamond in generic type - collapse try catch exception - using try-with-resource - using List#sort instead of Collections#sort - replaced lambda with method reference - using native compare method to compare numbers - using switch instead of if for in ESSyncUtil
This commit is contained in:
@@ -51,7 +51,7 @@ public class AviaterRegexFilter {
|
||||
// 对pattern按照从长到短的排序
|
||||
// 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
|
||||
// 的长度不一样
|
||||
Collections.sort(list, COMPARATOR);
|
||||
list.sort(COMPARATOR);
|
||||
// 对pattern进行头尾完全匹配
|
||||
list = completionPattern(list);
|
||||
this.pattern = StringUtils.join(list, PATTERN_SPLIT);
|
||||
@@ -88,13 +88,7 @@ public class AviaterRegexFilter {
|
||||
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
if (str1.length() > str2.length()) {
|
||||
return -1;
|
||||
} else if (str1.length() < str2.length()) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return Integer.compare(str2.length(), str1.length());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public class CanalMessageSerializerUtil {
|
||||
messageSize += CodedOutputStream.computeInt64Size(1, data.getId());
|
||||
|
||||
int dataSize = 0;
|
||||
for (int i = 0; i < rowEntries.size(); i++) {
|
||||
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntries.get(i));
|
||||
for (ByteString rowEntry : rowEntries) {
|
||||
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntry);
|
||||
}
|
||||
messageSize += dataSize;
|
||||
messageSize += 1 * rowEntries.size();
|
||||
@@ -53,8 +53,8 @@ public class CanalMessageSerializerUtil {
|
||||
output.writeRawVarint32(messageSize);
|
||||
// message
|
||||
output.writeInt64(1, data.getId());
|
||||
for (int i = 0; i < rowEntries.size(); i++) {
|
||||
output.writeBytes(2, rowEntries.get(i));
|
||||
for (ByteString rowEntry : rowEntries) {
|
||||
output.writeBytes(2, rowEntry);
|
||||
}
|
||||
output.checkNoSpaceLeft();
|
||||
return body;
|
||||
|
||||
Reference in New Issue
Block a user