mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
fix issue IDFN7Y,修复 SplitIter reset 后无法重新迭代的问题。
This commit is contained in:
@@ -70,4 +70,12 @@ public abstract class ComputeIter<T> implements Iterator<T> {
|
||||
this.finished = true;
|
||||
this.next = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置状态,用于再次遍历
|
||||
*/
|
||||
public void resetState() {
|
||||
this.finished = false;
|
||||
this.next = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,6 +105,7 @@ public class SplitIter extends ComputeIter<String> implements Serializable {
|
||||
this.finder.reset();
|
||||
this.offset = 0;
|
||||
this.count = 0;
|
||||
resetState();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
package cn.hutool.core.text.split;
|
||||
|
||||
import cn.hutool.core.text.finder.CharFinder;
|
||||
import cn.hutool.core.text.finder.LengthFinder;
|
||||
import cn.hutool.core.text.finder.PatternFinder;
|
||||
import cn.hutool.core.text.finder.StrFinder;
|
||||
import cn.hutool.core.text.finder.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -169,4 +166,19 @@ public class SplitIterTest {
|
||||
|
||||
assertEquals(Collections.singletonList("test"), result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issueIDFN7YTest() {
|
||||
final String text = "a,b,c";
|
||||
final TextFinder finder = new StrFinder(",", false);
|
||||
final SplitIter splitIter = new SplitIter(text, finder, 0, false);
|
||||
|
||||
List<String> firstResult = splitIter.toList(false);
|
||||
assertEquals(3, firstResult.size());
|
||||
|
||||
splitIter.reset();
|
||||
List<String> secondResult = splitIter.toList(false);
|
||||
assertEquals(3, secondResult.size());
|
||||
assertEquals(firstResult, secondResult);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user