= 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:
zavakid
2020-09-17 22:49:35 +08:00
parent 43c23ffb97
commit df24596092
33 changed files with 268 additions and 356 deletions

View File

@@ -20,7 +20,7 @@ public class Events<EVENT> implements Serializable {
private static final long serialVersionUID = -7337454954300706044L;
private PositionRange positionRange = new PositionRange();
private List<EVENT> events = new ArrayList<EVENT>();
private List<EVENT> events = new ArrayList<>();
public List<EVENT> getEvents() {
return events;

View File

@@ -81,9 +81,7 @@ public class MemoryEventStoreMemBatchTest extends MemoryEventStoreBase {
try {
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
} catch (CanalStoreException e) {
Assert.fail(e.getMessage());
} catch (InterruptedException e) {
} catch (CanalStoreException | InterruptedException e) {
Assert.fail(e.getMessage());
}
@@ -162,8 +160,7 @@ public class MemoryEventStoreMemBatchTest extends MemoryEventStoreBase {
Assert.assertTrue(entrys.getEvents().size() == batchSize);
Assert.assertEquals(position, entrys.getPositionRange().getStart());
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
} catch (CanalStoreException e) {
} catch (InterruptedException e) {
} catch (CanalStoreException | InterruptedException e) {
}
ExecutorService executor = Executors.newFixedThreadPool(1);

View File

@@ -109,8 +109,7 @@ public class MemoryEventStoreMultiThreadTest extends MemoryEventStoreBase {
}
try {
eventStore.put(event);
} catch (CanalStoreException e) {
} catch (InterruptedException e) {
} catch (CanalStoreException | InterruptedException e) {
}
}
}

View File

@@ -64,9 +64,7 @@ public class MemoryEventStorePutAndGetTest extends MemoryEventStoreBase {
try {
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
} catch (CanalStoreException e) {
Assert.fail(e.getMessage());
} catch (InterruptedException e) {
} catch (CanalStoreException | InterruptedException e) {
Assert.fail(e.getMessage());
}
@@ -140,8 +138,7 @@ public class MemoryEventStorePutAndGetTest extends MemoryEventStoreBase {
Assert.assertTrue(entrys.getEvents().size() == batchSize);
Assert.assertEquals(position, entrys.getPositionRange().getStart());
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
} catch (CanalStoreException e) {
} catch (InterruptedException e) {
} catch (CanalStoreException | InterruptedException e) {
}
ExecutorService executor = Executors.newFixedThreadPool(1);