This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f3a77f  Refactor use iterator to visit LinkedList. (#11829)
0f3a77f is described below

commit 0f3a77f920f880165c83f017b06d6d3144000536
Author: gin <[email protected]>
AuthorDate: Sun Aug 15 18:55:38 2021 +0800

    Refactor use iterator to visit LinkedList. (#11829)
---
 .../impl/ShadowInsertColumnTokenGenerator.java       | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
index 2bc32eb..f741e4b 100644
--- 
a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/rewrite/token/generator/impl/ShadowInsertColumnTokenGenerator.java
@@ -57,13 +57,21 @@ public final class ShadowInsertColumnTokenGenerator extends 
BaseShadowSQLTokenGe
     private void generateRemoveTokenForShadow(final InsertColumnsSegment 
insertColumnsSegment, final Collection<RemoveToken> removeTokens) {
         List<ColumnSegment> columnSegments = (LinkedList<ColumnSegment>) 
insertColumnsSegment.getColumns();
         String shadowColumn = getShadowColumn();
-        for (int i = 0; i < columnSegments.size(); i++) {
-            ColumnSegment columnSegment = columnSegments.get(i);
-            if (shadowColumn.equals(columnSegment.getIdentifier().getValue())) 
{
-                RemoveToken removeToken = i == 0 ? new 
RemoveToken(columnSegments.get(i).getStartIndex(), columnSegments.get(i + 
1).getStartIndex() - 1)
-                        : new RemoveToken(columnSegments.get(i - 
1).getStopIndex() + 1, columnSegments.get(i).getStopIndex());
-                removeTokens.add(removeToken);
+        int index = 0;
+        for (ColumnSegment each : columnSegments) {
+            if (shadowColumn.equals(each.getIdentifier().getValue())) {
+                removeTokens.add(createShadowColumnRemoveToken(columnSegments, 
index));
             }
+            index++;
         }
     }
+
+    private RemoveToken createShadowColumnRemoveToken(final 
List<ColumnSegment> columnSegments, final int index) {
+        return isFirstElement(index) ? new 
RemoveToken(columnSegments.get(index).getStartIndex(), columnSegments.get(index 
+ 1).getStartIndex() - 1)
+                : new RemoveToken(columnSegments.get(index - 1).getStopIndex() 
+ 1, columnSegments.get(index).getStopIndex());
+    }
+    
+    private boolean isFirstElement(final int count) {
+        return count == 0;
+    }
 }

Reply via email to